diff --git a/core/modules/file/src/Tests/FileFieldValidateTest.php b/core/modules/file/src/Tests/FileFieldValidateTest.php index 9d43060..de3b1c5 100644 --- a/core/modules/file/src/Tests/FileFieldValidateTest.php +++ b/core/modules/file/src/Tests/FileFieldValidateTest.php @@ -71,8 +71,10 @@ function testFileMaxSize() { $field_name = strtolower($this->randomMachineName()); $this->createFileField($field_name, 'node', $type_name, array(), array('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 = array( @@ -185,4 +187,25 @@ 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 = array( + '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)]', array( + ':class' => 'messages--error', + )); + $this->assertEqual(count($elements), 1, 'Ajax validation messages are displayed once.'); + } + } diff --git a/core/modules/image/src/Tests/ImageFieldValidateTest.php b/core/modules/image/src/Tests/ImageFieldValidateTest.php index 5f0bf21..bf6b4df 100644 --- a/core/modules/image/src/Tests/ImageFieldValidateTest.php +++ b/core/modules/image/src/Tests/ImageFieldValidateTest.php @@ -8,6 +8,7 @@ * @group image */ class ImageFieldValidateTest extends ImageFieldTestBase { + /** * Test min/max resolution settings. */ @@ -156,4 +157,26 @@ protected function getFieldSettings($min_resolution, $max_resolution) { ]; } + /** + * Test the validation message is displayed only once for ajax uploads. + */ + public function testAJAXValidationMessage() { + $field_name = strtolower($this->randomMachineName()); + $this->createImageField($field_name, 'article'); + + $this->drupalGet('node/add/article'); + /** @var \Drupal\file\FileInterface[] $text_files */ + $text_files = $this->drupalGetTestFiles('text'); + $text_file = reset($text_files); + $edit = array( + 'files[' . $field_name . '_0]' => $this->container->get('file_system')->realpath($text_file->uri), + 'title[0][value]' => $this->randomMachineName(), + ); + $this->drupalPostAjaxForm(NULL, $edit, $field_name . '_0_upload_button'); + $elements = $this->xpath('//div[contains(@class, :class)]', array( + ':class' => 'messages--error', + )); + $this->assertEqual(count($elements), 1, 'Ajax validation messages are displayed once.'); + } + } diff --git a/core/tests/Drupal/KernelTests/Core/Render/RenderTest.php b/core/tests/Drupal/KernelTests/Core/Render/RenderTest.php index 8860c19..6bb3bed 100644 --- a/core/tests/Drupal/KernelTests/Core/Render/RenderTest.php +++ b/core/tests/Drupal/KernelTests/Core/Render/RenderTest.php @@ -16,7 +16,7 @@ class RenderTest extends KernelTestBase { * * @var array */ - public static $modules = array('system', 'common_test'); + public static $modules = array('system', 'common_test', 'theme_test'); /** * Tests theme preprocess functions being able to attach assets. @@ -44,6 +44,23 @@ function testDrupalRenderThemePreprocessAttached() { } /** + * Ensures that render array children are processed correctly. + */ + public function testRenderChildren() { + // Ensure that #prefix and #suffix is only being printed once since that is + // the behaviour the caller code expects. + $build = [ + '#type' => 'container', + '#theme' => 'theme_test_render_element_children', + '#prefix' => 'kangaroo', + '#suffix' => 'kitten', + ]; + $this->render($build); + $this->removeWhiteSpace(); + $this->assertNoRaw('
kangarookitten
'); + } + + /** * Tests that we get an exception when we try to attach an illegal type. */ public function testProcessAttached() { diff --git a/core/tests/Drupal/Tests/Core/Render/RendererTest.php b/core/tests/Drupal/Tests/Core/Render/RendererTest.php index 51cfde8..7e24134 100644 --- a/core/tests/Drupal/Tests/Core/Render/RendererTest.php +++ b/core/tests/Drupal/Tests/Core/Render/RendererTest.php @@ -363,6 +363,25 @@ public function providerTestRenderBasic() { }; $data[] = [$build, 'baz', $setup_code]; + // #theme is implemented but #render_children is TRUE. In this case the + // calling code is expecting only the children to be rendered. #prefix and + // #suffix should not be inherited for the children. + $build = [ + '#theme' => 'common_test_foo', + '#children' => '', + '#prefix' => 'kangaroo', + '#suffix' => 'unicorn', + '#render_children' => TRUE, + 'child' => [ + '#markup' => 'kitten', + ], + ]; + $setup_code = function() { + $this->themeManager->expects($this->never()) + ->method('render'); + }; + $data[] = [$build, 'kitten', $setup_code]; + return $data; }