Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / file / src / Tests / FileFieldValidateTest.php
index 5ddcdde3f8974edd7cc5139f3362a63825db1e8e..be96f3c587eed0556e21a75c3df784535cf69216 100644 (file)
@@ -29,7 +29,7 @@ class FileFieldValidateTest extends FileFieldTestBase {
     // Try to post a new node without uploading a file.
     $edit = [];
     $edit['title[0][value]'] = $this->randomMachineName();
-    $this->drupalPostForm('node/add/' . $type_name, $edit, t('Save and publish'));
+    $this->drupalPostForm('node/add/' . $type_name, $edit, t('Save'));
     $this->assertRaw(t('@title field is required.', ['@title' => $field->getLabel()]), 'Node save failed when required file field was empty.');
 
     // Create a new node with the uploaded file.
@@ -50,7 +50,7 @@ class FileFieldValidateTest extends FileFieldTestBase {
     // Try to post a new node without uploading a file in the multivalue field.
     $edit = [];
     $edit['title[0][value]'] = $this->randomMachineName();
-    $this->drupalPostForm('node/add/' . $type_name, $edit, t('Save and publish'));
+    $this->drupalPostForm('node/add/' . $type_name, $edit, t('Save'));
     $this->assertRaw(t('@title field is required.', ['@title' => $field->getLabel()]), 'Node save failed when required multiple value file field was empty.');
 
     // Create a new node with the uploaded file into the multivalue field.
@@ -71,8 +71,10 @@ class FileFieldValidateTest extends FileFieldTestBase {
     $field_name = strtolower($this->randomMachineName());
     $this->createFileField($field_name, 'node', $type_name, [], ['required' => '1']);
 
-    $small_file = $this->getTestFile('text', 131072); // 128KB.
-    $large_file = $this->getTestFile('text', 1310720); // 1.2MB
+    // 128KB.
+    $small_file = $this->getTestFile('text', 131072);
+    // 1.2MB
+    $large_file = $this->getTestFile('text', 1310720);
 
     // Test uploading both a large and small file with different increments.
     $sizes = [
@@ -185,4 +187,25 @@ class FileFieldValidateTest extends FileFieldTestBase {
     $this->assertText('Article ' . $node->getTitle() . ' has been updated.');
   }
 
+  /**
+   * Test the validation message is displayed only once for ajax uploads.
+   */
+  public function testAJAXValidationMessage() {
+    $field_name = strtolower($this->randomMachineName());
+    $this->createFileField($field_name, 'node', 'article');
+
+    $this->drupalGet('node/add/article');
+    /** @var \Drupal\file\FileInterface $image_file */
+    $image_file = $this->getTestFile('image');
+    $edit = [
+      'files[' . $field_name . '_0]' => $this->container->get('file_system')->realpath($image_file->getFileUri()),
+      'title[0][value]' => $this->randomMachineName(),
+    ];
+    $this->drupalPostAjaxForm(NULL, $edit, $field_name . '_0_upload_button');
+    $elements = $this->xpath('//div[contains(@class, :class)]', [
+      ':class' => 'messages--error',
+    ]);
+    $this->assertEqual(count($elements), 1, 'Ajax validation messages are displayed once.');
+  }
+
 }