From 9dc42330911c8abb846aa62550cae56bcf55e6fe Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Mon, 15 Jun 2020 12:30:21 +0100 Subject: [PATCH] Issue #3135077 by mondrake, sja112, daffie, longwave, xjm: Remove usage of AssertLegacyTrait::pass() from traits --- .../tests/src/Functional/BookTestTrait.php | 3 --- .../tests/src/Traits/UserCreationTrait.php | 7 +---- .../src/Tests/AssertViewsCacheTagsTrait.php | 13 ++++----- .../Drupal/KernelTests/AssertContentTrait.php | 6 +---- .../Drupal/Tests/SchemaCheckTestTrait.php | 27 +++++++------------ .../Config/SchemaConfigListenerTestTrait.php | 4 --- 6 files changed, 17 insertions(+), 43 deletions(-) diff --git a/core/modules/book/tests/src/Functional/BookTestTrait.php b/core/modules/book/tests/src/Functional/BookTestTrait.php index c03dc6c5711b..38a93f44b24f 100644 --- a/core/modules/book/tests/src/Functional/BookTestTrait.php +++ b/core/modules/book/tests/src/Functional/BookTestTrait.php @@ -97,9 +97,6 @@ public function checkBookNode(EntityInterface $node, $nodes, $previous, $up, $ne if ($nodes !== NULL) { $this->assertPattern($this->generateOutlinePattern($nodes), new FormattableMarkup('Node @number outline confirmed.', ['@number' => $number])); } - else { - $this->pass(new FormattableMarkup('Node %number does not have outline.', ['%number' => $number])); - } // Check previous, up, and next links. if ($previous) { diff --git a/core/modules/user/tests/src/Traits/UserCreationTrait.php b/core/modules/user/tests/src/Traits/UserCreationTrait.php index 9d687fd4e5c0..21d3626383a3 100644 --- a/core/modules/user/tests/src/Traits/UserCreationTrait.php +++ b/core/modules/user/tests/src/Traits/UserCreationTrait.php @@ -283,12 +283,7 @@ protected function createRole(array $permissions, $rid = NULL, $name = NULL, $we $this->grantPermissions($role, $permissions); $assigned_permissions = Role::load($role->id())->getPermissions(); $missing_permissions = array_diff($permissions, $assigned_permissions); - if (!$missing_permissions) { - $this->pass(new FormattableMarkup('Created permissions: @perms', ['@perms' => implode(', ', $permissions)]), 'Role'); - } - else { - $this->fail(new FormattableMarkup('Failed to create permissions: @perms', ['@perms' => implode(', ', $missing_permissions)]), 'Role'); - } + $this->assertEmpty($missing_permissions); } return $role->id(); } diff --git a/core/modules/views/src/Tests/AssertViewsCacheTagsTrait.php b/core/modules/views/src/Tests/AssertViewsCacheTagsTrait.php index 26c1ffe0b527..d2033a92e2fe 100644 --- a/core/modules/views/src/Tests/AssertViewsCacheTagsTrait.php +++ b/core/modules/views/src/Tests/AssertViewsCacheTagsTrait.php @@ -50,13 +50,12 @@ protected function assertViewsCacheTags(ViewExecutable $view, $expected_results_ $request_stack->push($request); $renderer->renderRoot($build); - // Render array cache tags. - $this->pass('Checking render array cache tags.'); + // Check render array cache tags. sort($expected_render_array_cache_tags); $this->assertEqual($build['#cache']['tags'], $expected_render_array_cache_tags); if ($views_caching_is_enabled) { - $this->pass('Checking Views results cache item cache tags.'); + // Check Views render cache item cache tags. /** @var \Drupal\views\Plugin\views\cache\CachePluginBase $cache_plugin */ $cache_plugin = $view->display_handler->getPlugin('cache'); @@ -76,8 +75,7 @@ protected function assertViewsCacheTags(ViewExecutable $view, $expected_results_ $this->assertNull($results_cache_item, 'Results cache item not found.'); } - $this->pass('Checking Views render cache item cache tags.'); - + // Check Views render cache item cache tags. $original['#cache'] += ['contexts' => []]; $original['#cache']['contexts'] = Cache::mergeContexts($original['#cache']['contexts'], $this->container->getParameter('renderer.config')['required_cache_contexts']); @@ -132,12 +130,11 @@ protected function assertViewsCacheTagsFromStaticRenderArray(ViewExecutable $vie $request_stack->push($request); $renderer->renderRoot($build); - // Render array cache tags. - $this->pass('Checking render array cache tags.'); + // Check render array cache tags. sort($expected_render_array_cache_tags); $this->assertEqual($build['#cache']['tags'], $expected_render_array_cache_tags); - $this->pass('Checking Views render cache item cache tags.'); + // Check Views render cache item cache tags. $original['#cache'] += ['contexts' => []]; $original['#cache']['contexts'] = Cache::mergeContexts($original['#cache']['contexts'], $this->container->getParameter('renderer.config')['required_cache_contexts']); diff --git a/core/tests/Drupal/KernelTests/AssertContentTrait.php b/core/tests/Drupal/KernelTests/AssertContentTrait.php index ea06d26f18f9..0357a6b41117 100644 --- a/core/tests/Drupal/KernelTests/AssertContentTrait.php +++ b/core/tests/Drupal/KernelTests/AssertContentTrait.php @@ -127,16 +127,12 @@ protected function parse() { $html_dom = new \DOMDocument(); @$html_dom->loadHTML('<?xml encoding="UTF-8">' . $this->getRawContent()); if ($html_dom) { - $this->pass(new FormattableMarkup('Valid HTML found on "@path"', ['@path' => $this->getUrl()]), 'Browser'); // It's much easier to work with simplexml than DOM, luckily enough // we can just simply import our DOM tree. $this->elements = simplexml_import_dom($html_dom); } } - if ($this->elements === FALSE) { - $this->fail('Parsed page successfully.', 'Browser'); - } - + $this->assertNotFalse($this->elements, 'The current HTML page should be available for DOM navigation.'); return $this->elements; } diff --git a/core/tests/Drupal/Tests/SchemaCheckTestTrait.php b/core/tests/Drupal/Tests/SchemaCheckTestTrait.php index 96a0a7f80499..73f8dc5c8c6c 100644 --- a/core/tests/Drupal/Tests/SchemaCheckTestTrait.php +++ b/core/tests/Drupal/Tests/SchemaCheckTestTrait.php @@ -4,7 +4,6 @@ use Drupal\Core\Config\TypedConfigManagerInterface; use Drupal\Core\Config\Schema\SchemaCheckTrait; -use Drupal\Component\Render\FormattableMarkup; /** * Provides a class for checking configuration schema. @@ -24,25 +23,19 @@ trait SchemaCheckTestTrait { * The configuration data. */ public function assertConfigSchema(TypedConfigManagerInterface $typed_config, $config_name, $config_data) { - $errors = $this->checkConfigSchema($typed_config, $config_name, $config_data); - if ($errors === FALSE) { - // @todo Since the use of this trait is under TestBase, it works. - // Can be fixed as part of https://www.drupal.org/node/2260053. - $this->fail(new FormattableMarkup('No schema for @config_name', ['@config_name' => $config_name])); - return; + $check = $this->checkConfigSchema($typed_config, $config_name, $config_data); + $message = ''; + if ($check === FALSE) { + $message = 'Error: No schema exists.'; } - elseif ($errors === TRUE) { - // @todo Since the use of this trait is under TestBase, it works. - // Can be fixed as part of https://www.drupal.org/node/2260053. - $this->pass(new FormattableMarkup('Schema found for @config_name and values comply with schema.', ['@config_name' => $config_name])); - } - else { - foreach ($errors as $key => $error) { - // @todo Since the use of this trait is under TestBase, it works. - // Can be fixed as part of https://www.drupal.org/node/2260053. - $this->fail(new FormattableMarkup('Schema key @key failed with: @error', ['@key' => $key, '@error' => $error])); + elseif ($check !== TRUE) { + $this->assertIsArray($check, "The config schema check errors should be in the form of an array."); + $message = "Errors:\n"; + foreach ($check as $key => $error) { + $message .= "Schema key $key failed with: $error\n"; } } + $this->assertTrue($check, "There should be no errors in configuration '$config_name'. $message"); } /** diff --git a/core/tests/Drupal/Tests/Traits/Core/Config/SchemaConfigListenerTestTrait.php b/core/tests/Drupal/Tests/Traits/Core/Config/SchemaConfigListenerTestTrait.php index b399990af3f6..d0416aa7d88d 100644 --- a/core/tests/Drupal/Tests/Traits/Core/Config/SchemaConfigListenerTestTrait.php +++ b/core/tests/Drupal/Tests/Traits/Core/Config/SchemaConfigListenerTestTrait.php @@ -20,7 +20,6 @@ public function testConfigSchemaChecker() { $this->fail($message); } catch (SchemaIncompleteException $e) { - $this->pass($message); $this->assertEqual('No schema for config_schema_test.schemaless', $e->getMessage()); } @@ -29,7 +28,6 @@ public function testConfigSchemaChecker() { $config = $this->config('config_test.types')->set('int', 10); try { $config->save(); - $this->pass($message); } catch (SchemaIncompleteException $e) { $this->fail($message); @@ -42,7 +40,6 @@ public function testConfigSchemaChecker() { $config->get('int'); try { $config->save(); - $this->pass($message); } catch (SchemaIncompleteException $e) { $this->fail($message); @@ -58,7 +55,6 @@ public function testConfigSchemaChecker() { $this->fail($message); } catch (SchemaIncompleteException $e) { - $this->pass($message); $this->assertEqual('Schema errors for config_test.types with the following errors: config_test.types:array variable type is integer but applied schema class is Drupal\Core\Config\Schema\Sequence, config_test.types:foo missing schema', $e->getMessage()); } -- GitLab