Browse Source

Fix tests

8.x-2.x
Chi 2 years ago
parent
commit
68bb4e5505
  1. 2
      src/TwigExtension.php
  2. 15
      tests/src/Functional/TwigTweakTest.php
  3. 28
      tests/src/Kernel/AccessTest.php
  4. 8
      tests/twig_tweak_test/config/install/block.block.claro_powered_by_drupal.yml
  5. 17
      tests/twig_tweak_test/config/install/block.block.classy_page_title.yml
  6. 19
      tests/twig_tweak_test/config/install/block.block.classy_status_messages.yml
  7. 4
      tests/twig_tweak_test/templates/twig-tweak-test.html.twig

2
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);

15
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.

28
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,

8
tests/twig_tweak_test/config/install/block.block.classy_powered_by_drupal.yml → 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

17
tests/twig_tweak_test/config/install/block.block.classy_page_title.yml

@ -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: { }

19
tests/twig_tweak_test/config/install/block.block.classy_status_messages.yml

@ -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: { }

4
tests/twig_tweak_test/templates/twig-tweak-test.html.twig

@ -23,10 +23,10 @@
<div class="tt-view-result">{{ drupal_view_result('twig_tweak_test', 'page_1')|length }}</div>
<div class="tt-block">{{ drupal_block('system_branding_block', {use_site_name: false}, false) }}</div>
<div class="tt-block-with-wrapper">{{ drupal_block('system_branding_block', {label: 'Branding'}) }}</div>
<div class="tt-region">{{ drupal_region('sidebar_first') }}</div>
<div class="tt-region">{{ drupal_region('highlighted') }}</div>
<div class="tt-entity-default">{{ drupal_entity('node', 1) }}</div>
<div class="tt-entity-teaser">{{ drupal_entity('node', 1, 'teaser') }}</div>
<div class="tt-entity-from-url">{{ drupal_entity('node') }}</div>
<div class="tt-entity-from-url">{{ drupal_entity('node', view_mode='teaser') }}</div>
<div class="tt-entity-add-form">{{ drupal_entity_form('node', values={type: 'page'}) }}</div>
<div class="tt-entity-edit-form">{{ drupal_entity_form('node', 1) }}</div>
<div class="tt-field">{{ drupal_field('body', 'node', 1) }}</div>

Loading…
Cancel
Save