ModeratedNodeResourceTestBase.php in Drupal 8
File
core/modules/rest/tests/src/Functional/EntityResource/ModeratedNode/ModeratedNodeResourceTestBase.php
View source
<?php
namespace Drupal\Tests\rest\Functional\EntityResource\ModeratedNode;
use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait;
use Drupal\Tests\node\Functional\Rest\NodeResourceTestBase;
abstract class ModeratedNodeResourceTestBase extends NodeResourceTestBase {
use ContentModerationTestTrait;
public static $modules = [
'content_moderation',
];
protected $workflow;
protected function setUpAuthorization($method) {
parent::setUpAuthorization($method);
switch ($method) {
case 'POST':
case 'PATCH':
case 'DELETE':
$this
->grantPermissionsToTestedRole([
'use editorial transition publish',
'use editorial transition create_new_draft',
]);
break;
}
}
protected function createEntity() {
$entity = parent::createEntity();
if (!$this->workflow) {
$this->workflow = $this
->createEditorialWorkflow();
}
$this->workflow
->getTypePlugin()
->addEntityTypeAndBundle($entity
->getEntityTypeId(), $entity
->bundle());
$this->workflow
->save();
return $entity;
}
protected function getExpectedNormalizedEntity() {
return array_merge(parent::getExpectedNormalizedEntity(), [
'moderation_state' => [
[
'value' => 'published',
],
],
'vid' => [
[
'value' => (int) $this->entity
->getRevisionId(),
],
],
]);
}
}