CatalogBreadcrumbTest.php in Ubercart 8.4
File
uc_catalog/tests/src/Functional/CatalogBreadcrumbTest.php
View source
<?php
namespace Drupal\Tests\uc_catalog\Functional;
class CatalogBreadcrumbTest extends CatalogTestBase {
protected function setUp() {
parent::setUp();
$this
->drupalPlaceBlock('system_breadcrumb_block');
}
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());
$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]);
}
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());
$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]);
}
}