3 namespace Drupal\Tests\content_moderation\Kernel;
5 use Drupal\KernelTests\KernelTestBase;
6 use Drupal\node\Entity\NodeType;
7 use Drupal\Tests\node\Traits\NodeCreationTrait;
8 use Drupal\Tests\user\Traits\UserCreationTrait;
9 use Drupal\workflows\Entity\Workflow;
12 * Tests with node access enabled.
14 * @group content_moderation
16 class NodeAccessTest extends KernelTestBase {
18 use NodeCreationTrait;
19 use UserCreationTrait;
22 * The moderation information service.
24 * @var \Drupal\content_moderation\ModerationInformationInterface
26 protected $moderationInformation;
31 public static $modules = [
44 protected function setUp() {
47 $this->installEntitySchema('content_moderation_state');
48 $this->installEntitySchema('node');
49 $this->installEntitySchema('user');
50 $this->installEntitySchema('workflow');
51 $this->installConfig(['content_moderation', 'filter']);
52 $this->installSchema('system', ['sequences']);
53 $this->installSchema('node', ['node_access']);
55 // Add a moderated node type.
56 $node_type = NodeType::create([
61 $workflow = Workflow::load('editorial');
62 $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'page');
65 $this->moderationInformation = \Drupal::service('content_moderation.moderation_information');
69 * Tests for moderation information methods with node access.
71 public function testModerationInformation() {
72 // Create an admin user.
73 $user = $this->createUser([], NULL, TRUE);
74 \Drupal::currentUser()->setAccount($user);
77 $node = $this->createNode(['type' => 'page']);
78 $this->assertEquals($node->getRevisionId(), $this->moderationInformation->getDefaultRevisionId('node', $node->id()));
79 $this->assertEquals($node->getRevisionId(), $this->moderationInformation->getLatestRevisionId('node', $node->id()));
81 // Create a non-admin user.
82 $user = $this->createUser();
83 \Drupal::currentUser()->setAccount($user);
84 $this->assertEquals($node->getRevisionId(), $this->moderationInformation->getDefaultRevisionId('node', $node->id()));
85 $this->assertEquals($node->getRevisionId(), $this->moderationInformation->getLatestRevisionId('node', $node->id()));