TrackerNodeAccessTest.php in Zircon Profile 8
File
core/modules/tracker/src/Tests/TrackerNodeAccessTest.php
View source
<?php
namespace Drupal\tracker\Tests;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\comment\Tests\CommentTestTrait;
use Drupal\node\Entity\NodeType;
use Drupal\simpletest\WebTestBase;
class TrackerNodeAccessTest extends WebTestBase {
use CommentTestTrait;
public static $modules = array(
'node',
'comment',
'tracker',
'node_access_test',
);
protected function setUp() {
parent::setUp();
node_access_rebuild();
$this
->drupalCreateContentType(array(
'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);
}
function testTrackerNodeAccess() {
$access_user = $this
->drupalCreateUser(array(
'node test view',
'access user profiles',
));
$no_access_user = $this
->drupalCreateUser(array(
'access user profiles',
));
$this
->drupalLogin($access_user);
$private_node = $this
->drupalCreateNode(array(
'title' => t('Private node test'),
'private' => TRUE,
));
$public_node = $this
->drupalCreateNode(array(
'title' => t('Public node test'),
'private' => FALSE,
));
$this
->drupalGet('activity');
$this
->assertText($private_node
->getTitle(), 'Private node is visible to user with private access.');
$this
->assertText($public_node
->getTitle(), 'Public node is visible to user with private access.');
$this
->drupalGet('user/' . $access_user
->id() . '/activity');
$this
->assertText($private_node
->getTitle(), 'Private node is visible to user with private access.');
$this
->assertText($public_node
->getTitle(), 'Public node is visible to user with private access.');
$this
->drupalLogin($no_access_user);
$this
->drupalGet('activity');
$this
->assertNoText($private_node
->getTitle(), 'Private node is not visible to user without private access.');
$this
->assertText($public_node
->getTitle(), 'Public node is visible to user without private access.');
$this
->drupalGet('user/' . $access_user
->id() . '/activity');
$this
->assertNoText($private_node
->getTitle(), 'Private node is not visible to user without private access.');
$this
->assertText($public_node
->getTitle(), 'Public node is visible to user without private access.');
}
}