From 3d44e9ae8048468cc45bbdd32ab0ee768283e21b Mon Sep 17 00:00:00 2001 From: Nathaniel Catchpole Date: Tue, 18 Aug 2015 10:32:20 +0100 Subject: [PATCH] Issue #2551335 by alexpott, Wim Leers: Remove unnecessary SafeMarkup usage in tests and clear the static cache before every run --- .../src/Unit/FilterUninstallValidatorTest.php | 6 +-- .../src/Unit/ForumUninstallValidatorTest.php | 19 ++------ .../src/Unit/UserAccessControlHandlerTest.php | 10 +--- .../tests/src/Unit/EntityViewsDataTest.php | 5 +- .../src/Unit/Plugin/field/CounterTest.php | 41 ++++------------ .../tests/src/Unit/ViewsDataHelperTest.php | 5 +- core/phpunit.xml.dist | 4 +- .../Tests/Component/Utility/RandomTest.php | 5 +- .../Component/Utility/SafeMarkupTest.php | 47 ++++++++++++++----- .../Tests/Component/Utility/UrlHelperTest.php | 9 ++-- .../Core/Controller/TitleResolverTest.php | 3 +- .../RequiredModuleUninstallValidatorTest.php | 3 +- .../Drupal/Tests/Core/Form/FormCacheTest.php | 6 +-- .../Tests/Core/Form/FormValidatorTest.php | 3 +- .../Tests/Core/Path/PathMatcherTest.php | 8 +--- .../Core/Render/RendererPlaceholdersTest.php | 18 +++---- .../PhpTransliterationTest.php | 8 +--- .../Tests/Core/Utility/LinkGeneratorTest.php | 4 +- .../DrupalStandardsListener.php | 4 +- .../Tests/Listeners/SafeMarkupSideEffects.php | 35 ++++++++++++++ core/tests/Drupal/Tests/UnitTestCase.php | 6 +++ 21 files changed, 125 insertions(+), 124 deletions(-) rename core/tests/Drupal/Tests/{Standards => Listeners}/DrupalStandardsListener.php (98%) create mode 100644 core/tests/Drupal/Tests/Listeners/SafeMarkupSideEffects.php diff --git a/core/modules/filter/tests/src/Unit/FilterUninstallValidatorTest.php b/core/modules/filter/tests/src/Unit/FilterUninstallValidatorTest.php index cb37bf42418b..4a4f7bac36d8 100644 --- a/core/modules/filter/tests/src/Unit/FilterUninstallValidatorTest.php +++ b/core/modules/filter/tests/src/Unit/FilterUninstallValidatorTest.php @@ -7,7 +7,6 @@ namespace Drupal\Tests\filter\Unit; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Tests\UnitTestCase; /** @@ -160,10 +159,7 @@ class FilterUninstallValidatorTest extends UnitTestCase { ]); $expected = [ - SafeMarkup::format('Provides a filter plugin that is in use in the following filter formats: %formats', ['%formats' => implode(', ', [ - 'Filter Format 1 Label', - 'Filter Format 2 Label', - ])]), + 'Provides a filter plugin that is in use in the following filter formats: Filter Format 1 Label, Filter Format 2 Label' ]; $reasons = $this->filterUninstallValidator->validate($this->randomMachineName()); $this->assertSame($expected, $reasons); diff --git a/core/modules/forum/tests/src/Unit/ForumUninstallValidatorTest.php b/core/modules/forum/tests/src/Unit/ForumUninstallValidatorTest.php index 85145c2f5976..560a872834e4 100644 --- a/core/modules/forum/tests/src/Unit/ForumUninstallValidatorTest.php +++ b/core/modules/forum/tests/src/Unit/ForumUninstallValidatorTest.php @@ -7,7 +7,6 @@ namespace Drupal\Tests\forum\Unit; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Tests\UnitTestCase; /** @@ -127,10 +126,7 @@ class ForumUninstallValidatorTest extends UnitTestCase { $module = 'forum'; $expected = [ 'To uninstall Forum, first delete all Forum content', - SafeMarkup::format('To uninstall Forum, first delete all %vocabulary terms', [ - '@url' => '/path/to/vocabulary/overview', - '%vocabulary' => 'Vocabulary label', - ]), + 'To uninstall Forum, first delete all Vocabulary label terms', ]; $reasons = $this->forumUninstallValidator->validate($module); $this->assertSame($expected, $reasons); @@ -164,9 +160,7 @@ class ForumUninstallValidatorTest extends UnitTestCase { $module = 'forum'; $expected = [ 'To uninstall Forum, first delete all Forum content', - SafeMarkup::format('To uninstall Forum, first delete all %vocabulary terms', [ - '%vocabulary' => 'Vocabulary label', - ]), + 'To uninstall Forum, first delete all Vocabulary label terms', ]; $reasons = $this->forumUninstallValidator->validate($module); $this->assertSame($expected, $reasons); @@ -200,10 +194,7 @@ class ForumUninstallValidatorTest extends UnitTestCase { $module = 'forum'; $expected = [ - SafeMarkup::format('To uninstall Forum, first delete all %vocabulary terms', [ - '@url' => '/path/to/vocabulary/overview', - '%vocabulary' => 'Vocabulary label', - ]), + 'To uninstall Forum, first delete all Vocabulary label terms', ]; $reasons = $this->forumUninstallValidator->validate($module); $this->assertSame($expected, $reasons); @@ -236,9 +227,7 @@ class ForumUninstallValidatorTest extends UnitTestCase { $module = 'forum'; $expected = [ - SafeMarkup::format('To uninstall Forum, first delete all %vocabulary terms', [ - '%vocabulary' => 'Vocabulary label', - ]), + 'To uninstall Forum, first delete all Vocabulary label terms', ]; $reasons = $this->forumUninstallValidator->validate($module); $this->assertSame($expected, $reasons); diff --git a/core/modules/user/tests/src/Unit/UserAccessControlHandlerTest.php b/core/modules/user/tests/src/Unit/UserAccessControlHandlerTest.php index 05d7223f49a0..849cde5e4f9c 100644 --- a/core/modules/user/tests/src/Unit/UserAccessControlHandlerTest.php +++ b/core/modules/user/tests/src/Unit/UserAccessControlHandlerTest.php @@ -7,7 +7,6 @@ namespace Drupal\Tests\user\Unit; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Access\AccessResult; use Drupal\Core\Cache\Context\CacheContextsManager; use Drupal\Core\DependencyInjection\Container; @@ -133,13 +132,8 @@ class UserAccessControlHandlerTest extends UnitTestCase { ->will($this->returnValue($this->{$target})); foreach (array('view' => $view, 'edit' => $edit) as $operation => $result) { - $message = SafeMarkup::format("User @field field access returns @result with operation '@op' for @account accessing @target", array( - '@field' => $field, - '@result' => !isset($result) ? 'null' : ($result ? 'true' : 'false'), - '@op' => $operation, - '@account' => $viewer, - '@target' => $target, - )); + $result_text = !isset($result) ? 'null' : ($result ? 'true' : 'false'); + $message = "User '$field' field access returns '$result_text' with operation '$operation' for '$viewer' accessing '$target'"; $this->assertSame($result, $this->accessControlHandler->fieldAccess($operation, $field_definition, $this->{$viewer}, $this->items), $message); } } diff --git a/core/modules/views/tests/src/Unit/EntityViewsDataTest.php b/core/modules/views/tests/src/Unit/EntityViewsDataTest.php index 3dedb8252a59..b8db4feec0fa 100644 --- a/core/modules/views/tests/src/Unit/EntityViewsDataTest.php +++ b/core/modules/views/tests/src/Unit/EntityViewsDataTest.php @@ -930,13 +930,10 @@ class TestEntityType extends EntityType { } - namespace { - use Drupal\Component\Utility\SafeMarkup; - if (!function_exists('t')) { function t($string, array $args = []) { - return SafeMarkup::format($string, $args); + return strtr($string, $args); } } } diff --git a/core/modules/views/tests/src/Unit/Plugin/field/CounterTest.php b/core/modules/views/tests/src/Unit/Plugin/field/CounterTest.php index 5a68eb204d87..5280370ddbad 100644 --- a/core/modules/views/tests/src/Unit/Plugin/field/CounterTest.php +++ b/core/modules/views/tests/src/Unit/Plugin/field/CounterTest.php @@ -7,7 +7,6 @@ namespace Drupal\Tests\views\Unit\Plugin\field; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Tests\UnitTestCase; use Drupal\views\Entity\View; use Drupal\views\Plugin\views\field\Counter; @@ -125,15 +124,9 @@ class CounterTest extends UnitTestCase { $expected = $i + 1; $counter = $counter_handler->getValue($this->testData[$i]); - $this->assertEquals($expected, $counter, SafeMarkup::format('The expected number (@expected) patches with the rendered number (@counter) failed', array( - '@expected' => $expected, - '@counter' => $counter - ))); + $this->assertEquals($expected, $counter, 'The expected number matches with the counter number'); $counter = $this->renderCounter($counter_handler, $this->testData[$i]); - $this->assertEquals($expected, $counter, SafeMarkup::format('The expected number (@expected) patches with the rendered number (@counter) failed', array( - '@expected' => $expected, - '@counter' => $counter - ))); + $this->assertEquals($expected, $counter, 'The expected number matches with the rendered number'); } /** @@ -157,15 +150,9 @@ class CounterTest extends UnitTestCase { $expected = $rand_start + $i; $counter = $counter_handler->getValue($this->testData[$i]); - $this->assertEquals($expected, $counter, SafeMarkup::format('The expected number (@expected) patches with the rendered number (@counter) failed', array( - '@expected' => $expected, - '@counter' => $counter - ))); + $this->assertEquals($expected, $counter, 'The expected number matches with the counter number'); $counter = $this->renderCounter($counter_handler, $this->testData[$i]); - $this->assertEquals($expected, $counter, SafeMarkup::format('The expected number (@expected) patches with the rendered number (@counter) failed', array( - '@expected' => $expected, - '@counter' => $counter - ))); + $this->assertEquals($expected, $counter, 'The expected number matches with the rendered number'); } /** @@ -192,15 +179,9 @@ class CounterTest extends UnitTestCase { $expected = $offset + $rand_start + $i; $counter = $counter_handler->getValue($this->testData[$i]); - $this->assertEquals($expected, $counter, SafeMarkup::format('The expected number (@expected) patches with the rendered number (@counter) failed', array( - '@expected' => $expected, - '@counter' => $counter - ))); + $this->assertEquals($expected, $counter, 'The expected number matches with the counter number'); $counter = $this->renderCounter($counter_handler, $this->testData[$i]); - $this->assertEquals($expected, $counter, SafeMarkup::format('The expected number (@expected) patches with the rendered number (@counter) failed', array( - '@expected' => $expected, - '@counter' => $counter - ))); + $this->assertEquals($expected, $counter, 'The expected number matches with the rendered number'); } /** @@ -231,15 +212,9 @@ class CounterTest extends UnitTestCase { $expected = $items_per_page + $offset + $rand_start + $i; $counter = $counter_handler->getValue($this->testData[$i]); - $this->assertEquals($expected, $counter, SafeMarkup::format('The expected number (@expected) patches with the rendered number (@counter) failed', array( - '@expected' => $expected, - '@counter' => $counter - ))); + $this->assertEquals($expected, $counter, 'The expected number matches with the counter number'); $counter = $this->renderCounter($counter_handler, $this->testData[$i]); - $this->assertEquals($expected, $counter, SafeMarkup::format('The expected number (@expected) patches with the rendered number (@counter) failed', array( - '@expected' => $expected, - '@counter' => $counter - ))); + $this->assertEquals($expected, $counter, 'The expected number matches with the rendered number'); } /** diff --git a/core/modules/views/tests/src/Unit/ViewsDataHelperTest.php b/core/modules/views/tests/src/Unit/ViewsDataHelperTest.php index 35713d760ed1..a00567879f85 100644 --- a/core/modules/views/tests/src/Unit/ViewsDataHelperTest.php +++ b/core/modules/views/tests/src/Unit/ViewsDataHelperTest.php @@ -7,7 +7,6 @@ namespace Drupal\Tests\views\Unit; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Tests\UnitTestCase; use Drupal\views\ViewsDataHelper; use Drupal\views\Tests\ViewTestData; @@ -106,7 +105,7 @@ class ViewsDataHelperTest extends UnitTestCase { array_walk($expected_keys, function(&$item) { $item = "views_test_data.$item"; }); - $this->assertEquals($expected_keys, array_keys($fields), SafeMarkup::format('Handlers of type @handler_type are not listed as expected.', array('@handler_type' => $handler_type))); + $this->assertEquals($expected_keys, array_keys($fields), "Handlers of type $handler_type are not listed as expected"); } // Check for subtype filtering, so header and footer. @@ -117,7 +116,7 @@ class ViewsDataHelperTest extends UnitTestCase { array_walk($expected_keys, function(&$item) { $item = "views_test_data.$item"; }); - $this->assertEquals($expected_keys, array_keys($fields), SafeMarkup::format('Sub_type @sub_type is not filtered as expected.', array('@sub_type' => $sub_type))); + $this->assertEquals($expected_keys, array_keys($fields), "Sub_type $sub_type is not filtered as expected."); } } diff --git a/core/phpunit.xml.dist b/core/phpunit.xml.dist index 15b6316f79f7..2e496b805725 100644 --- a/core/phpunit.xml.dist +++ b/core/phpunit.xml.dist @@ -44,7 +44,9 @@ - + + + diff --git a/core/tests/Drupal/Tests/Component/Utility/RandomTest.php b/core/tests/Drupal/Tests/Component/Utility/RandomTest.php index ead6469990c4..a993100e2cb9 100644 --- a/core/tests/Drupal/Tests/Component/Utility/RandomTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/RandomTest.php @@ -8,7 +8,6 @@ namespace Drupal\Tests\Component\Utility; use Drupal\Component\Utility\Random; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Tests\UnitTestCase; /** @@ -39,7 +38,7 @@ class RandomTest extends UnitTestCase { $random = new Random(); for ($i = 0; $i <= 50; $i++) { $str = $random->string(1, TRUE); - $this->assertFalse(isset($strings[$str]), SafeMarkup::format('Generated duplicate random string !string', array('!string' => $str))); + $this->assertFalse(isset($strings[$str]), 'Generated duplicate random string ' . $str); $strings[$str] = TRUE; } } @@ -54,7 +53,7 @@ class RandomTest extends UnitTestCase { $random = new Random(); for ($i = 0; $i <= 10; $i++) { $str = $random->name(1, TRUE); - $this->assertFalse(isset($names[$str]), SafeMarkup::format('Generated duplicate random name !name', array('!name' => $str))); + $this->assertFalse(isset($names[$str]), 'Generated duplicate random name ' . $str); $names[$str] = TRUE; } } diff --git a/core/tests/Drupal/Tests/Component/Utility/SafeMarkupTest.php b/core/tests/Drupal/Tests/Component/Utility/SafeMarkupTest.php index 90a475fa46b5..bfa4cb3733a2 100644 --- a/core/tests/Drupal/Tests/Component/Utility/SafeMarkupTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/SafeMarkupTest.php @@ -8,6 +8,7 @@ namespace Drupal\Tests\Component\Utility; use Drupal\Component\Utility\SafeMarkup; +use Drupal\Component\Utility\SafeStringInterface; use Drupal\Component\Utility\Xss; use Drupal\Tests\UnitTestCase; @@ -183,11 +184,11 @@ class SafeMarkupTest extends UnitTestCase { function providerFormat() { $tests[] = array('Simple text', array(), 'Simple text', 'SafeMarkup::format leaves simple text alone.', TRUE); $tests[] = array('Escaped text: @value', array('@value' => '