function EntityStateChangeValidationTest::testTransitionAccessValidation

Same name in other branches
  1. 9 core/modules/content_moderation/tests/src/Kernel/EntityStateChangeValidationTest.php \Drupal\Tests\content_moderation\Kernel\EntityStateChangeValidationTest::testTransitionAccessValidation()
  2. 8.9.x core/modules/content_moderation/tests/src/Kernel/EntityStateChangeValidationTest.php \Drupal\Tests\content_moderation\Kernel\EntityStateChangeValidationTest::testTransitionAccessValidation()
  3. 10 core/modules/content_moderation/tests/src/Kernel/EntityStateChangeValidationTest.php \Drupal\Tests\content_moderation\Kernel\EntityStateChangeValidationTest::testTransitionAccessValidation()

@dataProvider transitionAccessValidationTestCases

File

core/modules/content_moderation/tests/src/Kernel/EntityStateChangeValidationTest.php, line 346

Class

EntityStateChangeValidationTest
@coversDefaultClass \Drupal\content_moderation\Plugin\Validation\Constraint\ModerationStateConstraintValidator @group content_moderation

Namespace

Drupal\Tests\content_moderation\Kernel

Code

public function testTransitionAccessValidation($permissions, $target_state, $messages) : void {
    $node_type = NodeType::create([
        'type' => 'example',
        'name' => 'Example',
    ]);
    $node_type->save();
    $workflow = $this->createEditorialWorkflow();
    $workflow->getTypePlugin()
        ->addState('foo', 'Foo');
    $workflow->getTypePlugin()
        ->addTransition('draft_to_foo', 'Draft to foo', [
        'draft',
    ], 'foo');
    $workflow->getTypePlugin()
        ->addTransition('foo_to_foo', 'Foo to foo', [
        'foo',
    ], 'foo');
    $workflow->getTypePlugin()
        ->addEntityTypeAndBundle('node', 'example');
    $workflow->save();
    $this->setCurrentUser($this->createUser($permissions));
    $node = Node::create([
        'type' => 'example',
        'title' => 'Test content',
        'moderation_state' => $target_state,
    ]);
    $this->assertTrue($node->isNew());
    $violations = $node->validate();
    $this->assertSameSize($messages, $violations);
    foreach ($messages as $i => $message) {
        $this->assertEquals($message, $violations->get($i)
            ->getMessage());
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.