You are here

CatalogBreadcrumbTest.php in Ubercart 8.4

File

uc_catalog/tests/src/Functional/CatalogBreadcrumbTest.php
View source
<?php

namespace Drupal\Tests\uc_catalog\Functional;


/**
 * Tests for the Ubercart catalog breadcrumbs.
 *
 * @group ubercart
 */
class CatalogBreadcrumbTest extends CatalogTestBase {

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
    $this
      ->drupalPlaceBlock('system_breadcrumb_block');
  }

  /**
   * Tests the product node breadcrumb.
   */
  public function testProductBreadcrumb() {
    $this
      ->drupalLogin($this->adminUser);
    $grandparent = $this
      ->createCatalogTerm();
    $parent = $this
      ->createCatalogTerm([
      'parent' => $grandparent
        ->id(),
    ]);
    $term = $this
      ->createCatalogTerm([
      'parent' => $parent
        ->id(),
    ]);
    $product = $this
      ->createProduct([
      'taxonomy_catalog' => [
        $term
          ->id(),
      ],
    ]);
    $this
      ->drupalGet($product
      ->toUrl());

    // Fetch each node title in the current breadcrumb.
    $links = $this
      ->xpath('//nav[@class="breadcrumb"]/ol/li/a');
    $func = function ($element) {
      return $element
        ->getText();
    };
    $links = array_map($func, $links);
    $this
      ->assertCount(5, $links, 'The correct number of links were found.');
    $this
      ->assertEquals('Home', $links[0]);
    $this
      ->assertEquals('Catalog', $links[1]);
    $this
      ->assertEquals($grandparent
      ->label(), $links[2]);
    $this
      ->assertEquals($parent
      ->label(), $links[3]);
    $this
      ->assertEquals($term
      ->label(), $links[4]);
  }

  /**
   * Tests the catalog view breadcrumb.
   */
  public function testCatalogBreadcrumb() {
    $this
      ->drupalLogin($this->adminUser);
    $grandparent = $this
      ->createCatalogTerm();
    $parent = $this
      ->createCatalogTerm([
      'parent' => $grandparent
        ->id(),
    ]);
    $term = $this
      ->createCatalogTerm([
      'parent' => $parent
        ->id(),
    ]);
    $product = $this
      ->createProduct([
      'taxonomy_catalog' => [
        $term
          ->id(),
      ],
    ]);
    $this
      ->drupalGet('catalog');
    $this
      ->clickLink($grandparent
      ->label());
    $this
      ->clickLink($parent
      ->label());
    $this
      ->clickLink($term
      ->label());

    // Fetch each node title in the current breadcrumb.
    $links = $this
      ->xpath('//nav[@class="breadcrumb"]/ol/li/a');
    $func = function ($element) {
      return $element
        ->getText();
    };
    $links = array_map($func, $links);
    $this
      ->assertCount(4, $links, 'The correct number of links were found.');
    $this
      ->assertEquals('Home', $links[0]);
    $this
      ->assertEquals('Catalog', $links[1]);
    $this
      ->assertEquals($grandparent
      ->label(), $links[2]);
    $this
      ->assertEquals($parent
      ->label(), $links[3]);
  }

}

Classes

Namesort descending Description
CatalogBreadcrumbTest Tests for the Ubercart catalog breadcrumbs.