Browse Source

Fix tests

merge-requests/17/head
Chi 2 years ago
parent
commit
f2805a1cc1
  1. 17
      tests/src/Functional/TwigTweakTest.php
  2. 14
      tests/src/Kernel/RegionViewBuilderTest.php
  3. 10
      tests/twig_tweak_test/config/install/block.block.claro_powered_by_drupal.yml
  4. 19
      tests/twig_tweak_test/config/install/block.block.classy_content.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. 2
      tests/twig_tweak_test/templates/twig-tweak-test.html.twig

17
tests/src/Functional/TwigTweakTest.php

@ -26,7 +26,7 @@ final class TwigTweakTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'classy';
protected $defaultTheme = 'claro';
/**
* {@inheritdoc}
@ -134,21 +134,20 @@ final class TwigTweakTest extends BrowserTestBase {
// -- 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->assertXpath($xpath);
// -- 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->assertXpath($xpath);
// -- 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() = "Twig Tweak Test"]]';
$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")]/span[. = "Powered by Drupal"]';
$this->assertXpath($xpath);
// -- Entity (default view mode).
@ -191,13 +190,13 @@ final class TwigTweakTest extends BrowserTestBase {
// -- 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->assertXpath($xpath);
// -- 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->assertXpath($xpath);
// -- Field.
@ -434,7 +433,7 @@ final class TwigTweakTest extends BrowserTestBase {
}
/**
* Checks that an element specified by a the xpath exists on the current page.
* Checks that an element specified by the xpath exists on the current page.
*/
private function assertXpath(string $xpath): void {
$this->assertSession()->elementExists('xpath', $xpath);

14
tests/src/Kernel/RegionViewBuilderTest.php

@ -33,12 +33,12 @@ final class RegionViewBuilderTest extends AbstractTestCase {
public function setUp(): void {
parent::setUp();
$this->installEntitySchema('block');
$this->container->get('theme_installer')->install(['stable']);
$this->container->get('theme_installer')->install(['stark']);
$values = [
'id' => 'public_block',
'plugin' => 'system_powered_by_block',
'theme' => 'stable',
'theme' => 'stark',
'region' => 'sidebar_first',
];
Block::create($values)->save();
@ -46,7 +46,7 @@ final class RegionViewBuilderTest extends AbstractTestCase {
$values = [
'id' => 'private_block',
'plugin' => 'system_powered_by_block',
'theme' => 'stable',
'theme' => 'stark',
'region' => 'sidebar_first',
];
Block::create($values)->save();
@ -61,7 +61,7 @@ final class RegionViewBuilderTest extends AbstractTestCase {
$renderer = $this->container->get('renderer');
$build = $view_builder->build('sidebar_first');
// The build should be empty because 'stable' is not a default theme.
// The build should be empty because 'stark' is not a default theme.
$expected_build = [
'#cache' => [
'contexts' => [],
@ -72,7 +72,7 @@ final class RegionViewBuilderTest extends AbstractTestCase {
self::assertSame($expected_build, $build);
// Specify the theme name explicitly.
$build = $view_builder->build('sidebar_first', 'stable');
$build = $view_builder->build('sidebar_first', 'stark');
$expected_build = [
// Only public_block should be rendered.
// @see twig_tweak_test_block_access()
@ -129,11 +129,11 @@ final class RegionViewBuilderTest extends AbstractTestCase {
$actual_html = $renderer->renderPlain($build);
self::assertSame(self::normalizeHtml($expected_html), self::normalizeHtml($actual_html));
// Set 'stable' as default site theme and check if the view builder without
// Set 'stark' as default site theme and check if the view builder without
// 'theme' argument returns the same result.
$this->container->get('config.factory')
->getEditable('system.theme')
->set('default', 'stable')
->set('default', 'stark')
->save();
$build = $view_builder->build('sidebar_first');

10
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,11 +4,11 @@ dependencies:
module:
- system
theme:
- classy
id: classy_powered_by_drupal
theme: classy
region: sidebar_first
weight: 20
- claro
id: claro_powered_by_drupal
theme: claro
region: highlighted
weight: 0
provider: null
plugin: system_powered_by_block
settings:

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

@ -1,19 +0,0 @@
langcode: en
status: true
dependencies:
module:
- system
theme:
- classy
id: classy_content
theme: classy
region: content
weight: 0
provider: null
plugin: system_main_block
settings:
id: system_main_block
label: 'Main page content'
provider: system
label_display: '0'
visibility: { }

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

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

@ -30,7 +30,7 @@
<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-uuid">{{ drupal_entity('node', 'ad1b902a-344f-41d1-8c61-a69f0366dbfa') }}</div>

Loading…
Cancel
Save