diff --git a/core/modules/content_moderation/src/Plugin/Menu/EditTab.php b/core/modules/content_moderation/src/Plugin/Menu/EditTab.php index 3a808793f6b3e8fc6efb9f3789782d72ccbcc66e..b94a45976e3cb57600d392c86c236f0065a26b11 100644 --- a/core/modules/content_moderation/src/Plugin/Menu/EditTab.php +++ b/core/modules/content_moderation/src/Plugin/Menu/EditTab.php @@ -84,7 +84,6 @@ public function getTitle() { return parent::getTitle(); } - // @todo https://www.drupal.org/node/2779933 write a test for this. return $this->moderationInfo->isLiveRevision($this->entity) ? $this->t('New draft') : $this->t('Edit draft'); @@ -94,7 +93,6 @@ public function getTitle() { * {@inheritdoc} */ public function getCacheTags() { - // @todo https://www.drupal.org/node/2779933 write a test for this. $tags = parent::getCacheTags(); // Tab changes if node or node-type is modified. if ($this->entity) { diff --git a/core/modules/content_moderation/tests/src/Functional/LocalTaskTest.php b/core/modules/content_moderation/tests/src/Functional/LocalTaskTest.php index 460c6ef93ce20f0e0ad5e939461998a10bc5c662..586a91a49185e2a62993963201600b3338428f63 100644 --- a/core/modules/content_moderation/tests/src/Functional/LocalTaskTest.php +++ b/core/modules/content_moderation/tests/src/Functional/LocalTaskTest.php @@ -42,7 +42,9 @@ protected function setUp() { $this->drupalPlaceBlock('local_tasks_block', ['id' => 'tabs_block']); $this->drupalLogin($this->createUser(['bypass node access'])); - $node_type = $this->createContentType(); + $node_type = $this->createContentType([ + 'type' => 'test_content_type', + ]); // Now enable moderation for subsequent nodes. $workflow = Workflow::load('editorial'); @@ -59,20 +61,35 @@ protected function setUp() { * Tests local tasks behave with content_moderation enabled. */ public function testLocalTasks() { + // The default state is a draft. + $this->drupalGet(sprintf('node/%s', $this->testNode->id())); + $this->assertTasks('Edit draft'); + + // When published as the live revision, the label changes. + $this->testNode->moderation_state = 'published'; + $this->testNode->save(); $this->drupalGet(sprintf('node/%s', $this->testNode->id())); - $this->assertTasks(TRUE); + $this->assertTasks('New draft'); + $tags = $this->drupalGetHeader('X-Drupal-Cache-Tags'); + $this->assertContains('node:1', $tags); + $this->assertContains('node_type:test_content_type', $tags); + + // Without an upcast node, the state cannot be determined. $this->clickLink('Task Without Upcast Node'); - $this->assertTasks(FALSE); + $this->assertTasks('Edit'); } /** * Assert the correct tasks appear. + * + * @param string $edit_tab_label + * The edit tab label to assert. */ - protected function assertTasks($with_upcast_node) { + protected function assertTasks($edit_tab_label) { $this->assertSession()->linkExists('View'); $this->assertSession()->linkExists('Task Without Upcast Node'); - $this->assertSession()->linkExists($with_upcast_node ? 'Edit draft' : 'Edit'); + $this->assertSession()->linkExists($edit_tab_label); $this->assertSession()->linkExists('Delete'); }