From 68bb4e550591813ddabaa83b19a5a533a434012b Mon Sep 17 00:00:00 2001 From: Chi Date: Fri, 23 Sep 2022 20:19:15 +0500 Subject: [PATCH] Fix tests --- src/TwigExtension.php | 2 +- tests/src/Functional/TwigTweakTest.php | 15 +++++----- tests/src/Kernel/AccessTest.php | 28 +++++++++---------- ...> block.block.claro_powered_by_drupal.yml} | 8 +++--- .../install/block.block.classy_page_title.yml | 17 ----------- .../block.block.classy_status_messages.yml | 19 ------------- .../templates/twig-tweak-test.html.twig | 4 +-- 7 files changed, 28 insertions(+), 65 deletions(-) rename tests/twig_tweak_test/config/install/{block.block.classy_powered_by_drupal.yml => block.block.claro_powered_by_drupal.yml} (76%) delete mode 100644 tests/twig_tweak_test/config/install/block.block.classy_page_title.yml delete mode 100644 tests/twig_tweak_test/config/install/block.block.classy_status_messages.yml diff --git a/src/TwigExtension.php b/src/TwigExtension.php index fd54657..52e8711 100644 --- a/src/TwigExtension.php +++ b/src/TwigExtension.php @@ -579,7 +579,7 @@ class TwigExtension extends AbstractExtension { * @return null|array * A render array for the entity or NULL if the entity does not exist. */ - public function drupalEntity($entity_type, $id = NULL, $view_mode = NULL, $langcode = NULL, $check_access = TRUE) { + public function drupalEntity($entity_type, $id = NULL, $view_mode = 'full', $langcode = NULL, $check_access = TRUE) { $entity_type_manager = \Drupal::entityTypeManager(); if ($id) { $entity = $entity_type_manager->getStorage($entity_type)->load($id); diff --git a/tests/src/Functional/TwigTweakTest.php b/tests/src/Functional/TwigTweakTest.php index 0854919..4be6707 100644 --- a/tests/src/Functional/TwigTweakTest.php +++ b/tests/src/Functional/TwigTweakTest.php @@ -25,7 +25,7 @@ class TwigTweakTest extends BrowserTestBase { /** * {@inheritdoc} */ - protected $defaultTheme = 'classy'; + protected $defaultTheme = 'claro'; /** * {@inheritdoc} @@ -133,21 +133,20 @@ class TwigTweakTest extends BrowserTestBase { // -- Test block. $xpath = '//div[@class = "tt-block"]'; - $xpath .= '/img[contains(@src, "/core/themes/classy/logo.svg") and @alt="Home"]'; + $xpath .= '/img[contains(@src, "/core/themes/claro/logo.svg") and @alt="Home"]'; $this->assertByXpath($xpath); // -- Test block with wrapper. $xpath = '//div[@class = "tt-block-with-wrapper"]'; $xpath .= '/div[@class = "block block-system block-system-branding-block"]'; $xpath .= '/h2[text() = "Branding"]'; - $xpath .= '/following-sibling::a[img[contains(@src, "/core/themes/classy/logo.svg") and @alt="Home"]]'; + $xpath .= '/following-sibling::a[img[contains(@src, "/core/themes/claro/logo.svg") and @alt="Home"]]'; $xpath .= '/following-sibling::div[@class = "site-name"]/a'; $this->assertByXpath($xpath); // -- Test region. - $xpath = '//div[@class = "tt-region"]/div[@class = "region region-sidebar-first"]'; - $xpath .= '/div[contains(@class, "block-page-title-block") and h1[@class="page-title" and text() = "Log in"]]'; - $xpath .= '/following-sibling::div[contains(@class, "block-system-powered-by-block")]/span[. = "Powered by Drupal"]'; + $xpath = '//div[@class = "tt-region"]/div[@class = "region region-highlighted"]'; + $xpath .= '/div[contains(@class, "block-system-powered-by-block")]'; $this->assertByXpath($xpath); // -- Test entity default view mode. @@ -189,13 +188,13 @@ class TwigTweakTest extends BrowserTestBase { // -- Test entity add form. $xpath = '//div[@class = "tt-entity-add-form"]/form'; $xpath .= '//input[@name = "title[0][value]" and @value = ""]'; - $xpath .= '/../../../div/input[@type = "submit" and @value = "Save"]'; + $xpath .= '/../../../../..//div/input[@type = "submit" and @value = "Save"]'; $this->assertByXpath($xpath); // -- Test entity edit form. $xpath = '//div[@class = "tt-entity-edit-form"]/form'; $xpath .= '//input[@name = "title[0][value]" and @value = "Alpha"]'; - $xpath .= '/../../../div/input[@type = "submit" and @value = "Save"]'; + $xpath .= '/../../../../..//div/input[@type = "submit" and @value = "Save"]'; $this->assertByXpath($xpath); // -- Test field. diff --git a/tests/src/Kernel/AccessTest.php b/tests/src/Kernel/AccessTest.php index 944fa0f..e5ee9f0 100644 --- a/tests/src/Kernel/AccessTest.php +++ b/tests/src/Kernel/AccessTest.php @@ -43,7 +43,7 @@ class AccessTest extends KernelTestBase { /** * {@inheritdoc} */ - public static $modules = [ + protected static $modules = [ 'twig_tweak', 'twig_tweak_test', 'node', @@ -97,8 +97,8 @@ class AccessTest extends KernelTestBase { self::assertArrayHasKey('#node', $build); $expected_cache = [ 'tags' => [ - 'node:1', 'node_view', + 'node:1', ], 'contexts' => [], 'max-age' => Cache::PERMANENT, @@ -112,8 +112,8 @@ class AccessTest extends KernelTestBase { self::assertArrayHasKey('#node', $build); $expected_cache = [ 'tags' => [ - 'node:1', 'node_view', + 'node:1', 'tag_from_twig_tweak_test_node_access', ], 'contexts' => [ @@ -129,8 +129,8 @@ class AccessTest extends KernelTestBase { self::assertArrayHasKey('#node', $build); $expected_cache = [ 'tags' => [ - 'node:1', 'node_view', + 'node:1', ], 'contexts' => [], 'max-age' => Cache::PERMANENT, @@ -170,8 +170,8 @@ class AccessTest extends KernelTestBase { 'user.permissions', ], 'tags' => [ - 'node:1', 'tag_from_twig_tweak_test_node_access', + 'node:1', ], 'max-age' => 50, ]; @@ -205,8 +205,8 @@ class AccessTest extends KernelTestBase { $expected_cache = [ 'contexts' => ['user.roles:authenticated'], 'tags' => [ - 'config:core.entity_form_display.node.article.default', 'node:1', + 'config:core.entity_form_display.node.article.default', ], 'max-age' => Cache::PERMANENT, ]; @@ -219,13 +219,13 @@ class AccessTest extends KernelTestBase { self::assertArrayHasKey('#form_id', $build); $expected_cache = [ 'contexts' => [ + 'user.roles:authenticated', 'user', 'user.permissions', - 'user.roles:authenticated', ], 'tags' => [ - 'config:core.entity_form_display.node.article.default', 'node:1', + 'config:core.entity_form_display.node.article.default', 'tag_from_twig_tweak_test_node_access', ], 'max-age' => 50, @@ -238,8 +238,8 @@ class AccessTest extends KernelTestBase { $expected_cache = [ 'contexts' => ['user.roles:authenticated'], 'tags' => [ - 'config:core.entity_form_display.node.article.default', 'node:1', + 'config:core.entity_form_display.node.article.default', ], 'max-age' => Cache::PERMANENT, ]; @@ -279,8 +279,8 @@ class AccessTest extends KernelTestBase { self::assertArrayHasKey('form_id', $build); $expected_cache = [ 'contexts' => [ - 'user.permissions', 'user.roles:authenticated', + 'user.permissions', ], 'tags' => ['config:core.entity_form_display.node.article.default'], 'max-age' => Cache::PERMANENT, @@ -292,8 +292,8 @@ class AccessTest extends KernelTestBase { self::assertArrayHasKey('form_id', $build); $expected_cache = [ 'contexts' => [ - 'user.permissions', 'user.roles:authenticated', + 'user.permissions', ], 'tags' => ['config:core.entity_form_display.node.article.default'], 'max-age' => Cache::PERMANENT, @@ -525,8 +525,8 @@ class AccessTest extends KernelTestBase { self::assertArrayHasKey('#node', $build); $expected_cache = [ 'tags' => [ - 'node:1', 'node_view', + 'node:1', ], 'contexts' => [], 'max-age' => Cache::PERMANENT, @@ -540,8 +540,8 @@ class AccessTest extends KernelTestBase { self::assertArrayHasKey('#node', $build); $expected_cache = [ 'tags' => [ - 'node:1', 'node_view', + 'node:1', 'tag_from_twig_tweak_test_node_access', ], 'contexts' => [ @@ -557,8 +557,8 @@ class AccessTest extends KernelTestBase { self::assertArrayHasKey('#node', $build); $expected_cache = [ 'tags' => [ - 'node:1', 'node_view', + 'node:1', ], 'contexts' => [], 'max-age' => Cache::PERMANENT, diff --git a/tests/twig_tweak_test/config/install/block.block.classy_powered_by_drupal.yml b/tests/twig_tweak_test/config/install/block.block.claro_powered_by_drupal.yml similarity index 76% rename from tests/twig_tweak_test/config/install/block.block.classy_powered_by_drupal.yml rename to tests/twig_tweak_test/config/install/block.block.claro_powered_by_drupal.yml index ad953f9..86227ab 100644 --- a/tests/twig_tweak_test/config/install/block.block.classy_powered_by_drupal.yml +++ b/tests/twig_tweak_test/config/install/block.block.claro_powered_by_drupal.yml @@ -4,10 +4,10 @@ dependencies: module: - system theme: - - classy -id: classy_powered_by_drupal -theme: classy -region: sidebar_first + - claro +id: claro_powered_by_drupal +theme: claro +region: highlighted weight: 20 provider: null plugin: system_powered_by_block diff --git a/tests/twig_tweak_test/config/install/block.block.classy_page_title.yml b/tests/twig_tweak_test/config/install/block.block.classy_page_title.yml deleted file mode 100644 index 3dd4f0c..0000000 --- a/tests/twig_tweak_test/config/install/block.block.classy_page_title.yml +++ /dev/null @@ -1,17 +0,0 @@ -langcode: en -status: true -dependencies: - theme: - - classy -id: classy_page_title -theme: classy -region: sidebar_first -weight: 0 -provider: null -plugin: page_title_block -settings: - id: page_title_block - label: 'Page title' - provider: core - label_display: '0' -visibility: { } diff --git a/tests/twig_tweak_test/config/install/block.block.classy_status_messages.yml b/tests/twig_tweak_test/config/install/block.block.classy_status_messages.yml deleted file mode 100644 index 19bd131..0000000 --- a/tests/twig_tweak_test/config/install/block.block.classy_status_messages.yml +++ /dev/null @@ -1,19 +0,0 @@ -langcode: en -status: true -dependencies: - module: - - system - theme: - - classy -id: classy_status_messages -theme: classy -region: sidebar_first -weight: 10 -provider: null -plugin: system_messages_block -settings: - id: system_messages_block - label: 'Status messages' - provider: system - label_display: '0' -visibility: { } diff --git a/tests/twig_tweak_test/templates/twig-tweak-test.html.twig b/tests/twig_tweak_test/templates/twig-tweak-test.html.twig index 49df8ef..4a95e64 100644 --- a/tests/twig_tweak_test/templates/twig-tweak-test.html.twig +++ b/tests/twig_tweak_test/templates/twig-tweak-test.html.twig @@ -23,10 +23,10 @@
{{ drupal_view_result('twig_tweak_test', 'page_1')|length }}
{{ drupal_block('system_branding_block', {use_site_name: false}, false) }}
{{ drupal_block('system_branding_block', {label: 'Branding'}) }}
-
{{ drupal_region('sidebar_first') }}
+
{{ drupal_region('highlighted') }}
{{ drupal_entity('node', 1) }}
{{ drupal_entity('node', 1, 'teaser') }}
-
{{ drupal_entity('node') }}
+
{{ drupal_entity('node', view_mode='teaser') }}
{{ drupal_entity_form('node', values={type: 'page'}) }}
{{ drupal_entity_form('node', 1) }}
{{ drupal_field('body', 'node', 1) }}