Issue #2843997 by Sam152: Add missing test coverage for content edit tab labels
parent
41eda3b8ef
commit
4ffb98e3d3
|
@ -84,7 +84,6 @@ class EditTab extends LocalTaskDefault implements ContainerFactoryPluginInterfac
|
||||||
return parent::getTitle();
|
return parent::getTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
// @todo https://www.drupal.org/node/2779933 write a test for this.
|
|
||||||
return $this->moderationInfo->isLiveRevision($this->entity)
|
return $this->moderationInfo->isLiveRevision($this->entity)
|
||||||
? $this->t('New draft')
|
? $this->t('New draft')
|
||||||
: $this->t('Edit draft');
|
: $this->t('Edit draft');
|
||||||
|
@ -94,7 +93,6 @@ class EditTab extends LocalTaskDefault implements ContainerFactoryPluginInterfac
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getCacheTags() {
|
public function getCacheTags() {
|
||||||
// @todo https://www.drupal.org/node/2779933 write a test for this.
|
|
||||||
$tags = parent::getCacheTags();
|
$tags = parent::getCacheTags();
|
||||||
// Tab changes if node or node-type is modified.
|
// Tab changes if node or node-type is modified.
|
||||||
if ($this->entity) {
|
if ($this->entity) {
|
||||||
|
|
|
@ -42,7 +42,9 @@ class LocalTaskTest extends BrowserTestBase {
|
||||||
$this->drupalPlaceBlock('local_tasks_block', ['id' => 'tabs_block']);
|
$this->drupalPlaceBlock('local_tasks_block', ['id' => 'tabs_block']);
|
||||||
$this->drupalLogin($this->createUser(['bypass node access']));
|
$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.
|
// Now enable moderation for subsequent nodes.
|
||||||
$workflow = Workflow::load('editorial');
|
$workflow = Workflow::load('editorial');
|
||||||
|
@ -59,20 +61,35 @@ class LocalTaskTest extends BrowserTestBase {
|
||||||
* Tests local tasks behave with content_moderation enabled.
|
* Tests local tasks behave with content_moderation enabled.
|
||||||
*/
|
*/
|
||||||
public function testLocalTasks() {
|
public function testLocalTasks() {
|
||||||
|
// The default state is a draft.
|
||||||
$this->drupalGet(sprintf('node/%s', $this->testNode->id()));
|
$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->clickLink('Task Without Upcast Node');
|
||||||
$this->assertTasks(FALSE);
|
$this->assertTasks('Edit');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assert the correct tasks appear.
|
* 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('View');
|
||||||
$this->assertSession()->linkExists('Task Without Upcast Node');
|
$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');
|
$this->assertSession()->linkExists('Delete');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue