public function InlineEntityFormTest::testEntityBrowserInsideInlineEntityForm in Entity Browser 8
Same name and namespace in other branches
- 8.2 tests/src/FunctionalJavascript/InlineEntityFormTest.php \Drupal\Tests\entity_browser\FunctionalJavascript\InlineEntityFormTest::testEntityBrowserInsideInlineEntityForm()
Check that selection state in entity browser Inline Entity Form.
File
- tests/
src/ FunctionalJavascript/ InlineEntityFormTest.php, line 57
Class
- InlineEntityFormTest
- Test for integration of entity browser and inline entity form.
Namespace
Drupal\Tests\entity_browser\FunctionalJavascriptCode
public function testEntityBrowserInsideInlineEntityForm() {
$this
->createFile('test_file1');
$this
->createFile('test_file2');
$this
->createFile('test_file3');
$this
->drupalGet('node/add/ief_content');
$page = $this
->getSession()
->getPage();
$page
->fillField('Title', 'Test IEF Title');
$page
->pressButton('Add new Test File Media');
$this
->assertSession()
->assertWaitOnAjaxRequest();
$page
->fillField('Media name', 'Test Bundle Media');
$page
->clickLink('Select entities');
$this
->getSession()
->switchToIFrame('entity_browser_iframe_ief_entity_browser_file');
$page
->checkField('entity_browser_select[file:1]');
$page
->checkField('entity_browser_select[file:2]');
$page
->pressButton('Select entities');
$this
->assertSession()
->assertWaitOnAjaxRequest();
$page
->pressButton('Use selected');
$this
->getSession()
->switchToIFrame();
$this
->assertSession()
->assertWaitOnAjaxRequest();
$page
->pressButton('Create Test File Media');
$this
->assertSession()
->assertWaitOnAjaxRequest();
$page
->pressButton('Save');
$this
->drupalGet('node/1/edit');
$page = $this
->getSession()
->getPage();
$page
->pressButton('Edit');
$this
->assertSession()
->assertWaitOnAjaxRequest();
// Test reorder of elements.
$dragged = $this
->xpath("//div[@data-drupal-selector='edit-ief-media-field-form-inline-entity-form-entities-0-form-ief-media-bundle-file-field-current-items-0']")[0];
$this
->dragDropElement($dragged, 150, 0);
$this
->assertSession()
->assertWaitOnAjaxRequest();
$page
->pressButton('Update Test File Media');
$this
->assertSession()
->assertWaitOnAjaxRequest();
$page
->pressButton('Edit');
$this
->assertSession()
->assertWaitOnAjaxRequest();
// Check that element on second position is test_file1 (file:1).
$secondElement = $page
->find('xpath', '//div[@data-drupal-selector="edit-ief-media-field-form-inline-entity-form-entities-0-form-ief-media-bundle-file-field-current"]/div[2]');
if (empty($secondElement)) {
throw new \Exception('Element is not found.');
}
$this
->assertSame('file:1', $secondElement
->getAttribute('data-entity-id'));
// Test remove of element.
$this
->click('input[name*="ief_media_bundle_file_field_remove_1_1"]');
$this
->assertSession()
->assertWaitOnAjaxRequest();
$page
->pressButton('Update Test File Media');
$this
->assertSession()
->assertWaitOnAjaxRequest();
$page
->pressButton('Edit');
$this
->assertSession()
->assertWaitOnAjaxRequest();
// Check that remote button does not exist for already removed entity.
$this
->assertSession()
->elementNotExists('css', '[name*="ief_media_bundle_file_field_remove_1_1"]');
// Test add inside Entity Browser.
$page
->clickLink('Select entities');
$this
->getSession()
->switchToIFrame('entity_browser_iframe_ief_entity_browser_file');
$page
->checkField('entity_browser_select[file:3]');
$page
->pressButton('Select entities');
$this
->assertSession()
->assertWaitOnAjaxRequest();
$page
->pressButton('Use selected');
$this
->getSession()
->switchToIFrame();
$this
->assertSession()
->assertWaitOnAjaxRequest();
$page
->pressButton('Update Test File Media');
$this
->assertSession()
->assertWaitOnAjaxRequest();
$page
->pressButton('Edit');
$this
->assertSession()
->assertWaitOnAjaxRequest();
// Check that element on second position is test_file3 (file:3).
$secondElement = $page
->find('xpath', '//div[@data-drupal-selector="edit-ief-media-field-form-inline-entity-form-entities-0-form-ief-media-bundle-file-field-current"]/div[2]');
if (empty($secondElement)) {
throw new \Exception('Element is not found.');
}
$this
->assertSame('file:3', $secondElement
->getAttribute('data-entity-id'));
// Test reorder inside Entity Browser.
$page
->clickLink('Select entities');
$this
->getSession()
->switchToIFrame('entity_browser_iframe_ief_entity_browser_file');
$dragged = $this
->xpath("//div[@data-drupal-selector='edit-selected-items-2-0']")[0];
$this
->dragDropElement($dragged, 150, 0);
$this
->assertSession()
->assertWaitOnAjaxRequest();
$page
->pressButton('Use selected');
$this
->getSession()
->switchToIFrame();
$this
->assertSession()
->assertWaitOnAjaxRequest();
$page
->pressButton('Update Test File Media');
$this
->assertSession()
->assertWaitOnAjaxRequest();
$page
->pressButton('Edit');
$this
->assertSession()
->assertWaitOnAjaxRequest();
// Check that element on second position is test_file2 (file:2).
$secondElement = $page
->find('xpath', '//div[@data-drupal-selector="edit-ief-media-field-form-inline-entity-form-entities-0-form-ief-media-bundle-file-field-current"]/div[2]');
if (empty($secondElement)) {
throw new \Exception('Element is not found.');
}
$this
->assertSame('file:2', $secondElement
->getAttribute('data-entity-id'));
// Test remove inside entity browser.
$page
->clickLink('Select entities');
$this
->getSession()
->switchToIFrame('entity_browser_iframe_ief_entity_browser_file');
$this
->assertSession()
->assertWaitOnAjaxRequest();
$page
->pressButton('remove_3_0');
$this
->assertSession()
->assertWaitOnAjaxRequest();
$page
->pressButton('Use selected');
$this
->getSession()
->switchToIFrame();
$this
->assertSession()
->assertWaitOnAjaxRequest();
$page
->pressButton('Update Test File Media');
$this
->assertSession()
->assertWaitOnAjaxRequest();
$page
->pressButton('Edit');
$this
->assertSession()
->assertWaitOnAjaxRequest();
// Check that element on first position is test_file2 (file:2).
$secondElement = $page
->find('xpath', '//div[@data-drupal-selector="edit-ief-media-field-form-inline-entity-form-entities-0-form-ief-media-bundle-file-field-current"]/div[1]');
if (empty($secondElement)) {
throw new \Exception('Element is not found.');
}
$this
->assertSame('file:2', $secondElement
->getAttribute('data-entity-id'));
}