3 namespace Drupal\Tests\content_moderation\Kernel;
5 use Drupal\node\Entity\Node;
6 use Drupal\node\Entity\NodeType;
7 use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait;
8 use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
9 use Drupal\views\Views;
12 * Tests the views integration of content_moderation.
14 * @group content_moderation
16 class ViewsDataIntegrationTest extends ViewsKernelTestBase {
18 use ContentModerationTestTrait;
23 public static $modules = [
24 'content_moderation_test_views',
34 protected function setUp($import_test_views = TRUE) {
35 parent::setUp($import_test_views);
37 $this->installEntitySchema('node');
38 $this->installEntitySchema('entity_test_mulrevpub');
39 $this->installEntitySchema('user');
40 $this->installEntitySchema('content_moderation_state');
41 $this->installSchema('node', 'node_access');
42 $this->installConfig('content_moderation_test_views');
43 $this->installConfig('content_moderation');
45 $node_type = NodeType::create([
49 $workflow = $this->createEditorialWorkflow();
50 $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'page');
51 $workflow->getTypePlugin()->addEntityTypeAndBundle('entity_test_mulrevpub', 'entity_test_mulrevpub');
56 * Tests the join from the revision data table to the moderation state table.
58 public function testContentModerationStateRevisionJoin() {
59 $node = Node::create([
61 'title' => 'Test title first revision',
63 $node->moderation_state->value = 'published';
66 $revision = clone $node;
67 $revision->setNewRevision(TRUE);
68 $revision->isDefaultRevision(FALSE);
69 $revision->title->value = 'Test title second revision';
70 $revision->moderation_state->value = 'draft';
73 $view = Views::getView('test_content_moderation_revision_test');
78 'vid' => $node->getRevisionId(),
79 'moderation_state' => 'published',
82 'vid' => $revision->getRevisionId(),
83 'moderation_state' => 'draft',
86 $this->assertIdenticalResultset($view, $expected_result, ['vid' => 'vid', 'moderation_state' => 'moderation_state']);
90 * Tests the join from the data table to the moderation state table.
92 public function testContentModerationStateBaseJoin() {
93 $node = Node::create([
95 'title' => 'Test title first revision',
97 $node->moderation_state->value = 'published';
100 $revision = clone $node;
101 $revision->setNewRevision(TRUE);
102 $revision->isDefaultRevision(FALSE);
103 $revision->title->value = 'Test title second revision';
104 $revision->moderation_state->value = 'draft';
107 $view = Views::getView('test_content_moderation_base_table_test');
112 'nid' => $node->id(),
113 // Joins from the base table to the default revision of the
114 // content_moderation.
115 'moderation_state' => 'published',
116 // Joins from the revision table to the default revision of the
117 // content_moderation.
118 'moderation_state_1' => 'published',
119 // Joins from the revision table to the revision of the
120 // content_moderation.
121 'moderation_state_2' => 'published',
124 $this->assertIdenticalResultset($view, $expected_result, ['nid' => 'nid', 'moderation_state' => 'moderation_state', 'moderation_state_1' => 'moderation_state_1', 'moderation_state_2' => 'moderation_state_2']);
128 * Tests the content moderation state views field.
130 public function testContentModerationStateField() {
131 $node = Node::create([
133 'title' => 'Test title',
135 $node->moderation_state->value = 'published';
138 $view = Views::getView('test_content_moderation_field_state_test');
143 'title' => 'Test title',
144 'moderation_state' => 'published',
147 $this->assertIdenticalResultset($view, $expected_result, ['title' => 'title', 'moderation_state' => 'moderation_state']);