You are here

public function ComplexWidgetTest::testEditedInlineEntityValidation in Inline Entity Form 8

Tests if a referenced content can be edited.

When the referenced content is newer than the referencing parent node, test if a referenced content can be edited.

File

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

Class

ComplexWidgetTest
IEF complex field widget tests.

Namespace

Drupal\Tests\inline_entity_form\FunctionalJavascript

Code

public function testEditedInlineEntityValidation() {

  // Get the xpath selectors for the input fields in this test.
  $nested_title_field_xpath = $this
    ->getXpathForNthInputByLabelText('Title', 2);
  $title_field_xpath = $this
    ->getXpathForNthInputByLabelText('Title', 1);
  $page = $this
    ->getSession()
    ->getPage();
  $assert_session = $this
    ->assertSession();
  $this
    ->updateSetting('allow_existing', TRUE);

  // Create referenced content.
  $referenced_nodes = $this
    ->createReferenceContent(1);

  // Create first referencing node.
  $this
    ->drupalCreateNode([
    'type' => 'ief_test_complex',
    'title' => 'First referencing node',
    'multi' => array_values($referenced_nodes),
  ]);
  $first_node = $this
    ->drupalGetNodeByTitle('First referencing node');

  // Create second referencing node.
  $this
    ->drupalCreateNode([
    'type' => 'ief_test_complex',
    'title' => 'Second referencing node',
    'multi' => array_values($referenced_nodes),
  ]);
  $second_node = $this
    ->drupalGetNodeByTitle('Second referencing node');

  // Edit referenced content in first node.
  $this
    ->drupalGet('node/' . $first_node
    ->id() . '/edit');
  $page
    ->pressButton('Edit');
  $this
    ->assertNotEmpty($nested_title = $assert_session
    ->waitForElement('xpath', $nested_title_field_xpath));
  $nested_title
    ->setValue('Some reference updated');
  $page
    ->pressButton('Update node');
  $this
    ->waitForRowByTitle('Some reference updated');
  $assert_session
    ->elementsCount('css', 'tr.ief-row-entity', 1);

  // Save the first node after editing the reference.
  $assert_session
    ->elementExists('xpath', $title_field_xpath)
    ->setValue('First node updated');
  $page
    ->pressButton('Save');
  $assert_session
    ->pageTextContains('IEF test complex First node updated has been updated.');

  // The changed value of the referenced content is now newer than the
  // changed value of the second node.
  // Edit referenced content in second node.
  $this
    ->drupalGet('node/' . $second_node
    ->id() . '/edit');

  // Edit referenced node.
  $page
    ->pressButton('Edit');
  $this
    ->assertNotEmpty($nested_title = $assert_session
    ->waitForElement('xpath', $nested_title_field_xpath));
  $nested_title
    ->setValue('Some reference updated the second time');
  $page
    ->pressButton('Update node');
  $this
    ->waitForRowByTitle('Some reference updated the second time');
  $assert_session
    ->elementsCount('css', 'tr.ief-row-entity', 1);

  // Save the second node after editing the reference.
  $assert_session
    ->elementExists('xpath', $title_field_xpath)
    ->setValue('Second node updated');
  $page
    ->pressButton('Save');
  $assert_session
    ->pageTextContains('IEF test complex Second node updated has been updated.');

  // Check if the referenced content could be edited.
  $assert_session
    ->pageTextNotContains('The content has either been modified by another user, or you have already submitted modifications. As a result, your changes cannot be saved.');
}