You are here

protected function NodeAccessBaseTableTest::assertTaxonomyPage in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/node/tests/src/Functional/NodeAccessBaseTableTest.php \Drupal\Tests\node\Functional\NodeAccessBaseTableTest::assertTaxonomyPage()

Checks taxonomy/term listings to ensure only accessible nodes are listed.

Parameters

$is_admin: A boolean indicating whether the current user is an administrator. If TRUE, all nodes should be listed. If FALSE, only public nodes and the user's own private nodes should be listed.

1 call to NodeAccessBaseTableTest::assertTaxonomyPage()
NodeAccessBaseTableTest::testNodeAccessBasic in core/modules/node/tests/src/Functional/NodeAccessBaseTableTest.php
Tests the "private" node access functionality.

File

core/modules/node/tests/src/Functional/NodeAccessBaseTableTest.php, line 210

Class

NodeAccessBaseTableTest
Tests behavior of the node access subsystem if the base table is not node.

Namespace

Drupal\Tests\node\Functional

Code

protected function assertTaxonomyPage($is_admin) {
  foreach ([
    $this->publicTid,
    $this->privateTid,
  ] as $tid_is_private => $tid) {
    $this
      ->drupalGet("taxonomy/term/{$tid}");
    $this->nidsVisible = [];
    foreach ($this
      ->xpath("//a[text()='Read more']") as $link) {

      // See also testTranslationRendering() in NodeTranslationUITest.
      $this
        ->assertEquals(1, preg_match('|node/(\\d+)$|', $link
        ->getAttribute('href'), $matches), 'Read more points to a node');
      $this->nidsVisible[$matches[1]] = TRUE;
    }
    foreach ($this->nodesByUser as $uid => $data) {
      foreach ($data as $nid => $is_private) {

        // Private nodes should be visible on the private term page,
        // public nodes should be visible on the public term page.
        $should_be_visible = $tid_is_private == $is_private;

        // Non-administrators can only see their own nodes on the private
        // term page.
        if (!$is_admin && $tid_is_private) {
          $should_be_visible = $should_be_visible && $uid == $this->webUser
            ->id();
        }
        $this
          ->assertIdentical(isset($this->nidsVisible[$nid]), $should_be_visible, strtr('A %private node by user %uid is %visible for user %current_uid on the %tid_is_private page.', [
          '%private' => $is_private ? 'private' : 'public',
          '%uid' => $uid,
          '%visible' => isset($this->nidsVisible[$nid]) ? 'visible' : 'not visible',
          '%current_uid' => $this->webUser
            ->id(),
          '%tid_is_private' => $tid_is_private ? 'private' : 'public',
        ]));
      }
    }
  }
}