class ModerationStateAccessTest
Same name and namespace in other branches
- 11.x core/modules/content_moderation/tests/src/Functional/ModerationStateAccessTest.php \Drupal\Tests\content_moderation\Functional\ModerationStateAccessTest
- 10 core/modules/content_moderation/tests/src/Functional/ModerationStateAccessTest.php \Drupal\Tests\content_moderation\Functional\ModerationStateAccessTest
- 8.9.x core/modules/content_moderation/tests/src/Functional/ModerationStateAccessTest.php \Drupal\Tests\content_moderation\Functional\ModerationStateAccessTest
Tests the view access control handler for moderation state entities.
@group content_moderation
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\content_moderation\Functional\ModerationStateAccessTest uses \Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of ModerationStateAccessTest
File
-
core/
modules/ content_moderation/ tests/ src/ Functional/ ModerationStateAccessTest.php, line 15
Namespace
Drupal\Tests\content_moderation\FunctionalView source
class ModerationStateAccessTest extends BrowserTestBase {
use ContentModerationTestTrait;
/**
* {@inheritdoc}
*/
protected static $modules = [
'content_moderation',
'node',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$node_type = NodeType::create([
'type' => 'test',
'label' => 'Test',
]);
$node_type->save();
$workflow = $this->createEditorialWorkflow();
$workflow->getTypePlugin()
->addEntityTypeAndBundle('node', 'test');
$workflow->save();
$this->container
->get('module_installer')
->install([
'content_moderation_test_views',
]);
}
/**
* Tests the view operation access handler with the view permission.
*/
public function testViewShowsCorrectStates() {
$permissions = [
'access content',
'view all revisions',
];
$editor1 = $this->drupalCreateUser($permissions);
$this->drupalLogin($editor1);
$node_1 = Node::create([
'type' => 'test',
'title' => 'Draft node',
'uid' => $editor1->id(),
]);
$node_1->moderation_state->value = 'draft';
$node_1->save();
$node_2 = Node::create([
'type' => 'test',
'title' => 'Published node',
'uid' => $editor1->id(),
]);
$node_2->moderation_state->value = 'published';
$node_2->save();
// Resave the node with a new state.
$node_2->setTitle('Archived node');
$node_2->moderation_state->value = 'archived';
$node_2->save();
// Now show the View, and confirm that the state labels are showing.
$this->drupalGet('/latest');
$page = $this->getSession()
->getPage();
$this->assertTrue($page->hasContent('Draft'));
$this->assertTrue($page->hasContent('Archived'));
$this->assertFalse($page->hasContent('Published'));
// Now log in as an admin and test the same thing.
$permissions = [
'access content',
'view all revisions',
];
$admin1 = $this->drupalCreateUser($permissions);
$this->drupalLogin($admin1);
$this->drupalGet('/latest');
$page = $this->getSession()
->getPage();
$this->assertEquals(200, $this->getSession()
->getStatusCode());
$this->assertTrue($page->hasContent('Draft'));
$this->assertTrue($page->hasContent('Archived'));
$this->assertFalse($page->hasContent('Published'));
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.