public function PluginsTest::testIframeDisplayPlugin in Entity Browser 8.2
Same name and namespace in other branches
- 8 tests/src/FunctionalJavascript/PluginsTest.php \Drupal\Tests\entity_browser\FunctionalJavascript\PluginsTest::testIframeDisplayPlugin()
Tests the Entity browser iframe display plugin.
File
- tests/
src/ FunctionalJavascript/ PluginsTest.php, line 17
Class
- PluginsTest
- Tests the entity_browser plugins.
Namespace
Drupal\Tests\entity_browser\FunctionalJavascriptCode
public function testIframeDisplayPlugin() {
$browser = $this
->getEntityBrowser('test_entity_browser_file', 'iframe', 'single', 'no_display');
$image = $this
->createFile('lama');
// Tests view widget on single display.
$this
->drupalGet('node/add/article');
$this
->assertSession()
->linkExists('Select entities');
$this
->getSession()
->getPage()
->clickLink('Select entities');
$this
->getSession()
->switchToIFrame('entity_browser_iframe_test_entity_browser_file');
$this
->getSession()
->getPage()
->checkField('entity_browser_select[file:' . $image
->id() . ']');
$this
->getSession()
->getPage()
->pressButton('Select entities');
$this
->getSession()
->switchToIFrame();
$this
->assertSession()
->waitForElement('css', '.field--type-entity-reference .button');
$this
->assertSession()
->pageTextContains('lama.jpg');
// Tests upload widget on single display. Gets the upload widget and sets
// the weight so we can test the view widget.
$upload_widget = $browser
->getWidget('2dc1ab07-2f8f-42c9-aab7-7eef7f8b7d87');
$upload_widget
->setWeight(0);
$browser
->save();
$this
->drupalGet('node/add/article');
$this
->assertSession()
->linkExists('Select entities');
$this
->getSession()
->getPage()
->clickLink('Select entities');
$this
->getSession()
->switchToIFrame('entity_browser_iframe_test_entity_browser_file');
$this
->getSession()
->getPage()
->checkField('entity_browser_select[file:' . $image
->id() . ']');
$this
->getSession()
->getPage()
->pressButton('Select entities');
$this
->getSession()
->switchToIFrame();
$this
->assertSession()
->waitForElement('css', '.field--type-entity-reference .button');
$this
->assertSession()
->pageTextContains('lama.jpg');
// Tests view tab with tabs widget selector.
$this
->getEntityBrowser('test_entity_browser_file', 'iframe', 'tabs', 'no_display');
$this
->drupalGet('node/add/article');
$this
->assertSession()
->linkExists('Select entities');
$this
->getSession()
->getPage()
->clickLink('Select entities');
$this
->getSession()
->switchToIFrame('entity_browser_iframe_test_entity_browser_file');
$this
->assertSession()
->linkExists('view');
$this
->assertSession()
->linkExists('upload');
$this
->clickLink('view');
$this
->getSession()
->getPage()
->checkField('entity_browser_select[file:' . $image
->id() . ']');
$this
->getSession()
->getPage()
->pressButton('Select entities');
$this
->getSession()
->switchToIFrame();
$this
->assertSession()
->waitForElement('css', '.field--type-entity-reference .button');
$this
->assertSession()
->pageTextContains('lama.jpg');
// Tests upload tab with tabs widget selector.
$this
->drupalGet('node/add/article');
$this
->getSession()
->getPage()
->clickLink('Select entities');
$this
->getSession()
->switchToIFrame('entity_browser_iframe_test_entity_browser_file');
$this
->clickLink('upload');
$this
->getSession()
->getPage()
->attachFileToField('edit-upload-upload', $this->container
->get('file_system')
->realpath($image
->getFileUri()));
$this
->assertSession()
->assertWaitOnAjaxRequest();
$image2 = $this
->getLastUploadedFile();
$this
->assertEquals('lama_0.jpg', $image2
->label());
$this
->getSession()
->getPage()
->checkField('upload[file_' . $image2
->id() . '][selected]');
$this
->getSession()
->getPage()
->pressButton('Select files');
$this
->getSession()
->switchToIFrame();
$this
->assertSession()
->assertWaitOnAjaxRequest();
$this
->assertSession()
->pageTextContains('lama_0.jpg');
// Tests view widget with drop down widget selector.
$this
->getEntityBrowser('test_entity_browser_file', 'iframe', 'drop_down', 'no_display');
// DropDown widget selector does not work with exposed view filter. This is
// a known bug and we need to remove exposed filters from the view until
// that is fixed.
/** @var \Drupal\views\Entity\View $view */
$view = $this->container
->get('entity_type.manager')
->getStorage('view')
->load('files_entity_browser');
$display =& $view
->getDisplay('default');
$display['display_options']['filters'] = [];
$view
->save();
$this
->drupalGet('node/add/article');
$this
->getSession()
->getPage()
->clickLink('Select entities');
$this
->getSession()
->switchToIFrame('entity_browser_iframe_test_entity_browser_file');
$this
->assertSession()
->selectExists('edit-widget');
$this
->getSession()
->getPage()
->checkField('entity_browser_select[file:' . $image
->id() . ']');
$this
->getSession()
->getPage()
->pressButton('Select entities');
$this
->getSession()
->switchToIFrame();
$this
->assertSession()
->waitForElement('css', '.field--type-entity-reference .button');
$this
->assertSession()
->pageTextContains('lama.jpg');
// Tests upload widget with drop down widget selector.
$this
->drupalGet('node/add/article');
$this
->getSession()
->getPage()
->clickLink('Select entities');
$this
->getSession()
->switchToIFrame('entity_browser_iframe_test_entity_browser_file');
$this
->getSession()
->getPage()
->selectFieldOption('edit-widget', '2dc1ab07-2f8f-42c9-aab7-7eef7f8b7d87');
$this
->assertSession()
->assertWaitOnAjaxRequest();
$this
->getSession()
->getPage()
->attachFileToField('files[upload][]', $this->container
->get('file_system')
->realpath($image
->getFileUri()));
$this
->assertSession()
->assertWaitOnAjaxRequest();
$image3 = $this
->getLastUploadedFile();
$this
->getSession()
->getPage()
->checkField('upload[file_' . $image3
->id() . '][selected]');
$this
->getSession()
->getPage()
->pressButton('Select files');
$this
->getSession()
->switchToIFrame();
$this
->assertSession()
->assertWaitOnAjaxRequest();
// In iframe I get page not found, so this fails.
$this
->assertSession()
->pageTextContains($image3
->label());
// Tests view selection display.
$view_configuration = [
'view' => 'test_selection_display_view',
'view_display' => 'entity_browser_1',
];
$browser = $this
->getEntityBrowser('test_entity_browser_file', 'iframe', 'single', 'view', [], [], $view_configuration);
$this
->drupalGet('node/add/article');
$this
->getSession()
->getPage()
->clickLink('Select entities');
$this
->getSession()
->switchToIFrame('entity_browser_iframe_test_entity_browser_file');
// Tests multistep selection display.
$dragon_image = $this
->createFile('dragon');
$unicorn_image = $this
->createFile('unicorn');
$upload_widget = $browser
->getWidget('2dc1ab07-2f8f-42c9-aab7-7eef7f8b7d87');
$upload_widget
->setWeight(-9);
$browser
->save();
$multistep_configuration = [
'entity_type' => 'file',
'display' => 'label',
'display_settings' => [],
'select_text' => 'Use selected',
'selection_hidden' => 0,
];
$browser = $this
->getEntityBrowser('test_entity_browser_file', 'iframe', 'tabs', 'multi_step_display', [], [], $multistep_configuration);
$upload_widget = $browser
->getWidget('774798f1-5ec5-4b63-84bd-124cd51ec07d');
$upload_widget
->setWeight(0);
$browser
->save();
$this
->drupalGet('node/add/article');
$this
->getSession()
->getPage()
->clickLink('Select entities');
$this
->getSession()
->switchToIFrame('entity_browser_iframe_test_entity_browser_file');
$this
->getSession()
->getPage()
->attachFileToField('files[upload][]', $this->container
->get('file_system')
->realpath($dragon_image
->getFileUri()));
$this
->assertSession()
->assertWaitOnAjaxRequest();
$this
->getSession()
->getPage()
->pressButton('Select files');
$image4 = $this
->getLastUploadedFile();
$this
->assertEquals('dragon_0.jpg', $image4
->label());
$this
->assertSession()
->pageTextContains('dragon_0.jpg');
$this
->assertSession()
->pageTextNotContains('unicorn.jpg');
$this
->getSession()
->getPage()
->clickLink('view');
$this
->assertSession()
->waitForField('entity_browser_select[file:' . $unicorn_image
->id() . ']')
->check();
$this
->getSession()
->getPage()
->pressButton('Select entities');
$this
->assertSession()
->assertWaitOnAjaxRequest();
$this
->assertSession()
->waitForElement('css', '#edit-selected-items-2-1-remove-button');
$this
->assertSession()
->waitForElement('css', '#edit-selected-items-1-0-remove-button');
$this
->getSession()
->getPage()
->pressButton('Use selected');
$this
->getSession()
->switchToIFrame();
$this
->assertSession()
->assertWaitOnAjaxRequest();
$this
->assertSession()
->pageTextContains('dragon_0.jpg');
$this
->assertSession()
->pageTextContains('unicorn.jpg');
}