3 namespace Drupal\Tests\content_moderation\Kernel;
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;
12 * Tests the views integration of content_moderation.
14 * @group content_moderation
16 class ViewsDataIntegrationTest extends ViewsKernelTestBase {
21 public static $modules = [
22 'content_moderation_test_views',
32 protected function setUp($import_test_views = TRUE) {
33 parent::setUp($import_test_views);
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');
43 $node_type = NodeType::create([
47 $workflow = Workflow::load('editorial');
48 $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'page');
49 $workflow->getTypePlugin()->addEntityTypeAndBundle('entity_test_mulrevpub', 'entity_test_mulrevpub');
54 * Tests the join from the revision data table to the moderation state table.
56 public function testContentModerationStateRevisionJoin() {
57 $node = Node::create([
59 'title' => 'Test title first revision',
61 $node->moderation_state->value = 'published';
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';
71 $view = Views::getView('test_content_moderation_revision_test');
76 'vid' => $node->getRevisionId(),
77 'moderation_state' => 'published',
80 'vid' => $revision->getRevisionId(),
81 'moderation_state' => 'draft',
84 $this->assertIdenticalResultset($view, $expected_result, ['vid' => 'vid', 'moderation_state' => 'moderation_state']);
88 * Tests the join from the data table to the moderation state table.
90 public function testContentModerationStateBaseJoin() {
91 $node = Node::create([
93 'title' => 'Test title first revision',
95 $node->moderation_state->value = 'published';
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';
105 $view = Views::getView('test_content_moderation_base_table_test');
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',
124 $this->assertIdenticalResultset($view, $expected_result, ['nid' => 'nid', 'moderation_state' => 'moderation_state', 'moderation_state_1' => 'moderation_state_1', 'moderation_state_2' => 'moderation_state_2']);