From 4ffb98e3d37e81c959273ab0c50b756a05dc886c Mon Sep 17 00:00:00 2001
From: Chris McCafferty <cilefen@gmail.com>
Date: Sun, 5 Feb 2017 14:00:34 -0500
Subject: [PATCH] Issue #2843997 by Sam152: Add missing test coverage for
 content edit tab labels

---
 .../src/Plugin/Menu/EditTab.php               |  2 --
 .../tests/src/Functional/LocalTaskTest.php    | 27 +++++++++++++++----
 2 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/core/modules/content_moderation/src/Plugin/Menu/EditTab.php b/core/modules/content_moderation/src/Plugin/Menu/EditTab.php
index 3a808793f6b3..b94a45976e3c 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 460c6ef93ce2..586a91a49185 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');
   }
 
-- 
GitLab