Verified Commit 435dc201 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3248295 by danflanagan8, xjm, dww, mglaman: Taxonomy tests should not rely on Classy

parent 4fa09fb8
Loading
Loading
Loading
Loading
+18 −15
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\taxonomy\Entity\Term;
use Drupal\Tests\system\Functional\Menu\AssertBreadcrumbTrait;

/**
 * Tests load, save and delete for taxonomy terms.
@@ -14,6 +15,8 @@
 */
class TermTest extends TaxonomyTestBase {

  use AssertBreadcrumbTrait;

  /**
   * Vocabulary for testing.
   *
@@ -38,7 +41,7 @@ class TermTest extends TaxonomyTestBase {
  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'classy';
  protected $defaultTheme = 'stark';

  /**
   * {@inheritdoc}
@@ -384,12 +387,12 @@ public function testTermInterface() {
    $this->assertSession()->pageTextContains($edit['description[0][value]']);

    // Did this page request display a 'term-listing-heading'?
    $this->assertSession()->elementExists('xpath', '//div[contains(@class, "field--name-description")]');
    $this->assertSession()->elementExists('xpath', '//div[@class="views-element-container"]/div/header/div/div/p');
    // Check that it does NOT show a description when description is blank.
    $term->setDescription(NULL);
    $term->save();
    $this->drupalGet('taxonomy/term/' . $term->id());
    $this->assertSession()->elementNotExists('xpath', '//div[contains(@class, "field--entity-taxonomy-term--description")]');
    $this->assertSession()->elementNotExists('xpath', '//div[@class="views-element-container"]/div/header/div/div/p');

    // Check that the description value is processed.
    $value = $this->randomMachineName();
@@ -580,20 +583,20 @@ public function testTermBreadcrumbs() {
    $this->assertNotNull($term, 'Term found in database.');

    // Check the breadcrumb on the term edit page.
    $this->drupalGet('taxonomy/term/' . $term->id() . '/edit');
    $breadcrumbs = $this->getSession()->getPage()->findAll('css', 'nav.breadcrumb ol li a');
    $this->assertCount(2, $breadcrumbs, 'The breadcrumbs are present on the page.');
    $this->assertSame('Home', $breadcrumbs[0]->getText(), 'First breadcrumb text is Home');
    $this->assertSame($term->label(), $breadcrumbs[1]->getText(), 'Second breadcrumb text is term name on term edit page.');
    $this->assertSession()->assertEscaped($breadcrumbs[1]->getText());
    $trail = [
      '' => 'Home',
      'taxonomy/term/' . $term->id() => $term->label(),
    ];
    $this->assertBreadcrumb('taxonomy/term/' . $term->id() . '/edit', $trail);
    $this->assertSession()->assertEscaped($term->label());

    // Check the breadcrumb on the term delete page.
    $this->drupalGet('taxonomy/term/' . $term->id() . '/delete');
    $breadcrumbs = $this->getSession()->getPage()->findAll('css', 'nav.breadcrumb ol li a');
    $this->assertCount(2, $breadcrumbs, 'The breadcrumbs are present on the page.');
    $this->assertSame('Home', $breadcrumbs[0]->getText(), 'First breadcrumb text is Home');
    $this->assertSame($term->label(), $breadcrumbs[1]->getText(), 'Second breadcrumb text is term name on term delete page.');
    $this->assertSession()->assertEscaped($breadcrumbs[1]->getText());
    $trail = [
      '' => 'Home',
      'taxonomy/term/' . $term->id() => $term->label(),
    ];
    $this->assertBreadcrumb('taxonomy/term/' . $term->id() . '/delete', $trail);
    $this->assertSession()->assertEscaped($term->label());
  }

}
+1 −1
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ class TermTranslationTest extends TaxonomyTestBase {
  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'classy';
  protected $defaultTheme = 'stark';

  /**
   * {@inheritdoc}
+52 −11
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ class TaxonomyIndexTidUiTest extends UITestBase {
  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'classy';
  protected $defaultTheme = 'stark';

  /**
   * Modules to enable.
@@ -169,9 +169,20 @@ public function testExposedFilter() {

    // Only the nodes with the selected term should be shown.
    $this->drupalGet('test-filter-taxonomy-index-tid');
    $this->assertSession()->elementsCount('xpath', '//div[@class="view-content"]//a', 2);
    $this->assertSession()->elementsCount('xpath', "//div[@class='view-content']//a[@href='{$node2->toUrl()->toString()}']", 1);
    $this->assertSession()->elementsCount('xpath', "//div[@class='view-content']//a[@href='{$node3->toUrl()->toString()}']", 1);
    $this->assertSession()->pageTextNotContains($node1->getTitle());
    $this->assertSession()->linkByHrefNotExists($node1->toUrl()->toString());
    $xpath_node2_link = $this->assertSession()->buildXPathQuery('//div[@class="views-row"]//a[@href=:url and text()=:label]', [
      ':url' => $node2->toUrl()->toString(),
      ':label' => $node2->label(),
    ]);
    $this->assertSession()->elementsCount('xpath', $xpath_node2_link, 1);
    $xpath_node3_link = $this->assertSession()->buildXPathQuery('//div[@class="views-row"]//a[@href=:url and text()=:label]', [
      ':url' => $node3->toUrl()->toString(),
      ':label' => $node3->label(),
    ]);
    $this->assertSession()->elementsCount('xpath', $xpath_node3_link, 1);
    $this->assertSession()->pageTextNotContains($node4->getTitle());
    $this->assertSession()->linkByHrefNotExists($node4->toUrl()->toString());

    // Expose the filter.
    $this->drupalGet('admin/structure/views/nojs/handler/test_filter_taxonomy_index_tid/default/filter/tid');
@@ -187,8 +198,17 @@ public function testExposedFilter() {
    // After switching to 'empty' operator, the node without a term should be
    // shown.
    $this->drupalGet('test-filter-taxonomy-index-tid');
    $this->assertSession()->elementsCount('xpath', '//div[@class="view-content"]//a', 1);
    $this->assertSession()->elementsCount('xpath', "//div[@class='view-content']//a[@href='{$node1->toUrl()->toString()}']", 1);
    $xpath_node1_link = $this->assertSession()->buildXPathQuery('//div[@class="views-row"]//a[@href=:url and text()=:label]', [
      ':url' => $node1->toUrl()->toString(),
      ':label' => $node1->label(),
    ]);
    $this->assertSession()->elementsCount('xpath', $xpath_node1_link, 1);
    $this->assertSession()->pageTextNotContains($node2->getTitle());
    $this->assertSession()->linkByHrefNotExists($node2->toUrl()->toString());
    $this->assertSession()->pageTextNotContains($node3->getTitle());
    $this->assertSession()->linkByHrefNotExists($node3->toUrl()->toString());
    $this->assertSession()->pageTextNotContains($node4->getTitle());
    $this->assertSession()->linkByHrefNotExists($node4->toUrl()->toString());

    // Set the operator to 'not empty'.
    $this->drupalGet('admin/structure/views/nojs/handler/test_filter_taxonomy_index_tid/default/filter/tid');
@@ -199,10 +219,23 @@ public function testExposedFilter() {
    // After switching to 'not empty' operator, all nodes with terms should be
    // shown.
    $this->drupalGet('test-filter-taxonomy-index-tid');
    $this->assertSession()->elementsCount('xpath', '//div[@class="view-content"]//a', 3);
    $this->assertSession()->elementsCount('xpath', "//div[@class='view-content']//a[@href='{$node2->toUrl()->toString()}']", 1);
    $this->assertSession()->elementsCount('xpath', "//div[@class='view-content']//a[@href='{$node3->toUrl()->toString()}']", 1);
    $this->assertSession()->elementsCount('xpath', "//div[@class='view-content']//a[@href='{$node4->toUrl()->toString()}']", 1);
    $this->assertSession()->pageTextNotContains($node1->getTitle());
    $this->assertSession()->linkByHrefNotExists($node1->toUrl()->toString());
    $xpath_node2_link = $this->assertSession()->buildXPathQuery('//div[@class="views-row"]//a[@href=:url and text()=:label]', [
      ':url' => $node2->toUrl()->toString(),
      ':label' => $node2->label(),
    ]);
    $this->assertSession()->elementsCount('xpath', $xpath_node2_link, 1);
    $xpath_node3_link = $this->assertSession()->buildXPathQuery('//div[@class="views-row"]//a[@href=:url and text()=:label]', [
      ':url' => $node3->toUrl()->toString(),
      ':label' => $node3->label(),
    ]);
    $this->assertSession()->elementsCount('xpath', $xpath_node3_link, 1);
    $xpath_node4_link = $this->assertSession()->buildXPathQuery('//div[@class="views-row"]//a[@href=:url and text()=:label]', [
      ':url' => $node4->toUrl()->toString(),
      ':label' => $node4->label(),
    ]);
    $this->assertSession()->elementsCount('xpath', $xpath_node4_link, 1);

    // Select 'Term ID' as the field to be displayed.
    $edit = ['name[taxonomy_term_field_data.tid]' => TRUE];
@@ -231,7 +264,15 @@ public function testExposedFilter() {
    $this->drupalGet('admin/structure/views/view/test_taxonomy_term_name/edit/default');
    $this->submitForm([], 'Save');
    $this->submitForm([], 'Update preview');
    $this->assertSession()->elementNotExists('xpath', "//div[@class='view-content']");
    $this->assertSession()->pageTextNotContains($node1->getTitle());
    $this->assertSession()->linkByHrefNotExists($node1->toUrl()->toString());
    $this->assertSession()->pageTextNotContains($node2->getTitle());
    $this->assertSession()->linkByHrefNotExists($node2->toUrl()->toString());
    $this->assertSession()->pageTextNotContains($node3->getTitle());
    $this->assertSession()->linkByHrefNotExists($node3->toUrl()->toString());
    $this->assertSession()->pageTextNotContains($node4->getTitle());
    $this->assertSession()->linkByHrefNotExists($node4->toUrl()->toString());
    $this->assertSession()->elementNotExists('xpath', "//div[@class='views-row']");
  }

  /**
+38 −8
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@ class TermDisplayConfigurableTest extends TaxonomyTestBase {
  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'classy';
  protected $defaultTheme = 'stark';

  /**
   * Views used by this test.
@@ -32,9 +32,16 @@ public function testDisplayConfigurable() {

    // Check the taxonomy_term with default non-configurable display.
    $this->drupalGet('test_term_show_entity');
    $assert->elementTextContains('css', 'h2 > a > .field--name-name', $this->term1->getName());
    $assert->elementNotExists('css', '.field--name-name .field__item');
    $assert->elementNotExists('css', '.field--name-name .field__label');
    // Name should be linked to entity and description should be displayed.
    $assert->pageTextContains($this->term1->getName());
    $assert->linkByHrefExists($this->term1->toUrl()->toString());
    $assert->pageTextContains($this->term1->getDescription());
    $assert->pageTextContains($this->term2->getName());
    $assert->linkByHrefExists($this->term2->toUrl()->toString());
    $assert->pageTextContains($this->term2->getDescription());
    // The field labels should not be present.
    $assert->pageTextNotContains('Name');
    $assert->pageTextNotContains('Description');

    // Enable helper module to make base fields' displays configurable.
    \Drupal::service('module_installer')->install(['taxonomy_term_display_configurable_test']);
@@ -48,16 +55,39 @@ public function testDisplayConfigurable() {

    // Recheck the taxonomy_term with configurable display.
    $this->drupalGet('test_term_show_entity');
    $assert->elementTextContains('css', 'div.field--name-name > div.field__item', $this->term1->getName());
    $assert->elementExists('css', 'div.field--name-name > div.field__label');
    // The description should be the first field in each row, with no label.
    // Name field should be the second field in view row. Value should be
    // displayed after the label. It should not be linked to the term.
    $assert->pageTextContains('Name');
    $assert->pageTextNotContains('Description');
    $assert->pageTextContains($this->term1->getName());
    $assert->linkByHrefNotExists($this->term1->toUrl()->toString());
    $assert->pageTextContains($this->term1->getDescription());
    $assert->elementTextContains('xpath', '//*[@class="views-row"][1]/div/div[1]//p', $this->term1->getDescription());
    $assert->elementTextContains('xpath', '//*[@class="views-row"][1]/div/div[2]/div[1]', 'Name');
    $assert->elementTextContains('xpath', '//*[@class="views-row"][1]/div/div[2]/div[2]', $this->term1->getName());
    $assert->pageTextContains($this->term2->getName());
    $assert->linkByHrefNotExists($this->term2->toUrl()->toString());
    $assert->pageTextContains($this->term2->getDescription());
    $assert->elementTextContains('xpath', '//*[@class="views-row"][2]/div/div[1]//p', $this->term2->getDescription());
    $assert->elementTextContains('xpath', '//*[@class="views-row"][2]/div/div[2]/div[1]', 'Name');
    $assert->elementTextContains('xpath', '//*[@class="views-row"][2]/div/div[2]/div[2]', $this->term2->getName());

    // Remove 'name' field from display.
    $display->removeComponent('name')->save();

    // Recheck the taxonomy_term with 'name' field removed from display.
    // There should just be an unlabelled description. Nothing should be
    // linked to the terms.
    $this->drupalGet('test_term_show_entity');
    $assert->responseNotContains($this->term1->getName());
    $assert->elementNotExists('css', 'div.field--name-name');
    $assert->pageTextNotContains('Name');
    $assert->pageTextNotContains('Description');
    $assert->pageTextNotContains($this->term1->getName());
    $assert->linkByHrefNotExists($this->term1->toUrl()->toString());
    $assert->pageTextContains($this->term1->getDescription());
    $assert->pageTextNotContains($this->term2->getName());
    $assert->linkByHrefNotExists($this->term2->toUrl()->toString());
    $assert->pageTextContains($this->term2->getDescription());
  }

}