6716ca36100cbe2915fb0bd71f6934daa19fd173
[yaffs-website] / web / core / modules / content_moderation / tests / src / Kernel / NodeAccessTest.php
1 <?php
2
3 namespace Drupal\Tests\content_moderation\Kernel;
4
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;
10
11 /**
12  * Tests with node access enabled.
13  *
14  * @group content_moderation
15  */
16 class NodeAccessTest extends KernelTestBase {
17
18   use NodeCreationTrait;
19   use UserCreationTrait;
20
21   /**
22    * The moderation information service.
23    *
24    * @var \Drupal\content_moderation\ModerationInformationInterface
25    */
26   protected $moderationInformation;
27
28   /**
29    * {@inheritdoc}
30    */
31   public static $modules = [
32     'content_moderation',
33     'filter',
34     'node',
35     'node_access_test',
36     'system',
37     'user',
38     'workflows',
39   ];
40
41   /**
42    * {@inheritdoc}
43    */
44   protected function setUp() {
45     parent::setUp();
46
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']);
54
55     // Add a moderated node type.
56     $node_type = NodeType::create([
57       'type' => 'page',
58       'label' => 'Page',
59     ]);
60     $node_type->save();
61     $workflow = Workflow::load('editorial');
62     $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'page');
63     $workflow->save();
64
65     $this->moderationInformation = \Drupal::service('content_moderation.moderation_information');
66   }
67
68   /**
69    * Tests for moderation information methods with node access.
70    */
71   public function testModerationInformation() {
72     // Create an admin user.
73     $user = $this->createUser([], NULL, TRUE);
74     \Drupal::currentUser()->setAccount($user);
75
76     // Create a node.
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()));
80
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()));
86   }
87
88 }