Browse Source

Clean-up tests

merge-requests/4/head
Chi 5 years ago
parent
commit
50c7bbb671
  1. 104
      tests/src/Functional/TwigTweakTest.php

104
tests/src/Functional/TwigTweakTest.php

@ -100,7 +100,7 @@ class TwigTweakTest extends BrowserTestBase {
\Drupal::service('cache_tags.invalidator')->invalidateTags(['block_view']);
$this->drupalGet('<front>');
// Test default views display.
// -- Test default views display.
$xpath = '//div[@class = "tt-view-default"]';
$xpath .= '//div[contains(@class, "view-twig-tweak-test") and contains(@class, "view-display-id-default")]';
$xpath .= '/div[@class = "view-content"]//ul[count(./li) = 3]/li';
@ -108,7 +108,7 @@ class TwigTweakTest extends BrowserTestBase {
$this->assertByXpath($xpath . '//a[contains(@href, "/node/2") and text() = "Beta"]');
$this->assertByXpath($xpath . '//a[contains(@href, "/node/3") and text() = "Gamma"]');
// Test page_1 view display.
// -- Test page_1 view display.
$xpath = '//div[@class = "tt-view-page_1"]';
$xpath .= '//div[contains(@class, "view-twig-tweak-test") and contains(@class, "view-display-id-page_1")]';
$xpath .= '/div[@class = "view-content"]//ul[count(./li) = 3]/li';
@ -116,22 +116,22 @@ class TwigTweakTest extends BrowserTestBase {
$this->assertByXpath($xpath . '//a[contains(@href, "/node/2") and text() = "Beta"]');
$this->assertByXpath($xpath . '//a[contains(@href, "/node/3") and text() = "Gamma"]');
// Test view argument.
// -- Test view argument.
$xpath = '//div[@class = "tt-view-page_1-with-argument"]';
$xpath .= '//div[contains(@class, "view-twig-tweak-test")]';
$xpath .= '/div[@class = "view-content"]//ul[count(./li) = 1]/li';
$this->assertByXpath($xpath . '//a[contains(@href, "/node/1") and text() = "Alpha"]');
// Test view result.
// -- Test view result.
$xpath = '//div[@class = "tt-view-result" and text() = 3]';
$this->assertByXpath($xpath);
// Test block.
// -- Test block.
$xpath = '//div[@class = "tt-block"]';
$xpath .= '/img[contains(@src, "/core/themes/classy/logo.svg") and @alt="Home"]';
$this->assertByXpath($xpath);
// Test block with wrapper.
// -- 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"]';
@ -139,25 +139,25 @@ class TwigTweakTest extends BrowserTestBase {
$xpath .= '/following-sibling::div[@class = "site-name"]/a';
$this->assertByXpath($xpath);
// Test region.
// -- 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"]';
$this->assertByXpath($xpath);
// Test entity default view mode.
// -- Test entity default view mode.
$xpath = '//div[@class = "tt-entity-default"]';
$xpath .= '/article[contains(@class, "node") and not(contains(@class, "node--view-mode-teaser"))]';
$xpath .= '/h2/a/span[text() = "Alpha"]';
$this->assertByXpath($xpath);
// Test entity teaser view mode.
// -- Test entity teaser view mode.
$xpath = '//div[@class = "tt-entity-teaser"]';
$xpath .= '/article[contains(@class, "node") and contains(@class, "node--view-mode-teaser")]';
$xpath .= '/h2/a/span[text() = "Alpha"]';
$this->assertByXpath($xpath);
// Test loading entity from url.
// -- Test loading entity from URL.
$xpath = '//div[@class = "tt-entity-from-url" and not(text())]';
$this->assertByXpath($xpath);
$this->drupalGet('/node/2');
@ -166,11 +166,11 @@ class TwigTweakTest extends BrowserTestBase {
$xpath .= '/h2/a/span[text() = "Beta"]';
$this->assertByXpath($xpath);
// Test access to entity add form.
// -- Test access to entity add form.
$xpath = '//div[@class = "tt-entity-add-form"]/form';
$this->assertSession()->elementNotExists('xpath', $xpath);
// Test access to entity edit form.
// -- Test access to entity edit form.
$xpath = '//div[@class = "tt-entity-edit-form"]/form';
$this->assertSession()->elementNotExists('xpath', $xpath);
@ -179,114 +179,114 @@ class TwigTweakTest extends BrowserTestBase {
$this->grantPermissions(Role::load(Role::ANONYMOUS_ID), $permissions);
$this->drupalGet('/node/2');
// Test entity add form.
// -- 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"]';
$this->assertByXpath($xpath);
// Test entity edit form.
// -- 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"]';
$this->assertByXpath($xpath);
// Test field.
// -- Test field.
$xpath = '//div[@class = "tt-field"]/div[contains(@class, "field--name-body")]/p[text() != ""]';
$this->assertByXpath($xpath);
// Test menu (default).
// -- Test menu (default).
$xpath = '//div[@class = "tt-menu-default"]/ul[@class = "menu"]/li/a[text() = "Link 1"]/../ul[@class = "menu"]/li/ul[@class = "menu"]/li/a[text() = "Link 3"]';
$this->assertByXpath($xpath);
// Test menu (level).
// -- Test menu (level).
$xpath = '//div[@class = "tt-menu-level"]/ul[@class = "menu"]/li/a[text() = "Link 2"]/../ul[@class = "menu"]/li/a[text() = "Link 3"]';
$this->assertByXpath($xpath);
// Test menu (depth).
// -- Test menu (depth).
$xpath = '//div[@class = "tt-menu-depth"]/ul[@class = "menu"]/li[not(ul)]/a[text() = "Link 1"]';
$this->assertByXpath($xpath);
// Test form.
// -- Test form.
$xpath = '//div[@class = "tt-form"]/form[@class="system-cron-settings"]/input[@type = "submit" and @value = "Run cron"]';
$this->assertByXpath($xpath);
// Test image by FID.
// -- Test image by FID.
$xpath = '//div[@class = "tt-image-by-fid"]/img[contains(@src, "/files/image-test.png")]';
$this->assertByXpath($xpath);
// Test image by URI.
// -- Test image by URI.
$xpath = '//div[@class = "tt-image-by-uri"]/img[contains(@src, "/files/image-test.png")]';
$this->assertByXpath($xpath);
// Test image by UUID.
// -- Test image by UUID.
$xpath = '//div[@class = "tt-image-by-uuid"]/img[contains(@src, "/files/image-test.png")]';
$this->assertByXpath($xpath);
// Test image with style.
// -- Test image with style.
$xpath = '//div[@class = "tt-image-with-style"]/img[contains(@src, "/files/styles/thumbnail/public/image-test.png")]';
$this->assertByXpath($xpath);
// Test image with responsive style.
// -- Test image with responsive style.
$xpath = '//div[@class = "tt-image-with-responsive-style"]/picture/img[contains(@src, "/files/image-test.png")]';
$this->assertByXpath($xpath);
// Test token.
// -- Test token.
$xpath = '//div[@class = "tt-token" and text() = "Drupal"]';
$this->assertByXpath($xpath);
// Test token with context.
// -- Test token with context.
$xpath = '//div[@class = "tt-token-data" and text() = "Beta"]';
$this->assertByXpath($xpath);
// Test config.
// -- Test config.
$xpath = '//div[@class = "tt-config" and text() = "Anonymous"]';
$this->assertByXpath($xpath);
// Test page title.
// -- Test page title.
$xpath = '//div[@class = "tt-title" and text() = "Beta"]';
$this->assertByXpath($xpath);
// Test URL.
// -- Test URL.
$url = Url::fromUserInput('/node/1', ['absolute' => TRUE])->toString();
$xpath = sprintf('//div[@class = "tt-url"]/div[@data-case="default" and text() = "%s"]', $url);
$this->assertByXpath($xpath);
// Test URL (with langcode).
// -- Test URL (with langcode).
$url = str_replace('node/1', 'ru/node/1', $url);
$xpath = sprintf('//div[@class = "tt-url"]/div[@data-case="with-langcode" and text() = "%s"]', $url);
$this->assertByXpath($xpath);
// Test link.
// -- Test link.
$url = Url::fromUserInput('/node/1/edit', ['absolute' => TRUE]);
$link = Link::fromTextAndUrl('Edit', $url)->toString();
$xpath = '//div[@class = "tt-link"]';
self::assertEquals($link, trim($this->xpath($xpath)[0]->getHtml()));
// Test link with HTML.
// -- Test link with HTML.
$text = Markup::create('<b>Edit</b>');
$url = Url::fromUserInput('/node/1/edit', ['absolute' => TRUE]);
$link = Link::fromTextAndUrl($text, $url)->toString();
$xpath = '//div[@class = "tt-link-html"]';
self::assertEquals($link, trim($this->xpath($xpath)[0]->getHtml()));
// Test status messages.
// -- Test status messages.
$xpath = '//div[@class = "tt-messages"]//div[contains(@class, "messages--status") and contains(., "Hello world!")]';
$this->assertByXpath($xpath);
// Test breadcrumb.
// -- Test breadcrumb.
$xpath = '//div[@class = "tt-breadcrumb"]/nav[@class = "breadcrumb"]/ol/li/a[text() = "Home"]';
$this->assertByXpath($xpath);
// Test protected link.
// -- Test protected link.
$xpath = '//div[@class = "tt-link-access"]';
self::assertEquals('', trim($this->xpath($xpath)[0]->getHtml()));
// Test token replacement.
// -- Test token replacement.
$xpath = '//div[@class = "tt-token-replace" and text() = "Site name: Drupal"]';
$this->assertByXpath($xpath);
// Test contextual links.
// -- Test contextual links.
$xpath = '//div[@class="tt-contextual-links" and not(div[@data-contextual-id])]';
$this->assertByXpath($xpath);
@ -295,65 +295,65 @@ class TwigTweakTest extends BrowserTestBase {
$xpath = '//div[@class="tt-contextual-links" and div[@data-contextual-id]]';
$this->assertByXpath($xpath);
// Test preg replacement.
// -- Test preg replacement.
$xpath = '//div[@class = "tt-preg-replace" and text() = "FOO-bar"]';
$this->assertByXpath($xpath);
// Test image style.
// -- Test image style.
$xpath = '//div[@class = "tt-image-style" and contains(text(), "styles/thumbnail/public/images/ocean.jpg")]';
$this->assertByXpath($xpath);
// Test transliteration.
// -- Test transliteration.
$xpath = '//div[@class = "tt-transliterate" and contains(text(), "Privet!")]';
$this->assertByXpath($xpath);
// Test text format.
// -- Test text format.
$xpath = '//div[@class = "tt-check-markup"]';
self::assertEquals('<b>bold</b> strong', trim($this->xpath($xpath)[0]->getHtml()));
// Test truncation.
// -- Test truncation.
$xpath = '//div[@class = "tt-truncate" and text() = "Hello…"]';
$this->assertByXpath($xpath);
// Test 'with'.
// -- Test 'with'.
$xpath = '//div[@class = "tt-with"]/b[text() = "Example"]';
$this->assertByXpath($xpath);
// Test nested 'with'.
// -- Test nested 'with'.
$xpath = '//div[@class = "tt-with-nested" and text() = "{alpha:{beta:{gamma:456}}}"]';
$this->assertByXpath($xpath);
// Test 'children'.
// -- Test 'children'.
$xpath = '//div[@class = "tt-children" and text() = "doremi"]';
$this->assertByXpath($xpath);
// Test node view.
// -- Test entity view.
$xpath = '//div[@class = "tt-node-view"]/article[contains(@class, "node--view-mode-default")]/h2[a/span[text() = "Beta"]]';
$xpath .= '/following-sibling::div[@class = "node__content"]/div/p';
$this->assertByXpath($xpath);
// Field list view.
// -- Test Field list view.
$xpath = '//div[@class = "tt-field-list-view"]/span[contains(@class, "field--name-title") and text() = "Beta"]';
$this->assertByXpath($xpath);
// Field item view.
// -- Test field item view.
$xpath = '//div[@class = "tt-field-item-view" and text() = "Beta"]';
$this->assertByXpath($xpath);
// Test file URL from URI.
// -- Test file URL from URI.
$xpath = '//div[@class = "tt-file-url-from-uri" and contains(text(), "/files/image-test.png")]';
$this->assertByXpath($xpath);
// Test file URL from image field.
// -- Test file URL from image field.
$this->drupalGet('/node/1');
$xpath = '//div[@class = "tt-file-url-from-image-field" and contains(text(), "/files/image-test.png")]';
$this->assertByXpath($xpath);
// Test file URL from a specific image field item.
// -- Test file URL from a specific image field item.
$xpath = '//div[@class = "tt-file-url-from-image-field-delta" and contains(text(), "/files/image-test.png")]';
$this->assertByXpath($xpath);
// Test file URL from media field.
// -- Test file URL from media field.
$xpath = '//div[@class = "tt-file-url-from-media-field" and contains(text(), "/files/image-1.png")]';
$this->assertByXpath($xpath);
}

Loading…
Cancel
Save