Commit 6002539d authored by larowlan's avatar larowlan

Issue #2843785 by vaplas, Sam152, Wim Leers: EntityResource: Provide...

Issue #2843785 by vaplas, Sam152, Wim Leers: EntityResource: Provide comprehensive test coverage for Workflow entity
parent d00ef290
<?php
namespace Drupal\Tests\workflows\Functional\Hal;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
use Drupal\Tests\workflows\Functional\Rest\WorkflowResourceTestBase;
/**
* @group hal
*/
class WorkflowHalJsonAnonTest extends WorkflowResourceTestBase {
use AnonResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['hal'];
/**
* {@inheritdoc}
*/
protected static $format = 'hal_json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/hal+json';
}
<?php
namespace Drupal\Tests\workflows\Functional\Hal;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
/**
* @group hal
*/
class WorkflowHalJsonBasicAuthTest extends WorkflowHalJsonAnonTest {
use BasicAuthResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['basic_auth'];
/**
* {@inheritdoc}
*/
protected static $auth = 'basic_auth';
}
<?php
namespace Drupal\Tests\workflows\Functional\Hal;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
/**
* @group hal
*/
class WorkflowHalJsonCookieTest extends WorkflowHalJsonAnonTest {
use CookieResourceTestTrait;
/**
* {@inheritdoc}
*/
protected static $auth = 'cookie';
}
<?php
namespace Drupal\Tests\workflows\Functional\Rest;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
/**
* @group rest
*/
class WorkflowJsonAnonTest extends WorkflowResourceTestBase {
use AnonResourceTestTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
}
<?php
namespace Drupal\Tests\workflows\Functional\Rest;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
/**
* @group rest
*/
class WorkflowJsonBasicAuthTest extends WorkflowResourceTestBase {
use BasicAuthResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['basic_auth'];
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
/**
* {@inheritdoc}
*/
protected static $auth = 'basic_auth';
}
<?php
namespace Drupal\Tests\workflows\Functional\Rest;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
/**
* @group rest
*/
class WorkflowJsonCookieTest extends WorkflowResourceTestBase {
use CookieResourceTestTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
/**
* {@inheritdoc}
*/
protected static $auth = 'cookie';
}
<?php
namespace Drupal\Tests\workflows\Functional\Rest;
use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
use Drupal\workflows\Entity\Workflow;
/**
* ResourceTestBase for Workflow entity.
*/
abstract class WorkflowResourceTestBase extends EntityResourceTestBase {
/**
* {@inheritdoc}
*/
public static $modules = [
'workflows',
'workflow_type_test',
];
/**
* {@inheritdoc}
*/
protected static $entityTypeId = 'workflow';
/**
* {@inheritdoc}
*/
protected static $patchProtectedFieldNames = [];
/**
* The Workflow entity.
*
* @var \Drupal\workflows\WorkflowInterface
*/
protected $entity;
/**
* {@inheritdoc}
*/
protected function setUpAuthorization($method) {
$this->grantPermissionsToTestedRole(['administer workflows']);
}
/**
* {@inheritdoc}
*/
protected function createEntity() {
$workflow = Workflow::create([
'id' => 'rest_workflow',
'label' => 'REST Worklow',
'type' => 'workflow_type_complex_test',
]);
$workflow
->addState('draft', 'Draft')
->addState('published', 'Published');
$workflow->getTypePlugin()->setConfiguration([
'example_setting' => 'foo',
'states' => [
'draft' => [
'extra' => 'bar',
],
],
]);
$workflow->save();
return $workflow;
}
/**
* {@inheritdoc}
*/
protected function getExpectedNormalizedEntity() {
return [
'dependencies' => [
'module' => [
'workflow_type_test',
],
],
'id' => 'rest_workflow',
'label' => 'REST Worklow',
'langcode' => 'en',
'states' => [
'draft' => [
'label' => 'Draft',
'weight' => 0,
],
'published' => [
'label' => 'Published',
'weight' => 1,
],
],
'status' => TRUE,
'transitions' => [],
'type' => 'workflow_type_complex_test',
'type_settings' => [
'states' => [
'draft' => [
'extra' => 'bar',
],
],
'transitions' => [],
'example_setting' => 'foo',
],
'uuid' => $this->entity->uuid(),
];
}
/**
* {@inheritdoc}
*/
protected function getNormalizedPostEntity() {
// @todo Update in https://www.drupal.org/node/2300677.
}
}
# Workflows extension relation types.
# See https://tools.ietf.org/html/rfc5988#section-4.2.
add-state-form:
uri: https://drupal.org/link-relations/add-state-form
description: A form where a state can be created.
add-transition-form:
uri: https://drupal.org/link-relations/add-transition-form
description: A form where a transition can be created.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment