class WorkflowStateTransitionOperationsAccessCheckTest in Drupal 8
Same name and namespace in other branches
- 9 core/modules/workflows/tests/src/Unit/WorkflowStateTransitionOperationsAccessCheckTest.php \Drupal\Tests\workflows\Unit\WorkflowStateTransitionOperationsAccessCheckTest
- 10 core/modules/workflows/tests/src/Unit/WorkflowStateTransitionOperationsAccessCheckTest.php \Drupal\Tests\workflows\Unit\WorkflowStateTransitionOperationsAccessCheckTest
@coversDefaultClass \Drupal\workflows\WorkflowStateTransitionOperationsAccessCheck @group workflows
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\workflows\Unit\WorkflowStateTransitionOperationsAccessCheckTest
Expanded class hierarchy of WorkflowStateTransitionOperationsAccessCheckTest
File
- core/
modules/ workflows/ tests/ src/ Unit/ WorkflowStateTransitionOperationsAccessCheckTest.php, line 19
Namespace
Drupal\Tests\workflows\UnitView source
class WorkflowStateTransitionOperationsAccessCheckTest extends UnitTestCase {
/**
* Test the access method correctly proxies to the entity access system.
*
* @covers ::access
* @dataProvider accessTestCases
*/
public function testAccess($route_requirement, $resulting_entity_access_check, $route_parameters = []) {
$workflow_entity_access_result = AccessResult::allowed();
$workflow = $this
->prophesize(WorkflowInterface::class);
$workflow
->access($resulting_entity_access_check, Argument::type(AccountInterface::class), TRUE)
->shouldBeCalled()
->willReturn($workflow_entity_access_result);
$route = new Route('', [
'workflow' => NULL,
'workflow_transition' => NULL,
'workflow_state' => NULL,
], [
'_workflow_access' => $route_requirement,
]);
$route_match_params = [
'workflow' => $workflow
->reveal(),
] + $route_parameters;
$route_match = new RouteMatch(NULL, $route, $route_match_params);
$access_check = new WorkflowStateTransitionOperationsAccessCheck();
$account = $this
->prophesize(AccountInterface::class);
$this
->assertEquals($workflow_entity_access_result, $access_check
->access($route_match, $account
->reveal()));
}
/**
* Test cases for ::testAccess.
*/
public function accessTestCases() {
return [
'Transition add' => [
'add-transition',
'add-transition',
],
'Transition update' => [
'update-transition',
'update-transition:foo-transition',
[
'workflow_transition' => 'foo-transition',
],
],
'Transition delete' => [
'delete-transition',
'delete-transition:foo-transition',
[
'workflow_transition' => 'foo-transition',
],
],
'State add' => [
'add-state',
'add-state',
],
'State update' => [
'update-state',
'update-state:bar-state',
[
'workflow_state' => 'bar-state',
],
],
'State delete' => [
'delete-state',
'delete-state:bar-state',
[
'workflow_state' => 'bar-state',
],
],
];
}
/**
* @covers ::access
*/
public function testMissingRouteParams() {
$workflow = $this
->prophesize(WorkflowInterface::class);
$workflow
->access()
->shouldNotBeCalled();
$route = new Route('', [
'workflow' => NULL,
'workflow_state' => NULL,
], [
'_workflow_access' => 'update-state',
]);
$access_check = new WorkflowStateTransitionOperationsAccessCheck();
$account = $this
->prophesize(AccountInterface::class);
$missing_both = new RouteMatch(NULL, $route, []);
$this
->assertEquals(AccessResult::neutral(), $access_check
->access($missing_both, $account
->reveal()));
$missing_state = new RouteMatch(NULL, $route, [
'workflow' => $workflow
->reveal(),
]);
$this
->assertEquals(AccessResult::neutral(), $access_check
->access($missing_state, $account
->reveal()));
$missing_workflow = new RouteMatch(NULL, $route, [
'workflow_state' => 'foo',
]);
$this
->assertEquals(AccessResult::neutral(), $access_check
->access($missing_workflow, $account
->reveal()));
}
/**
* @covers ::access
* @dataProvider invalidOperationNameTestCases
*/
public function testInvalidOperationName($operation_name) {
$this
->expectException(\Exception::class);
$this
->expectExceptionMessage("Invalid _workflow_access operation '{$operation_name}' specified for route 'Foo Route'.");
$route = new Route('', [], [
'_workflow_access' => $operation_name,
]);
$access_check = new WorkflowStateTransitionOperationsAccessCheck();
$account = $this
->prophesize(AccountInterface::class);
$access_check
->access(new RouteMatch('Foo Route', $route, []), $account
->reveal());
}
/**
* Test cases for ::testInvalidOperationName.
*/
public function invalidOperationNameTestCases() {
return [
[
'invalid-op',
],
[
'foo-add-transition',
],
[
'add-transition-bar',
],
];
}
/**
* @covers \Drupal\workflows\WorkflowDeleteAccessCheck::access
* @expectedDeprecation Using the _workflow_state_delete_access check is deprecated in Drupal 8.6.0 and will be removed before Drupal 9.0.0, use _workflow_access instead. As an internal API _workflow_state_delete_access may also be removed in a minor release.
* @group legacy
*/
public function testLegacyWorkflowStateDeleteAccessCheck() {
$workflow_entity_access_result = AccessResult::allowed();
// When using the legacy access check, passing a route with a state called
// 'foo-state' will result in an entity access check of
// 'delete-state:foo-state'.
$workflow = $this
->prophesize(WorkflowInterface::class);
$workflow
->access('delete-state:foo-state', Argument::type(AccountInterface::class), TRUE)
->shouldBeCalled()
->willReturn($workflow_entity_access_result);
$route = new Route('', [
'workflow' => NULL,
'workflow_state' => NULL,
], [
'_workflow_state_delete_access' => 'true',
]);
$route_match = new RouteMatch(NULL, $route, [
'workflow' => $workflow
->reveal(),
'workflow_state' => 'foo-state',
]);
$access_check = new WorkflowDeleteAccessCheck();
$this
->assertEquals($workflow_entity_access_result, $access_check
->access($route_match, $this
->prophesize(AccountInterface::class)
->reveal()));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 340 | |
WorkflowStateTransitionOperationsAccessCheckTest:: |
public | function | Test cases for ::testAccess. | |
WorkflowStateTransitionOperationsAccessCheckTest:: |
public | function | Test cases for ::testInvalidOperationName. | |
WorkflowStateTransitionOperationsAccessCheckTest:: |
public | function | Test the access method correctly proxies to the entity access system. | |
WorkflowStateTransitionOperationsAccessCheckTest:: |
public | function | @covers ::access @dataProvider invalidOperationNameTestCases | |
WorkflowStateTransitionOperationsAccessCheckTest:: |
public | function | @covers \Drupal\workflows\WorkflowDeleteAccessCheck::access @expectedDeprecation Using the _workflow_state_delete_access check is deprecated in Drupal 8.6.0 and will be removed before Drupal 9.0.0, use _workflow_access instead. As an internal API… | |
WorkflowStateTransitionOperationsAccessCheckTest:: |
public | function | @covers ::access |