diff --git a/core/modules/file/src/Tests/FileFieldValidateTest.php b/core/modules/file/src/Tests/FileFieldValidateTest.php new file mode 100644 index 0000000000..257f9c806b --- /dev/null +++ b/core/modules/file/src/Tests/FileFieldValidateTest.php @@ -0,0 +1,34 @@ +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.'); + } + +} diff --git a/core/modules/file/tests/src/Functional/FileFieldTestBase.php b/core/modules/file/tests/src/Functional/FileFieldTestBase.php index 8561c108fd..1cd5072bac 100644 --- a/core/modules/file/tests/src/Functional/FileFieldTestBase.php +++ b/core/modules/file/tests/src/Functional/FileFieldTestBase.php @@ -8,7 +8,6 @@ use Drupal\Tests\BrowserTestBase; use Drupal\file\Entity\File; use Drupal\Tests\TestFileCreationTrait; -use Drupal\Tests\Traits\DrupalPostFormWithInvalidOptionsTrait; /** * Provides methods specifically for testing File module's field handling. @@ -17,7 +16,6 @@ use FileFieldCreationTrait; - use DrupalPostFormWithInvalidOptionsTrait; use TestFileCreationTrait { getTestFiles as drupalGetTestFiles; } @@ -117,14 +115,11 @@ public function uploadNodeFile(FileInterface $file, $field_name, $nid_or_type, $ * The revision number. * @param array $extras * Additional values when a new node is created. - * @param bool $is_invalid - * FALSE (by default) using drupalPostForm() - * TRUE using drupalPostFormWithInvalidOptions(). * * @return int * The node id. */ - public function uploadNodeFiles(array $files, $field_name, $nid_or_type, $new_revision = TRUE, array $extras = [], $is_invalid = FALSE) { + public function uploadNodeFiles(array $files, $field_name, $nid_or_type, $new_revision = TRUE, array $extras = []) { $edit = [ 'title[0][value]' => $this->randomMachineName(), 'revision' => (string) (int) $new_revision, @@ -167,12 +162,7 @@ public function uploadNodeFiles(array $files, $field_name, $nid_or_type, $new_re } } - if ($is_invalid) { - $this->drupalPostFormWithInvalidOptions("node/$nid/edit", $edit, t('Save')); - } - else { - $this->drupalPostForm("node/$nid/edit", $edit, t('Save')); - } + $this->drupalPostForm("node/$nid/edit", $edit, t('Save')); return $nid; } diff --git a/core/modules/file/tests/src/Functional/FileFieldValidateTest.php b/core/modules/file/tests/src/Functional/FileFieldValidateTest.php index 40c7771113..c307ce0fb2 100644 --- a/core/modules/file/tests/src/Functional/FileFieldValidateTest.php +++ b/core/modules/file/tests/src/Functional/FileFieldValidateTest.php @@ -187,25 +187,4 @@ public function testFileRemoval() { $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.'); - } - } diff --git a/core/modules/file/tests/src/Functional/SaveUploadFormTest.php b/core/modules/file/tests/src/Functional/SaveUploadFormTest.php index c0411b7748..c7c3f21b8c 100644 --- a/core/modules/file/tests/src/Functional/SaveUploadFormTest.php +++ b/core/modules/file/tests/src/Functional/SaveUploadFormTest.php @@ -4,7 +4,6 @@ use Drupal\file\Entity\File; use Drupal\Tests\TestFileCreationTrait; -use Drupal\Tests\Traits\DrupalPostFormWithInvalidOptionsTrait; /** * Tests the _file_save_upload_from_form() function. @@ -19,8 +18,6 @@ class SaveUploadFormTest extends FileManagedTestBase { getTestFiles as drupalGetTestFiles; } - use DrupalPostFormWithInvalidOptionsTrait; - /** * Modules to enable. * @@ -454,10 +451,8 @@ public function testCombinedErrorMessages() { /** @var \Drupal\Core\File\FileSystemInterface $file_system */ $file_system = \Drupal::service('file_system'); $edit = [ - 'files[file_test_upload][]' => [ - $file_system->realpath($this->phpfile->uri), - $file_system->realpath($textfile->uri), - ], + 'files[file_test_upload][0]' => $file_system->realpath($this->phpfile->uri), + 'files[file_test_upload][1]' => $file_system->realpath($textfile->uri), 'allow_all_extensions' => FALSE, 'is_image_file' => TRUE, 'extensions' => 'jpeg', diff --git a/core/modules/simpletest/src/Tests/UiPhpUnitOutputTest.php b/core/modules/simpletest/src/Tests/UiPhpUnitOutputTest.php index e032cef941..c2ebfc92c4 100644 --- a/core/modules/simpletest/src/Tests/UiPhpUnitOutputTest.php +++ b/core/modules/simpletest/src/Tests/UiPhpUnitOutputTest.php @@ -35,9 +35,9 @@ public function testOutput() { // Check that there are
tags for the HTML output by // SimpletestUiPrinter. - $this->assertEqual($output[19], 'HTML output was generated
'); + $this->assertEqual($output[20], 'HTML output was generated
'); // Check that URLs are printed as HTML links. - $this->assertIdentical(strpos($output[20], 'drupalGet($path); + } + + $edit_params = []; + $edit_files = []; + foreach ($edit as $key => $value) { + if (strpos($key, 'files') === 0) { + $edit_files[$key] = $value; + } + else { + $edit_params[$key] = $value; + } + } + + $submit_xpath = $this->assertSession()->buttonExists((string) $submit)->getXpath(); + $client = $this->getSession()->getDriver()->getClient(); + $form = $client->getCrawler()->filterXPath($submit_xpath)->form(); + $params = array_replace_recursive($form->getPhpValues(), $edit_params); + $files = array_replace_recursive($form->getPhpFiles(), $edit_files); + $client->request($form->getMethod(), $form->getUri(), $params, $files); + } + }