You are here

public function ComplexWidgetTest::testDuplicatingEntities in Inline Entity Form 8

Tests if duplicating entities works.

File

tests/src/FunctionalJavascript/ComplexWidgetTest.php, line 557

Class

ComplexWidgetTest
IEF complex field widget tests.

Namespace

Drupal\Tests\inline_entity_form\FunctionalJavascript

Code

public function testDuplicatingEntities() {

  // Get the xpath selectors for the input fields in this test.
  $title_field_xpath = $this
    ->getXpathForNthInputByLabelText('Title', 2);
  $first_name_field_xpath = $this
    ->getXpathForNthInputByLabelText('First name', 1);
  $page = $this
    ->getSession()
    ->getPage();
  $assert_session = $this
    ->assertSession();
  $this
    ->updateSetting('allow_duplicate', TRUE);
  $referenceNodes = $this
    ->createReferenceContent(2);
  $this
    ->drupalCreateNode([
    'type' => 'ief_test_complex',
    'title' => 'Some title',
    'multi' => array_values($referenceNodes),
  ]);
  $parent_node = $this
    ->drupalGetNodeByTitle('Some title');
  $this
    ->drupalGet('node/' . $parent_node
    ->id() . '/edit');
  $this
    ->assertNotEmpty($multi_fieldset = $assert_session
    ->waitForElement('css', 'fieldset[data-drupal-selector="edit-multi"]'));
  $assert_session
    ->buttonExists('Duplicate', $multi_fieldset)
    ->press();
  $this
    ->assertNotEmpty($create_node_button = $assert_session
    ->waitForButton('Duplicate node'));
  $assert_session
    ->elementExists('xpath', $title_field_xpath)
    ->setValue('Duplicate!');
  $assert_session
    ->elementExists('xpath', $first_name_field_xpath)
    ->setValue('Bojan');
  $create_node_button
    ->press();
  $this
    ->waitForRowByTitle('Duplicate!');
  $assert_session
    ->elementsCount('css', 'tr.ief-row-entity', 3);
  $this
    ->assertRowByTitle('Some reference 1');
  $this
    ->assertRowByTitle('Some reference 2');
  $this
    ->assertRowByTitle('Duplicate!');
  $page
    ->pressButton('Save');
  $duplicate = $this
    ->drupalGetNodeByTitle('Duplicate!');
  $this
    ->assertNotEmpty($duplicate, 'Duplicate node created.');
  $this
    ->assertSame('Bojan', $duplicate->first_name->value);
}