diff --git a/src/Tests/ComplexSimpleWidgetTest.php b/src/Tests/ComplexSimpleWidgetTest.php index 8b70ae3..92e6f74 100644 --- a/src/Tests/ComplexSimpleWidgetTest.php +++ b/src/Tests/ComplexSimpleWidgetTest.php @@ -113,8 +113,10 @@ class ComplexSimpleWidgetTest extends InlineEntityFormTestBase { * associated with. */ public function testIsolatedCancel() { + // First assertion, two edit forms open, hit Cancel on one, other should + // remain open. $this->drupalGet('node/add/ief_complex_simple'); - // Setup for the test, create two entities + // Create two entities. $outer_title_field = 'ief_complex_outer[form][inline_entity_form][title][0][value]'; $inner_title_field = 'ief_complex_outer[form][inline_entity_form][single][0][inline_entity_form][title][0][value]'; for ($i = 0; $i < 2; $i++) { @@ -130,10 +132,31 @@ class ComplexSimpleWidgetTest extends InlineEntityFormTestBase { // the first, we expect the second to remain open. $this->drupalPostAjaxForm(NULL, [], $this->getButtonName('//input[@type="submit" and @value="Cancel" and @data-drupal-selector="edit-ief-complex-outer-form-inline-entity-form-entities-0-form-actions-ief-edit-cancel"]')); $this->assertFieldByName('ief_complex_outer[form][inline_entity_form][entities][1][form][title][0][value]', '', 'Second inline edit form remained open when the first was closed.'); - // Now lets open a Create form, and Cancel it, we should be left with the - // same second inline entity edit form still open. - $this->drupalPostAjaxForm(NULL, [], $this->getButtonName('//input[@type="submit" and @value="Add new node" and @data-drupal-selector="edit-ief-complex-outer-actions-ief-add"]')); - $this->drupalPostAjaxForm(NULL, [], $this->getButtonName('//input[@type="submit" and @value="Cancel" and @data-drupal-selector="edit-ief-complex-outer-form-inline-entity-form-actions-ief-add-cancel"]')); - $this->assertFieldByName('ief_complex_outer[form][inline_entity_form][entities][1][form][title][0][value]', '', 'Second inline edit form remained open when the create inline entity form was closed.'); + + // Second and third assertion. In both cases, we open and edit form and the + // create form. We then try hitting Cancel on the edit and create in turn + // making sure the other remains open. + $create_clicks = array(TRUE, FALSE); + foreach ($create_clicks as $create_click) { + $this->drupalGet('node/add/ief_complex_simple'); + // Create an entity. + $this->drupalPostAjaxForm(NULL, [], $this->getButtonName('//input[@type="submit" and @value="Add new node" and @data-drupal-selector="edit-ief-complex-outer-actions-ief-add"]')); + $edit[$outer_title_field] = $this->randomMachineName(8); + $edit[$inner_title_field] = $this->randomMachineName(8); + $create_outer_button_selector = '//input[@type="submit" and @value="Create node" and @data-drupal-selector="edit-ief-complex-outer-form-inline-entity-form-actions-ief-add-save"]'; + $this->drupalPostAjaxForm(NULL, $edit, $this->getButtonName($create_outer_button_selector)); + // After it's been created, open the form + $this->drupalPostAjaxForm(NULL, [], $this->getButtonName('//input[@type="submit" and @value="Edit" and @data-drupal-selector="edit-ief-complex-outer-entities-0-actions-ief-entity-edit"]')); + // Open a Create form. + $this->drupalPostAjaxForm(NULL, [], $this->getButtonName('//input[@type="submit" and @value="Add new node" and @data-drupal-selector="edit-ief-complex-outer-actions-ief-add"]')); + if ($create_click) { + $this->drupalPostAjaxForm(NULL, [], $this->getButtonName('//input[@type="submit" and @value="Cancel" and @data-drupal-selector="edit-ief-complex-outer-form-inline-entity-form-actions-ief-add-cancel"]')); + $this->assertFieldByName('ief_complex_outer[form][inline_entity_form][entities][0][form][title][0][value]', '', 'Edit inline entity form remained open when the create inline entity form was closed.'); + } + else { + $this->drupalPostAjaxForm(NULL, [], $this->getButtonName('//input[@type="submit" and @value="Cancel" and @data-drupal-selector="edit-ief-complex-outer-form-inline-entity-form-entities-0-form-actions-ief-edit-cancel"]')); + $this->assertFieldByName('ief_complex_outer[form][inline_entity_form][title][0][value]', '', 'Create inline entity form remained open when the edit inline entity form was closed.'); + } + } } }