public function ConfigurationTest::testWidgetsConfig in Entity Browser 8
Same name and namespace in other branches
- 8.2 tests/src/FunctionalJavascript/ConfigurationTest.php \Drupal\Tests\entity_browser\FunctionalJavascript\ConfigurationTest::testWidgetsConfig()
Tests WidgetsConfig form.
File
- tests/
src/ FunctionalJavascript/ ConfigurationTest.php, line 223
Class
- ConfigurationTest
- Tests the config UI for adding and editing entity browsers.
Namespace
Drupal\Tests\entity_browser\FunctionalJavascriptCode
public function testWidgetsConfig() {
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('/admin/config/content/entity_browser');
$this
->clickLink('Add Entity browser');
$this
->assertSession()
->fieldExists('label')
->setValue('Test entity browser');
$this
->getSession()
->executeScript("jQuery('.visually-hidden').removeClass('visually-hidden');");
$this
->assertSession()
->fieldExists('name')
->setValue('test_entity_browser');
// Use defaults and save to go to WidgetsConfig form.
$this
->drupalPostForm(NULL, [], 'Save');
$this
->assertSession()
->addressEquals('/admin/config/content/entity_browser/test_entity_browser/widgets');
$this
->assertSession()
->pageTextContains('The entity browser Test entity browser has been added. Now you may configure the widgets you would like to use.');
$widgetSelect = $this
->assertSession()
->selectExists('widget');
$this
->assertSession()
->responseContains('The available plugins are:');
$this
->assertSession()
->responseContains("<strong>Upload:</strong> Adds an upload field browser's widget.");
$this
->assertSession()
->responseContains("<strong>View:</strong> Uses a view to provide entity listing in a browser's widget.");
$this
->assertSession()
->responseContains("<strong>Entity form:</strong> Provides entity form widget.");
// Test adding and removing entity form widget.
$widgetSelect
->selectOption('entity_form');
$selector = $this
->assertSession()
->waitforElementVisible('css', 'tr.draggable')
->getAttribute('data-drupal-selector');
$uuid = str_replace('edit-table-', '', $selector);
$this
->assertSession()
->fieldExists("table[{$uuid}][label]");
$this
->assertSession()
->fieldExists("table[{$uuid}][form][submit_text]");
$this
->assertSession()
->selectExists("table[{$uuid}][form][entity_type]")
->selectOption('node');
$this
->assertSession()
->assertWaitOnAjaxRequest();
$this
->assertSession()
->selectExists("table[{$uuid}][form][bundle][select]")
->selectOption('foo');
$this
->assertSession()
->selectExists("table[{$uuid}][form][form_mode][form_select]");
$this
->drupalPostForm(NULL, [], 'Save');
$this
->assertSession()
->addressEquals('/admin/config/content/entity_browser/test_entity_browser/widgets');
$this
->assertSession()
->pageTextContains('The entity browser Test entity browser has been updated.');
$entity_browser = EntityBrowser::load('test_entity_browser');
$widget = $entity_browser
->getWidget($uuid);
$widgetSettings = $widget
->getConfiguration()['settings'];
$this
->assertEquals([
'submit_text' => 'Save entity',
'entity_type' => 'node',
'bundle' => 'foo',
'form_mode' => 'default',
], $widgetSettings, 'Entity browser widget configuration was correctly saved.');
$this
->assertSession()
->buttonExists("edit-table-{$uuid}-remove")
->press();
$this
->assertSession()
->assertWaitOnAjaxRequest();
$this
->assertSession()
->elementNotExists('css', 'tr[data-drupal-selector="edit-table-' . $uuid . '"]');
// There should be no widgets now.
$this
->assertSession()
->elementNotExists('css', 'tr.draggable');
// Test adding and removing view widget.
$widgetSelect
->selectOption('view');
$selector = $this
->assertSession()
->waitforElementVisible('css', 'tr.draggable')
->getAttribute('data-drupal-selector');
$uuid = str_replace('edit-table-', '', $selector);
$this
->assertSession()
->fieldExists("table[{$uuid}][label]");
$this
->assertSession()
->fieldExists("table[{$uuid}][form][submit_text]");
$this
->assertSession()
->fieldExists("table[{$uuid}][form][auto_select]")
->check();
$this
->assertSession()
->selectExists("table[{$uuid}][form][view]")
->selectOption('nodes_entity_browser.entity_browser_1');
$this
->drupalPostForm(NULL, [], 'Save');
$this
->assertSession()
->addressEquals('/admin/config/content/entity_browser/test_entity_browser/widgets');
$this
->assertSession()
->pageTextContains('The entity browser Test entity browser has been updated.');
$entity_browser = EntityBrowser::load('test_entity_browser');
$widget = $entity_browser
->getWidget($uuid);
$widgetSettings = $widget
->getConfiguration()['settings'];
$this
->assertEquals([
'view' => 'nodes_entity_browser',
'view_display' => 'entity_browser_1',
'submit_text' => 'Select entities',
'auto_select' => TRUE,
], $widgetSettings, 'Entity browser widget configuration was correctly saved.');
$this
->assertSession()
->buttonExists("edit-table-{$uuid}-remove")
->press();
$this
->assertSession()
->assertWaitOnAjaxRequest();
$this
->assertSession()
->elementNotExists('css', 'tr[data-drupal-selector="edit-table-' . $uuid . '"]');
// There should be no widgets now.
$this
->assertSession()
->elementNotExists('css', 'tr.draggable');
// Test adding and removing upload widget.
$widgetSelect
->selectOption('upload');
$selector = $this
->assertSession()
->waitforElementVisible('css', 'tr.draggable')
->getAttribute('data-drupal-selector');
$uuid = str_replace('edit-table-', '', $selector);
$this
->assertSession()
->fieldExists("table[{$uuid}][label]");
$this
->assertSession()
->fieldExists("table[{$uuid}][form][submit_text]");
$this
->assertSession()
->fieldExists("table[{$uuid}][form][upload_location]");
$this
->assertSession()
->fieldExists("table[{$uuid}][form][multiple]");
$this
->assertSession()
->fieldExists("table[{$uuid}][form][upload_location]");
$this
->assertSession()
->elementExists('css', 'a.token-dialog.use-ajax');
$this
->drupalPostForm(NULL, [], 'Save');
$this
->assertSession()
->addressEquals('/admin/config/content/entity_browser/test_entity_browser/widgets');
$this
->assertSession()
->pageTextContains('The entity browser Test entity browser has been updated.');
$entity_browser = EntityBrowser::load('test_entity_browser');
$widget = $entity_browser
->getWidget($uuid);
$widgetSettings = $widget
->getConfiguration()['settings'];
$this
->assertEquals([
'upload_location' => 'public://',
'multiple' => TRUE,
'submit_text' => 'Select files',
'extensions' => 'jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp',
], $widgetSettings, 'Entity browser widget configuration was correctly saved.');
$this
->assertSession()
->buttonExists("edit-table-{$uuid}-remove")
->press();
$this
->assertSession()
->assertWaitOnAjaxRequest();
$this
->assertSession()
->elementNotExists('css', 'tr[data-drupal-selector="edit-table-' . $uuid . '"]');
// There should be no widgets now.
$this
->assertSession()
->elementNotExists('css', 'tr.draggable');
// Go back to listing page.
$this
->drupalGet('/admin/config/content/entity_browser');
$this
->assertSession()
->responseContains('admin/config/content/entity_browser/test_entity_browser/edit');
// Test that removing widget without saving doesn't remove it permanently.
$entity_browser = EntityBrowser::load('test_entity_browser');
$widget = $entity_browser
->getWidget($uuid);
$this
->assertNotEmpty($widget);
}