function StateTransitionValidationTest::testUserSensitiveValidTransitions
Same name in other branches
- 9 core/modules/content_moderation/tests/src/Unit/StateTransitionValidationTest.php \Drupal\Tests\content_moderation\Unit\StateTransitionValidationTest::testUserSensitiveValidTransitions()
- 10 core/modules/content_moderation/tests/src/Unit/StateTransitionValidationTest.php \Drupal\Tests\content_moderation\Unit\StateTransitionValidationTest::testUserSensitiveValidTransitions()
- 11.x core/modules/content_moderation/tests/src/Unit/StateTransitionValidationTest.php \Drupal\Tests\content_moderation\Unit\StateTransitionValidationTest::testUserSensitiveValidTransitions()
Verifies user-aware transition validation.
@dataProvider userTransitionsProvider
Parameters
string $from_id: The state to transition from.
string $to_id: The state to transition to.
string $permission: The permission to give the user, or not.
bool $allowed: Whether or not to grant a user this permission.
bool $result: Whether getValidTransitions() is expected to have the.
File
-
core/
modules/ content_moderation/ tests/ src/ Unit/ StateTransitionValidationTest.php, line 71
Class
- StateTransitionValidationTest
- @coversDefaultClass \Drupal\content_moderation\StateTransitionValidation @group content_moderation
Namespace
Drupal\Tests\content_moderation\UnitCode
public function testUserSensitiveValidTransitions($from_id, $to_id, $permission, $allowed, $result) {
$user = $this->prophesize(AccountInterface::class);
// The one listed permission will be returned as instructed; Any others are
// always denied.
$user->hasPermission($permission)
->willReturn($allowed);
$user->hasPermission(Argument::type('string'))
->willReturn(FALSE);
$entity = $this->prophesize(ContentEntityInterface::class);
$entity = $entity->reveal();
$entity->moderation_state = new \stdClass();
$entity->moderation_state->value = $from_id;
$moderation_info = $this->prophesize(ModerationInformationInterface::class);
$moderation_info->getWorkflowForEntity($entity)
->willReturn($this->workflow);
$validator = new StateTransitionValidation($moderation_info->reveal());
$has_transition = FALSE;
foreach ($validator->getValidTransitions($entity, $user->reveal()) as $transition) {
if ($transition->to()
->id() === $to_id) {
$has_transition = TRUE;
break;
}
}
$this->assertSame($result, $has_transition);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.