public function Update230Test::testAlterTransitions in Lightning Workflow 8.3
@covers ::alterTransitions
File
- tests/
src/ Kernel/ Update230Test.php, line 71
Class
- Update230Test
- @group lightning_workflow
Namespace
Drupal\Tests\lightning_workflow\KernelCode
public function testAlterTransitions() {
$workflow = <<<END
langcode: en
status: true
id: editorial
label: 'Editorial'
type: content_moderation
type_settings:
states:
archived:
label: Archived
weight: 5
published: false
default_revision: true
draft:
label: Draft
published: false
default_revision: false
weight: -5
published:
label: Published
published: true
default_revision: true
weight: 0
review:
label: 'In review'
weight: -1
published: false
default_revision: false
transitions:
archive:
label: Archive
from:
- published
to: archived
weight: 2
archived_draft:
label: 'Restore to Draft'
from:
- archived
to: draft
weight: 3
archived_published:
label: Restore
from:
- archived
to: published
weight: 4
create_new_draft:
label: 'Create New Draft'
to: draft
weight: 0
from:
- draft
- published
publish:
label: Publish
to: published
weight: 1
from:
- draft
- published
review:
label: Review
to: review
weight: 0
from:
- draft
- review
entity_types: { }
END;
$workflow = Yaml::decode($workflow);
$this
->assertSame(SAVED_NEW, Workflow::create($workflow)
->save());
$io = $this
->prophesize(StyleInterface::class);
$io
->confirm(Argument::any())
->willReturn(TRUE);
$this->update
->alterTransitions($io
->reveal());
$workflow = Workflow::load($workflow['id']);
$this
->assertInstanceOf(Workflow::class, $workflow);
/** @var \Drupal\workflows\Entity\Workflow $workflow */
$plugin = $workflow
->getTypePlugin();
$this
->assertSame('Send to review', $plugin
->getTransition('review')
->label());
$this
->assertSame('Restore from archive', $plugin
->getTransition('archived_published')
->label());
$this
->assertFalse($plugin
->hasTransition('archived_draft'));
$this
->assertArrayHasKey('archived', $plugin
->getTransition('create_new_draft')
->from());
$this
->assertSame('create_new_draft', $plugin
->getTransitionFromStateToState('archived', 'draft')
->id());
}