function NodeAccessBaseTableTest::assertTaxonomyPage

Same name in other branches
  1. 9 core/modules/node/tests/src/Functional/NodeAccessBaseTableTest.php \Drupal\Tests\node\Functional\NodeAccessBaseTableTest::assertTaxonomyPage()
  2. 8.9.x core/modules/node/tests/src/Functional/NodeAccessBaseTableTest.php \Drupal\Tests\node\Functional\NodeAccessBaseTableTest::assertTaxonomyPage()
  3. 11.x 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.

@internal

Parameters

bool $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 249

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(bool $is_admin) : void {
    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->assertSame($should_be_visible, isset($this->nidsVisible[$nid]), 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',
                ]));
            }
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.