X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fcontent_moderation%2Ftests%2Fsrc%2FKernel%2FViewsDataIntegrationTest.php;h=00e107295aad917fcf7ebaf8da514c000e0e17a9;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hp=d4c4aa37cdecd401841203a4aea1b376688d178b;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/web/core/modules/content_moderation/tests/src/Kernel/ViewsDataIntegrationTest.php b/web/core/modules/content_moderation/tests/src/Kernel/ViewsDataIntegrationTest.php index d4c4aa37c..00e107295 100644 --- a/web/core/modules/content_moderation/tests/src/Kernel/ViewsDataIntegrationTest.php +++ b/web/core/modules/content_moderation/tests/src/Kernel/ViewsDataIntegrationTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\content_moderation\Kernel; -use Drupal\entity_test\Entity\EntityTestMulRevPub; use Drupal\node\Entity\Node; use Drupal\node\Entity\NodeType; use Drupal\Tests\views\Kernel\ViewsKernelTestBase; @@ -51,54 +50,6 @@ class ViewsDataIntegrationTest extends ViewsKernelTestBase { $workflow->save(); } - /** - * Tests content_moderation_views_data(). - * - * @see content_moderation_views_data() - */ - public function testViewsData() { - $node = Node::create([ - 'type' => 'page', - 'title' => 'Test title first revision', - ]); - $node->moderation_state->value = 'published'; - $node->save(); - - // Create a totally unrelated entity to ensure the extra join information - // joins by the correct entity type. - $unrelated_entity = EntityTestMulRevPub::create([ - 'id' => $node->id(), - ]); - $unrelated_entity->save(); - - $this->assertEquals($unrelated_entity->id(), $node->id()); - - $revision = clone $node; - $revision->setNewRevision(TRUE); - $revision->isDefaultRevision(FALSE); - $revision->title->value = 'Test title second revision'; - $revision->moderation_state->value = 'draft'; - $revision->save(); - - $view = Views::getView('test_content_moderation_latest_revision'); - $view->execute(); - - // Ensure that the content_revision_tracker contains the right latest - // revision ID. - // Also ensure that the relationship back to the revision table contains the - // right latest revision. - $expected_result = [ - [ - 'nid' => $node->id(), - 'revision_id' => $revision->getRevisionId(), - 'title' => $revision->label(), - 'moderation_state_1' => 'draft', - 'moderation_state' => 'published', - ], - ]; - $this->assertIdenticalResultset($view, $expected_result, ['nid' => 'nid', 'content_revision_tracker_revision_id' => 'revision_id', 'moderation_state' => 'moderation_state', 'moderation_state_1' => 'moderation_state_1']); - } - /** * Tests the join from the revision data table to the moderation state table. */ @@ -157,14 +108,12 @@ class ViewsDataIntegrationTest extends ViewsKernelTestBase { $expected_result = [ [ 'nid' => $node->id(), - // @todo I would have expected that the content_moderation_state default - // revision is the same one as in the node, but it isn't. // Joins from the base table to the default revision of the // content_moderation. - 'moderation_state' => 'draft', + 'moderation_state' => 'published', // Joins from the revision table to the default revision of the // content_moderation. - 'moderation_state_1' => 'draft', + 'moderation_state_1' => 'published', // Joins from the revision table to the revision of the // content_moderation. 'moderation_state_2' => 'published', @@ -173,4 +122,27 @@ class ViewsDataIntegrationTest extends ViewsKernelTestBase { $this->assertIdenticalResultset($view, $expected_result, ['nid' => 'nid', 'moderation_state' => 'moderation_state', 'moderation_state_1' => 'moderation_state_1', 'moderation_state_2' => 'moderation_state_2']); } + /** + * Tests the content moderation state views field. + */ + public function testContentModerationStateField() { + $node = Node::create([ + 'type' => 'page', + 'title' => 'Test title', + ]); + $node->moderation_state->value = 'published'; + $node->save(); + + $view = Views::getView('test_content_moderation_field_state_test'); + $view->execute(); + + $expected_result = [ + [ + 'title' => 'Test title', + 'moderation_state' => 'published', + ], + ]; + $this->assertIdenticalResultset($view, $expected_result, ['title' => 'title', 'moderation_state' => 'moderation_state']); + } + }