TrackerNodeAccessTest.php in Drupal 10
File
core/modules/tracker/tests/src/Functional/TrackerNodeAccessTest.php
View source
<?php
namespace Drupal\Tests\tracker\Functional;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\comment\Tests\CommentTestTrait;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\BrowserTestBase;
class TrackerNodeAccessTest extends BrowserTestBase {
use CommentTestTrait;
protected static $modules = [
'node',
'comment',
'tracker',
'node_access_test',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
node_access_rebuild();
$this
->drupalCreateContentType([
'type' => 'page',
]);
node_access_test_add_field(NodeType::load('page'));
$this
->addDefaultCommentField('node', 'page', 'comment', CommentItemInterface::OPEN);
\Drupal::state()
->set('node_access_test.private', TRUE);
}
public function testTrackerNodeAccessIndexing() {
$author = $this
->drupalCreateUser();
$private_node = $this
->drupalCreateNode([
'title' => 'Private node test',
'private' => TRUE,
'uid' => $author
->id(),
]);
\Drupal::database()
->delete('tracker_node')
->execute();
\Drupal::state()
->set('tracker.index_nid', $private_node
->id());
tracker_cron();
$user = $this
->drupalCreateUser([
'node test view',
]);
$this
->drupalLogin($user);
$this
->drupalGet('activity');
$this
->assertSession()
->pageTextContains($private_node
->getTitle());
}
public function testTrackerNodeAccess() {
$access_user = $this
->drupalCreateUser([
'node test view',
'access user profiles',
]);
$no_access_user = $this
->drupalCreateUser([
'access user profiles',
]);
$this
->drupalLogin($access_user);
$private_node = $this
->drupalCreateNode([
'title' => 'Private node test',
'private' => TRUE,
]);
$public_node = $this
->drupalCreateNode([
'title' => 'Public node test',
'private' => FALSE,
]);
$this
->drupalGet('activity');
$this
->assertSession()
->pageTextContains($private_node
->getTitle());
$this
->assertSession()
->pageTextContains($public_node
->getTitle());
$this
->drupalGet('user/' . $access_user
->id() . '/activity');
$this
->assertSession()
->pageTextContains($private_node
->getTitle());
$this
->assertSession()
->pageTextContains($public_node
->getTitle());
$this
->drupalLogin($no_access_user);
$this
->drupalGet('activity');
$this
->assertSession()
->pageTextNotContains($private_node
->getTitle());
$this
->assertSession()
->pageTextContains($public_node
->getTitle());
$this
->drupalGet('user/' . $access_user
->id() . '/activity');
$this
->assertSession()
->pageTextNotContains($private_node
->getTitle());
$this
->assertSession()
->pageTextContains($public_node
->getTitle());
}
}