View source
<?php
namespace Drupal\Tests\entity_browser\FunctionalJavascript;
use Drupal\Component\Utility\NestedArray;
class MultiStepSelectionDisplayTest extends EntityBrowserWebDriverTestBase {
protected function openEntityBrowser() {
$this
->getSession()
->getPage()
->clickLink('Select entities');
$this
->getSession()
->switchToIFrame('entity_browser_iframe_test_entity_browser_file');
$this
->waitForAjaxToFinish();
}
protected function closeEntityBrowser() {
$this
->assertSession()
->elementExists('xpath', '//*[@data-drupal-selector="edit-use-selected"]')
->press();
$this
->getSession()
->switchToIFrame();
$this
->waitForAjaxToFinish();
}
protected function clickViewEntity($entityId) {
$xpathViewRow = '//*[./*[contains(@class, "views-field-entity-browser-select") and .//input[@name="entity_browser_select[' . $entityId . ']"]]]';
$this
->assertSession()
->elementExists('xpath', $xpathViewRow)
->press();
}
protected function waitSelectionDisplayAjaxCommands() {
$this
->waitForAjaxToFinish();
$this
->getSession()
->wait(200);
$this
->waitForAjaxToFinish();
}
protected function changeFieldFormDisplayConfig(array $configuration) {
$form_display = $this->container
->get('entity_type.manager')
->getStorage('entity_form_display')
->load('node.article.default');
$form_display
->setComponent('field_reference', NestedArray::mergeDeep($form_display
->getComponent('field_reference'), $configuration))
->save();
}
public function testAjaxCommands() {
$this
->createFile('test_file1');
$this
->createFile('test_file2');
$this
->createFile('test_file3');
$widget_configurations = [
'774798f1-5ec5-4b63-84bd-124cd51ec07d' => [
'settings' => [
'view' => 'files_entity_browser_html',
'auto_select' => TRUE,
],
],
];
$this
->getEntityBrowser('test_entity_browser_file', 'iframe', 'tabs', 'multi_step_display', [], [], [], $widget_configurations);
$this
->drupalGet('node/add/article');
$this
->openEntityBrowser();
$this
->assertSession()
->elementNotExists('xpath', '//*[@data-drupal-selector="edit-use-selected"]');
$this
->assertSession()
->elementNotExists('xpath', '//*[@data-drupal-selector="edit-show-selection"]');
$this
->clickViewEntity('file:1');
$this
->waitSelectionDisplayAjaxCommands();
$this
->assertSession()
->elementExists('xpath', '//*[@data-drupal-selector="edit-use-selected"]');
$this
->assertSession()
->elementExists('xpath', '//*[@data-drupal-selector="edit-show-selection"]');
$this
->assertSession()
->elementExists('xpath', '//input[@data-row-id="0"]')
->press();
$this
->waitSelectionDisplayAjaxCommands();
$this
->assertSession()
->elementNotExists('xpath', '//*[@data-drupal-selector="edit-use-selected"]');
$this
->assertSession()
->elementNotExists('xpath', '//*[@data-drupal-selector="edit-show-selection"]');
$this
->clickViewEntity('file:1');
$this
->waitSelectionDisplayAjaxCommands();
$this
->closeEntityBrowser();
$widget_configurations = [
'774798f1-5ec5-4b63-84bd-124cd51ec07d' => [
'settings' => [
'view' => 'files_entity_browser',
'auto_select' => TRUE,
],
],
];
$this
->getEntityBrowser('test_entity_browser_file', 'iframe', 'tabs', 'multi_step_display', [], [], [], $widget_configurations);
$this
->drupalGet('node/add/article');
$this
->openEntityBrowser();
$entitiesToAdd = [
'file:1',
'file:2',
'file:3',
'file:1',
'file:2',
];
foreach ($entitiesToAdd as $entityId) {
$this
->clickViewEntity($entityId);
}
$this
->waitSelectionDisplayAjaxCommands();
$this
->assertSession()
->elementsCount('xpath', '//div[contains(@class, "entities-list")]/*', 5);
foreach (array_keys($entitiesToAdd) as $entityIndex) {
$this
->assertSession()
->elementExists('xpath', '//input[@data-row-id="' . $entityIndex . '"]')
->press();
}
$this
->waitSelectionDisplayAjaxCommands();
$this
->assertSession()
->elementNotExists('xpath', '//*[@data-drupal-selector="edit-use-selected"]');
$this
->assertSession()
->elementNotExists('xpath', '//*[@data-drupal-selector="edit-show-selection"]');
$this
->clickViewEntity('file:1');
$this
->waitSelectionDisplayAjaxCommands();
$this
->closeEntityBrowser();
$widget_configurations = [
'774798f1-5ec5-4b63-84bd-124cd51ec07d' => [
'settings' => [
'view' => 'files_entity_browser_grid',
'auto_select' => TRUE,
],
],
];
$this
->getEntityBrowser('test_entity_browser_file', 'iframe', 'tabs', 'multi_step_display', [], [], [], $widget_configurations);
$this
->changeFieldFormDisplayConfig([
'settings' => [
'selection_mode' => 'selection_edit',
],
]);
$this
->drupalGet('node/add/article');
$this
->openEntityBrowser();
$this
->clickViewEntity('file:1');
$this
->waitSelectionDisplayAjaxCommands();
$this
->closeEntityBrowser();
$this
->openEntityBrowser();
$this
->clickViewEntity('file:2');
$this
->waitSelectionDisplayAjaxCommands();
$this
->closeEntityBrowser();
$this
->assertSession()
->elementsCount('xpath', '//div[contains(@class, "entities-list")]/*', 2);
$widget_configurations = [
'774798f1-5ec5-4b63-84bd-124cd51ec07d' => [
'settings' => [
'view' => 'files_entity_browser_unformatted',
'auto_select' => TRUE,
],
],
];
$this
->getEntityBrowser('test_entity_browser_file', 'iframe', 'tabs', 'multi_step_display', [], [], [], $widget_configurations);
$this
->drupalGet('node/add/article');
$this
->openEntityBrowser();
$entitiesToAdd = [
'file:1',
'file:2',
'file:3',
];
foreach ($entitiesToAdd as $entityId) {
$this
->clickViewEntity($entityId);
$this
->waitSelectionDisplayAjaxCommands();
}
$this
->closeEntityBrowser();
$this
->assertSession()
->elementsCount('xpath', '//div[contains(@class, "entities-list")]/*', 3);
$this
->openEntityBrowser();
$this
->assertSession()
->elementExists('xpath', '//input[@data-row-id="0"]')
->press();
$this
->waitSelectionDisplayAjaxCommands();
$this
->closeEntityBrowser();
$this
->assertSession()
->elementsCount('xpath', '//div[contains(@class, "entities-list")]/*', 2);
}
}