You are here

public function BreadcrumbTest::testBlogNodeBreadcrumb in Blog 3.x

Same name and namespace in other branches
  1. 8.2 tests/src/Functional/BreadcrumbTest.php \Drupal\Tests\blog\Functional\BreadcrumbTest::testBlogNodeBreadcrumb()

Blog node type breadcrumb test.

File

tests/src/Functional/BreadcrumbTest.php, line 41

Class

BreadcrumbTest
Breadcrumb test for blog module.

Namespace

Drupal\Tests\blog\Functional

Code

public function testBlogNodeBreadcrumb() {
  $blog_nid = array_rand($this->blogNodes1);
  $blog_owner = $this->blogNodes1[$blog_nid]
    ->getOwner();
  $this
    ->drupalGet('node/' . $blog_nid);
  $links = $this
    ->getSession()
    ->getPage()
    ->findAll('css', '#block-breadcrumb li a');
  $this
    ->assertEquals(count($links), 3, 'Breadcrumb element number is correctly.');
  [
    $home,
    $blogs,
    $personal_blog,
  ] = $links;
  $this
    ->assertTrue($home
    ->getAttribute('href') === base_path() && $home
    ->getHtml() === 'Home', 'Home link correctly.');
  $expected_url = Url::fromRoute('view.blog.blog_all')
    ->toString();
  $this
    ->assertTrue($blogs
    ->getAttribute('href') === $expected_url && $blogs
    ->getHtml() === 'Blogs', 'Blogs link correctly.');
  $blog_name = $this->container
    ->get('blog.lister')
    ->userBlogTitle($blog_owner);
  $expected_url = Url::fromRoute('view.blog.blog_user_all', [
    'arg_0' => $blog_owner
      ->id(),
  ])
    ->toString();
  $this
    ->assertTrue($personal_blog
    ->getAttribute('href') === $expected_url && $personal_blog
    ->getHtml() === (string) $blog_name, 'Personal blog link correctly.');
}