Issue #2843997 by Sam152: Add missing test coverage for content edit tab labels

8.4.x
Chris McCafferty 2017-02-05 14:00:34 -05:00
parent 41eda3b8ef
commit 4ffb98e3d3
2 changed files with 22 additions and 7 deletions

View File

@ -84,7 +84,6 @@ class EditTab extends LocalTaskDefault implements ContainerFactoryPluginInterfac
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 @@ class EditTab extends LocalTaskDefault implements ContainerFactoryPluginInterfac
* {@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) {

View File

@ -42,7 +42,9 @@ class LocalTaskTest extends BrowserTestBase {
$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 @@ class LocalTaskTest extends BrowserTestBase {
* 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(TRUE);
$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('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');
}