public function ComplexWidgetRevisionsTest::testRevisionsWithTestEntityNoBundle in Inline Entity Form 8
Tests saving entity revision with test entity that has no bundle.
File
- tests/
src/ FunctionalJavascript/ ComplexWidgetRevisionsTest.php, line 219
Class
- ComplexWidgetRevisionsTest
- IEF complex entity reference revisions tests.
Namespace
Drupal\Tests\inline_entity_form\FunctionalJavascriptCode
public function testRevisionsWithTestEntityNoBundle() {
// Get the xpath selectors for the fields in this test.
$title_field_xpath = $this
->getXpathForNthInputByLabelText('Title', 1);
$name_field_xpath = $this
->getXpathForNthInputByLabelText('Name', 1);
// Get the xpath selectors for the buttons in this test.
$first_add_new_no_bundle_node_button = $this
->getXpathForButtonWithValue('Add new entity test without bundle', 1);
$first_no_bundle_create_node_button = $this
->getXpathForButtonWithValue('Create entity test without bundle', 1);
$first_no_bundle_node_edit_button = $this
->getXpathForButtonWithValue('Edit', 1);
$first_no_bundle_update_node_button = $this
->getXpathForButtonWithValue('Update entity test without bundle', 1);
$this
->drupalGet($this->formContentAddUrl);
$page = $this
->getSession()
->getPage();
$assert_session = $this
->assertSession();
// Open up test entity with no bundle IEF form.
$assert_session
->elementExists('xpath', $first_add_new_no_bundle_node_button)
->press();
$assert_session
->waitForElementRemoved('xpath', $first_add_new_no_bundle_node_button);
$this
->assertNotEmpty($assert_session
->waitForElement('xpath', $first_no_bundle_create_node_button));
// Save level 2 test entity without bundle IEF form.
$assert_session
->elementExists('xpath', $name_field_xpath)
->setValue('Level 2 entity without bundle');
$assert_session
->elementExists('xpath', $first_no_bundle_create_node_button)
->press();
$assert_session
->waitForElementRemoved('xpath', $first_add_new_no_bundle_node_button);
$this
->assertNotEmpty($assert_session
->waitForElement('xpath', $first_no_bundle_node_edit_button));
// Save the top level entity.
$assert_session
->elementExists('xpath', $title_field_xpath)
->setValue('Level 1');
$page
->pressButton('Save');
// Assert that the entities are correctly saved.
$assert_session
->pageTextContains('Level 1 has been created.');
$assert_session
->pageTextContains('Level 2 entity without bundle');
// Load the new revision id of the entity.
$entity_no_bundle = $this->container
->get('entity_type.manager')
->getStorage('entity_test_no_bundle')
->loadByProperties([
'name' => 'Level 2 entity without bundle',
]);
$entity = reset($entity_no_bundle);
$entity_no_bundle_vid = $entity
->getLoadedRevisionId();
// Re-edit the created node to test for revisions.
$node = $this
->drupalGetNodeByTitle('Level 1');
$this
->drupalGet('node/' . $node
->id() . '/edit');
// Open up test entity with no bundle IEF form for editing.
$assert_session
->elementExists('xpath', $first_no_bundle_node_edit_button)
->press();
$this
->assertNotEmpty($assert_session
->waitForElement('xpath', $first_no_bundle_update_node_button));
// Change test entity with no bundle title.
$assert_session
->elementExists('xpath', $name_field_xpath)
->setValue('Level 2.1 entity without bundle');
$assert_session
->elementExists('xpath', $first_no_bundle_update_node_button)
->press();
$this
->assertNotEmpty($assert_session
->waitForElement('xpath', $first_no_bundle_node_edit_button));
// Save the top level entity.
$page
->fillField('title[0][value]', 'Level 1.1');
$page
->pressButton('Save');
// Assert that the entities are correctly saved.
$assert_session
->pageTextContains('Level 1.1 has been updated.');
$assert_session
->pageTextContains('Level 2.1 entity without bundle');
// Reload the new revision id of the entity.
$this->container
->get('entity_type.manager')
->getStorage('entity_test_no_bundle')
->resetCache();
$entity_no_bundle = $this->container
->get('entity_type.manager')
->getStorage('entity_test_no_bundle')
->load($entity
->id());
$entity_no_bundle_vid_new = $entity_no_bundle
->getLoadedRevisionId();
// Assert that new revision was created.
$this
->assertNotEquals($entity_no_bundle_vid, $entity_no_bundle_vid_new);
}