public function ViewsModerationStateFilterTest::testModerationStateFilterOnJoinedEntity in Drupal 9
Same name and namespace in other branches
- 8 core/modules/content_moderation/tests/src/Kernel/ViewsModerationStateFilterTest.php \Drupal\Tests\content_moderation\Kernel\ViewsModerationStateFilterTest::testModerationStateFilterOnJoinedEntity()
- 10 core/modules/content_moderation/tests/src/Kernel/ViewsModerationStateFilterTest.php \Drupal\Tests\content_moderation\Kernel\ViewsModerationStateFilterTest::testModerationStateFilterOnJoinedEntity()
Tests the moderation state filter on an entity added via a relationship.
File
- core/
modules/ content_moderation/ tests/ src/ Kernel/ ViewsModerationStateFilterTest.php, line 199
Class
- ViewsModerationStateFilterTest
- Tests the views 'moderation_state_filter' filter plugin.
Namespace
Drupal\Tests\content_moderation\KernelCode
public function testModerationStateFilterOnJoinedEntity() {
$workflow = Workflow::load('editorial');
$workflow
->getTypePlugin()
->addEntityTypeAndBundle('node', 'example');
$workflow
->save();
// Create some sample content that will satisfy a view of users with a
// relationship to an item of content.
$user = $this
->createUser([], 'Test user');
$node = Node::create([
'type' => 'example',
'title' => 'Test node',
'moderation_state' => 'published',
'uid' => $user
->id(),
]);
$node
->save();
// When filtering by published nodes, the sample content will appear.
$view = Views::getView('test_content_moderation_filter_via_relationship');
$view
->setExposedInput([
'moderation_state' => 'editorial-published',
]);
$view
->execute();
$this
->assertIdenticalResultset($view, [
[
'name' => 'Test user',
'title' => 'Test node',
'moderation_state' => 'published',
],
], [
'name' => 'name',
'title' => 'title',
'moderation_state' => 'moderation_state',
]);
// Filtering by the draft state will filter out the sample content.
$view = Views::getView('test_content_moderation_filter_via_relationship');
$view
->setExposedInput([
'moderation_state' => 'editorial-draft',
]);
$view
->execute();
$this
->assertIdenticalResultset($view, [], [
'name' => 'name',
]);
}