class WorkflowStateTransitionOperationsAccessCheckTest
Tests Drupal\workflows\WorkflowStateTransitionOperationsAccessCheck.
Attributes
#[CoversClass(WorkflowStateTransitionOperationsAccessCheck::class)]
#[Group('workflows')]
Hierarchy
- class \Drupal\Tests\UnitTestCase uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\workflows\Unit\WorkflowStateTransitionOperationsAccessCheckTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of WorkflowStateTransitionOperationsAccessCheckTest
File
-
core/
modules/ workflows/ tests/ src/ Unit/ WorkflowStateTransitionOperationsAccessCheckTest.php, line 22
Namespace
Drupal\Tests\workflows\UnitView source
class WorkflowStateTransitionOperationsAccessCheckTest extends UnitTestCase {
/**
* Tests the access method correctly proxies to the entity access system.
*
* @legacy-covers ::access
*/
public function testAccess($route_requirement, $resulting_entity_access_check, $route_parameters = []) : void {
$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 static 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',
],
],
];
}
/**
* Tests missing route params.
*
* @legacy-covers ::access
*/
public function testMissingRouteParams() : void {
$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()));
}
/**
* Tests invalid operation name.
*
* @legacy-covers ::access
*/
public function testInvalidOperationName($operation_name) : void {
$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 static function invalidOperationNameTestCases() {
return [
[
'invalid-op',
],
[
'foo-add-transition',
],
[
'add-transition-bar',
],
];
}
}
Members
| Title Sort descending | Modifiers | Object type | Summary | Overrides |
|---|---|---|---|---|
| ExpectDeprecationTrait::expectDeprecation | public | function | Adds an expected deprecation. | |
| ExpectDeprecationTrait::setUpErrorHandler | public | function | Sets up the test error handler. | |
| ExpectDeprecationTrait::tearDownErrorHandler | public | function | Tears down the test error handler. | |
| RandomGeneratorTrait::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | |
| RandomGeneratorTrait::randomMachineName | protected | function | Generates a unique random string containing letters and numbers. | |
| RandomGeneratorTrait::randomObject | public | function | Generates a random PHP object. | |
| RandomGeneratorTrait::randomString | public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |
| UnitTestCase::$root | protected | property | The app root. | |
| UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | |
| UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed array. | |
| UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | |
| UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | |
| UnitTestCase::setDebugDumpHandler | public static | function | Registers the dumper CLI handler when the DebugDump extension is enabled. | |
| UnitTestCase::setUp | protected | function | 366 | |
| UnitTestCase::setupMockIterator | protected | function | Set up a traversable class mock to return specific items when iterated. | |
| WorkflowStateTransitionOperationsAccessCheckTest::accessTestCases | public static | function | Test cases for ::testAccess. | |
| WorkflowStateTransitionOperationsAccessCheckTest::invalidOperationNameTestCases | public static | function | Test cases for ::testInvalidOperationName. | |
| WorkflowStateTransitionOperationsAccessCheckTest::testAccess | public | function | Tests the access method correctly proxies to the entity access system. | |
| WorkflowStateTransitionOperationsAccessCheckTest::testInvalidOperationName | public | function | Tests invalid operation name. | |
| WorkflowStateTransitionOperationsAccessCheckTest::testMissingRouteParams | public | function | Tests missing route params. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.