Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / content_moderation / tests / src / Kernel / ViewsDataIntegrationTest.php
1 <?php
2
3 namespace Drupal\Tests\content_moderation\Kernel;
4
5 use Drupal\node\Entity\Node;
6 use Drupal\node\Entity\NodeType;
7 use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
8 use Drupal\views\Views;
9 use Drupal\workflows\Entity\Workflow;
10
11 /**
12  * Tests the views integration of content_moderation.
13  *
14  * @group content_moderation
15  */
16 class ViewsDataIntegrationTest extends ViewsKernelTestBase {
17
18   /**
19    * {@inheritdoc}
20    */
21   public static $modules = [
22     'content_moderation_test_views',
23     'node',
24     'content_moderation',
25     'workflows',
26     'entity_test',
27   ];
28
29   /**
30    * {@inheritdoc}
31    */
32   protected function setUp($import_test_views = TRUE) {
33     parent::setUp($import_test_views);
34
35     $this->installEntitySchema('node');
36     $this->installEntitySchema('entity_test_mulrevpub');
37     $this->installEntitySchema('user');
38     $this->installEntitySchema('content_moderation_state');
39     $this->installSchema('node', 'node_access');
40     $this->installConfig('content_moderation_test_views');
41     $this->installConfig('content_moderation');
42
43     $node_type = NodeType::create([
44       'type' => 'page',
45     ]);
46     $node_type->save();
47     $workflow = Workflow::load('editorial');
48     $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'page');
49     $workflow->getTypePlugin()->addEntityTypeAndBundle('entity_test_mulrevpub', 'entity_test_mulrevpub');
50     $workflow->save();
51   }
52
53   /**
54    * Tests the join from the revision data table to the moderation state table.
55    */
56   public function testContentModerationStateRevisionJoin() {
57     $node = Node::create([
58       'type' => 'page',
59       'title' => 'Test title first revision',
60     ]);
61     $node->moderation_state->value = 'published';
62     $node->save();
63
64     $revision = clone $node;
65     $revision->setNewRevision(TRUE);
66     $revision->isDefaultRevision(FALSE);
67     $revision->title->value = 'Test title second revision';
68     $revision->moderation_state->value = 'draft';
69     $revision->save();
70
71     $view = Views::getView('test_content_moderation_revision_test');
72     $view->execute();
73
74     $expected_result = [
75       [
76         'vid' => $node->getRevisionId(),
77         'moderation_state' => 'published',
78       ],
79       [
80         'vid' => $revision->getRevisionId(),
81         'moderation_state' => 'draft',
82       ],
83     ];
84     $this->assertIdenticalResultset($view, $expected_result, ['vid' => 'vid', 'moderation_state' => 'moderation_state']);
85   }
86
87   /**
88    * Tests the join from the data table to the moderation state table.
89    */
90   public function testContentModerationStateBaseJoin() {
91     $node = Node::create([
92       'type' => 'page',
93       'title' => 'Test title first revision',
94     ]);
95     $node->moderation_state->value = 'published';
96     $node->save();
97
98     $revision = clone $node;
99     $revision->setNewRevision(TRUE);
100     $revision->isDefaultRevision(FALSE);
101     $revision->title->value = 'Test title second revision';
102     $revision->moderation_state->value = 'draft';
103     $revision->save();
104
105     $view = Views::getView('test_content_moderation_base_table_test');
106     $view->execute();
107
108     $expected_result = [
109       [
110         'nid' => $node->id(),
111         // @todo I would have expected that the content_moderation_state default
112         //   revision is the same one as in the node, but it isn't.
113         // Joins from the base table to the default revision of the
114         // content_moderation.
115         'moderation_state' => 'draft',
116         // Joins from the revision table to the default revision of the
117         // content_moderation.
118         'moderation_state_1' => 'draft',
119         // Joins from the revision table to the revision of the
120         // content_moderation.
121         'moderation_state_2' => 'published',
122       ],
123     ];
124     $this->assertIdenticalResultset($view, $expected_result, ['nid' => 'nid', 'moderation_state' => 'moderation_state', 'moderation_state_1' => 'moderation_state_1', 'moderation_state_2' => 'moderation_state_2']);
125   }
126
127 }