AdminToolbarStateTest.php in Moderation Sidebar 8
File
tests/src/Functional/AdminToolbarStateTest.php
View source
<?php
namespace Drupal\Tests\moderation_sidebar\Functional;
use Drupal\node\NodeInterface;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait;
class AdminToolbarStateTest extends BrowserTestBase {
use ContentModerationTestTrait;
protected $defaultTheme = 'stark';
public static $modules = [
'toolbar',
'moderation_sidebar',
'node',
];
protected function setUp() {
parent::setUp();
$node_type = $this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
$node_type
->setNewRevision(TRUE);
$node_type
->save();
$user = $this
->createUser([], NULL, TRUE);
$this
->drupalLogin($user);
}
public function testModeratedEntity() {
$workflow = $this
->createEditorialWorkflow();
$workflow
->getTypePlugin()
->addEntityTypeAndBundle('node', 'article');
$workflow
->save();
$node = $this
->createNode([
'type' => 'article',
]);
$url = $node
->toUrl()
->toString();
$assert_session = $this
->assertSession();
$node
->set('moderation_state', 'draft');
$node
->save();
$this
->drupalGet($url);
$assert_session
->elementExists('css', '.moderation-label-draft[data-label="Draft"]');
$node
->set('moderation_state', 'published');
$node
->save();
$this
->drupalGet($url);
$assert_session
->elementExists('css', '.moderation-label-published[data-label="Published"]');
$node
->set('moderation_state', 'archived');
$node
->save();
$this
->drupalGet($url);
$assert_session
->elementExists('css', '.moderation-label-draft[data-label="Archived"]');
}
public function testNotModeratedEntity() {
$node = $this
->createNode([
'type' => 'article',
]);
$url = $node
->toUrl()
->toString();
$assert_session = $this
->assertSession();
$node
->set('status', NodeInterface::NOT_PUBLISHED);
$node
->save();
$this
->drupalGet($url);
$assert_session
->elementExists('css', '.moderation-label-draft[data-label="Draft"]');
$node
->set('status', NodeInterface::PUBLISHED);
$node
->save();
$this
->drupalGet($url);
$assert_session
->elementExists('css', '.moderation-label-published[data-label="Published"]');
}
}