.../tests/Traits/ContentModerationTestTrait.php | 91 ++++++++++++++++++++++ tests/src/Functional/ResourceTestBase.php | 7 +- 2 files changed, 96 insertions(+), 2 deletions(-) diff --git a/src/BackwardCompatibility/tests/Traits/ContentModerationTestTrait.php b/src/BackwardCompatibility/tests/Traits/ContentModerationTestTrait.php new file mode 100644 index 0000000..310bcfb --- /dev/null +++ b/src/BackwardCompatibility/tests/Traits/ContentModerationTestTrait.php @@ -0,0 +1,91 @@ +=8.6 + */ +trait ContentModerationTestTrait { + + /** + * Creates the editorial workflow. + * + * @return \Drupal\workflows\Entity\Workflow + * The editorial workflow entity. + */ + protected function createEditorialWorkflow() { + $workflow = Workflow::create([ + 'type' => 'content_moderation', + 'id' => 'editorial', + 'label' => 'Editorial', + 'type_settings' => [ + 'states' => [ + 'archived' => [ + 'label' => 'Archived', + 'weight' => 5, + 'published' => FALSE, + 'default_revision' => TRUE, + ], + 'draft' => [ + 'label' => 'Draft', + 'published' => FALSE, + 'default_revision' => FALSE, + 'weight' => -5, + ], + 'published' => [ + 'label' => 'Published', + 'published' => TRUE, + 'default_revision' => TRUE, + 'weight' => 0, + ], + ], + 'transitions' => [ + 'archive' => [ + 'label' => 'Archive', + 'from' => ['published'], + 'to' => 'archived', + 'weight' => 2, + ], + 'archived_draft' => [ + 'label' => 'Restore to Draft', + 'from' => ['archived'], + 'to' => 'draft', + 'weight' => 3, + ], + 'archived_published' => [ + 'label' => 'Restore', + 'from' => ['archived'], + 'to' => 'published', + 'weight' => 4, + ], + 'create_new_draft' => [ + 'label' => 'Create New Draft', + 'to' => 'draft', + 'weight' => 0, + 'from' => [ + 'draft', + 'published', + ], + ], + 'publish' => [ + 'label' => 'Publish', + 'to' => 'published', + 'weight' => 1, + 'from' => [ + 'draft', + 'published', + ], + ], + ], + ], + ]); + $workflow->save(); + return $workflow; + } + +} diff --git a/tests/src/Functional/ResourceTestBase.php b/tests/src/Functional/ResourceTestBase.php index 5b770be..751e808 100644 --- a/tests/src/Functional/ResourceTestBase.php +++ b/tests/src/Functional/ResourceTestBase.php @@ -27,13 +27,13 @@ use Drupal\Core\TypedData\TypedDataInternalPropertiesHelper; use Drupal\Core\Url; use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; +use Drupal\jsonapi\BackwardCompatibility\tests\Traits\ContentModerationTestTrait; use Drupal\jsonapi\JsonApiResource\NullEntityCollection; use Drupal\jsonapi\Normalizer\HttpExceptionNormalizer; use Drupal\jsonapi\JsonApiResource\JsonApiDocumentTopLevel; use Drupal\jsonapi\ResourceResponse; use Drupal\path\Plugin\Field\FieldType\PathItem; use Drupal\Tests\BrowserTestBase; -use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait; use Drupal\user\Entity\Role; use Drupal\user\EntityOwnerInterface; use Drupal\user\RoleInterface; @@ -2801,7 +2801,10 @@ abstract class ResourceTestBase extends BrowserTestBase { $this->assertTrue($this->container->get('module_installer')->install(['content_moderation'], TRUE), 'Installed modules.'); // Set up an editorial workflow. - $workflow = $this->createEditorialWorkflow(); + $workflow = floatval(\Drupal::VERSION) > 8.5 + ? $this->createEditorialWorkflow() + // @todo Remove when we stop supporting Drupal 8.5. + : entity_load('workflow', 'editorial'); $workflow->getTypePlugin()->addEntityTypeAndBundle(static::$entityTypeId, $this->entity->bundle()); $workflow->save();