public function InlineEntityFormTest::test in Lightning Workflow 8.2
File
- modules/
lightning_scheduler/ tests/ src/ Functional/ InlineEntityFormTest.php, line 118
Class
- InlineEntityFormTest
- @group lightning_workflow @group lightning_scheduler
Namespace
Drupal\Tests\lightning_scheduler\FunctionalCode
public function test() {
$assert = $this
->assertSession();
// Test with an un-moderated host entity.
$this
->drupalGet('/user/' . $this->rootUser
->id() . '/edit');
$assert
->statusCodeEquals(200);
$inline_entity_form = $this
->assertInlineEntityForm();
$assert
->fieldExists('Title', $inline_entity_form)
->setValue('Kaboom?');
$assert
->fieldExists('field_inline_entity[0][inline_entity_form][moderation_state][0][state]');
$assert
->buttonExists('Save')
->press();
$assert
->statusCodeEquals(200);
// Test with a moderated host entity.
$this
->drupalGet('node/add/alpha');
$assert
->fieldExists('title[0][value]')
->setValue('Foobar');
$inline_entity_form = $this
->assertInlineEntityForm();
$assert
->fieldExists('Title', $inline_entity_form)
->setValue('Foobaz');
$host_transitions_field = 'moderation_state[0][scheduled_transitions][data]';
$inline_transitions_field = 'field_inline_entity[0][inline_entity_form][moderation_state][0][scheduled_transitions][data]';
$transition_1 = Json::encode([
[
'state' => 'published',
'when' => gmdate('c', time() + 100),
],
]);
$transition_2 = Json::encode([
[
'state' => 'published',
'when' => gmdate('c', time() + 200),
],
]);
$assert
->hiddenFieldExists($host_transitions_field)
->setValue($transition_1);
$assert
->hiddenFieldExists($inline_transitions_field, $inline_entity_form)
->setValue($transition_2);
$assert
->buttonExists('Save')
->press();
/** @var \Drupal\Core\Entity\EntityStorageInterface $node_storage */
$node_storage = $this->container
->get('entity_type.manager')
->getStorage('node');
$alpha = $node_storage
->loadByProperties([
'type' => 'alpha',
]);
$beta = $node_storage
->loadByProperties([
'type' => 'beta',
]);
$this
->assertCount(1, $alpha);
$this
->assertCount(1, $beta);
$this
->drupalGet(reset($alpha)
->toUrl('edit-form'));
$assert
->hiddenFieldValueEquals($host_transitions_field, $transition_1);
$this
->drupalGet(reset($beta)
->toUrl('edit-form'));
$assert
->hiddenFieldValueEquals($host_transitions_field, $transition_2);
}