You are here

public function MicrositeMenuBlockTest::testMenuBlock in Entity Reference Hierarchy 3.x

Same name and namespace in other branches
  1. 8.2 modules/entity_hierarchy_microsite/tests/src/Functional/MicrositeMenuBlockTest.php \Drupal\Tests\entity_hierarchy_microsite\Functional\MicrositeMenuBlockTest::testMenuBlock()

Tests menu block.

File

modules/entity_hierarchy_microsite/tests/src/Functional/MicrositeMenuBlockTest.php, line 42

Class

MicrositeMenuBlockTest
Defines a class for testing microsite menu block.

Namespace

Drupal\Tests\entity_hierarchy_microsite\Functional

Code

public function testMenuBlock() {
  $logo = $this
    ->createImageMedia();
  $root = $this
    ->createTestEntity(NULL, 'Root');
  $children = $this
    ->createChildEntities($root
    ->id(), 5);
  $microsite = Microsite::create([
    'name' => $root
      ->label(),
    'home' => $root,
    'logo' => $logo,
  ]);
  $microsite
    ->save();
  $this
    ->drupalGet($root
    ->toUrl());
  $assert = $this
    ->assertSession();
  $menu = $assert
    ->elementExists('css', '#block-microsite-menu ul');
  $links = $menu
    ->findAll('css', 'li a');
  $this
    ->assertCount(5, $links);
  foreach ($children as $child) {
    $this
      ->assertNotEmpty($menu
      ->find('named', [
      'link',
      $child
        ->label(),
    ]));
    $assert
      ->linkExists($child
      ->label());
    $xpath = $this
      ->buildXPathQuery('//a[contains(@href, :href)]', [
      ':href' => $child
        ->toUrl()
        ->toString(),
    ]);
    $this
      ->assertNotEmpty($menu
      ->find('xpath', $xpath));
  }
}