You are here

public function InlineEntityFormTest::testHostEntityWithModeration in Lightning Scheduler 8

@depends testHostEntityWithoutModeration

File

tests/src/Functional/InlineEntityFormTest.php, line 134

Class

InlineEntityFormTest
@group lightning_scheduler

Namespace

Drupal\Tests\lightning_scheduler\Functional

Code

public function testHostEntityWithModeration() {
  $page = $this
    ->getSession()
    ->getPage();

  // Test with a moderated host entity.
  $this
    ->drupalGet('node/add/alpha');
  $page
    ->fillField('Title', 'Foobar');
  $this
    ->assertInlineEntityForm()
    ->fillField('Title', 'Foobar');
  $host_field = 'moderation_state[0][scheduled_transitions][data]';
  $inline_field = 'field_inline_entity[0][inline_entity_form][moderation_state][0][scheduled_transitions][data]';
  $transition_1 = [
    [
      'state' => 'published',
      'when' => time() + 100,
    ],
  ];
  $transition_2 = [
    [
      'state' => 'published',
      'when' => time() + 200,
    ],
  ];
  $this
    ->setTransitionData($host_field, $transition_1);
  $this
    ->setTransitionData($inline_field, $transition_2);
  $page
    ->pressButton('Save');

  /** @var \Drupal\Core\Entity\EntityStorageInterface $storage */
  $storage = $this->container
    ->get('entity_type.manager')
    ->getStorage('node');
  $alpha = $storage
    ->loadByProperties([
    'type' => 'alpha',
  ]);
  $beta = $storage
    ->loadByProperties([
    'type' => 'beta',
  ]);
  $this
    ->assertCount(1, $alpha);
  $this
    ->assertCount(1, $beta);
  $this
    ->drupalGet(reset($alpha)
    ->toUrl('edit-form'));
  $this
    ->assertTransitionData($host_field, $transition_1);
  $this
    ->drupalGet(reset($beta)
    ->toUrl('edit-form'));
  $this
    ->assertTransitionData($host_field, $transition_2);
}