View source
<?php
namespace Drupal\Tests\entity_browser\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
class EntityEmbedTest extends WebDriverTestBase {
protected static $modules = [
'entity_browser',
'entity_browser_test',
'embed',
'entity_embed',
'entity_browser_entity_embed_test',
];
protected $adminUser;
protected $defaultTheme = 'stark';
protected function setUp() {
parent::setUp();
$this->adminUser = $this
->drupalCreateUser([
'access content',
'use text format full_html',
'create test_entity_embed content',
'access widget_context_default_value entity browser pages',
'access bundle_filter entity browser pages',
]);
}
public function testEntityBrowserWidgetContext() {
$this
->drupalLogin($this->adminUser);
$this
->createNode([
'type' => 'shark',
'title' => 'Luke',
]);
$this
->createNode([
'type' => 'jet',
'title' => 'Leia',
]);
$this
->createNode([
'type' => 'article',
'title' => 'Darth',
]);
$this
->drupalGet('/node/add/test_entity_embed');
$this
->assertSession()
->waitForElement('css', 'a.cke_button__jet_shark_embed')
->click();
$this
->assertSession()
->waitForId('views-exposed-form-widget-context-default-value-entity-browser-1');
$this
->getSession()
->switchToIFrame('entity_browser_iframe_widget_context_default_value');
$this
->assertSession()
->responseContains('Luke');
$this
->assertSession()
->responseContains('Leia');
$this
->assertSession()
->responseNotContains('Darth');
$embed_button = $this->container
->get('entity_type.manager')
->getStorage('embed_button')
->load('jet_shark_embed');
$type_settings = $embed_button
->getTypeSettings();
$type_settings['bundles'] = [
'article' => 'article',
];
$embed_button
->set('type_settings', $type_settings);
$embed_button
->save();
$this
->drupalGet('/node/add/test_entity_embed');
$this
->assertSession()
->waitForElement('css', 'a.cke_button__jet_shark_embed')
->click();
$this
->assertSession()
->waitForId('views-exposed-form-widget-context-default-value-entity-browser-1');
$this
->getSession()
->switchToIFrame('entity_browser_iframe_widget_context_default_value');
$this
->assertSession()
->responseNotContains('Luke');
$this
->assertSession()
->responseNotContains('Leia');
$this
->assertSession()
->responseContains('Darth');
}
public function testContextualBundle() {
$this
->drupalLogin($this->adminUser);
$this
->createNode([
'type' => 'shark',
'title' => 'Luke',
]);
$this
->createNode([
'type' => 'jet',
'title' => 'Leia',
]);
$this
->createNode([
'type' => 'article',
'title' => 'Darth',
]);
$this
->drupalGet('/node/add/test_entity_embed');
$this
->assertSession()
->waitForElement('css', 'a.cke_button__bundle_filter_test')
->click();
$this
->assertSession()
->waitForId('views-exposed-form-bundle-filter-entity-browser-1');
$this
->getSession()
->switchToIFrame('entity_browser_iframe_bundle_filter');
$this
->assertSession()
->responseContains('Luke');
$this
->assertSession()
->responseContains('Leia');
$this
->assertSession()
->responseNotContains('Darth');
$embed_button = $this->container
->get('entity_type.manager')
->getStorage('embed_button')
->load('bundle_filter_test');
$type_settings = $embed_button
->getTypeSettings();
$type_settings['bundles'] = [
'article' => 'article',
];
$embed_button
->set('type_settings', $type_settings);
$embed_button
->save();
$this
->drupalGet('/node/add/test_entity_embed');
$this
->assertSession()
->waitForElement('css', 'a.cke_button__bundle_filter_test')
->click();
$this
->assertSession()
->waitForId('views-exposed-form-bundle-filter-entity-browser-1');
$this
->getSession()
->switchToIFrame('entity_browser_iframe_bundle_filter');
$this
->assertSession()
->responseNotContains('Luke');
$this
->assertSession()
->responseNotContains('Leia');
$this
->assertSession()
->responseContains('Darth');
}
public function testContextualBundleExposed() {
$this
->config('entity_browser.browser.bundle_filter')
->set('widgets.b882a89d-9ce4-4dfe-9802-62df93af232a.settings.view', 'bundle_filter_exposed')
->save();
$this
->drupalLogin($this->adminUser);
$this
->createNode([
'type' => 'shark',
'title' => 'Luke',
]);
$this
->createNode([
'type' => 'jet',
'title' => 'Leia',
]);
$this
->createNode([
'type' => 'article',
'title' => 'Darth',
]);
$this
->drupalGet('/node/add/test_entity_embed');
$this
->assertSession()
->waitForElement('css', 'a.cke_button__bundle_filter_test')
->click();
$this
->assertSession()
->waitForId('views-exposed-form-bundle-filter-entity-browser-1');
$this
->getSession()
->switchToIFrame('entity_browser_iframe_bundle_filter');
$this
->assertSession()
->responseContains('Luke');
$this
->assertSession()
->responseContains('Leia');
$this
->assertSession()
->responseNotContains('Darth');
$this
->assertSession()
->selectExists('Type')
->selectOption('jet');
$this
->assertSession()
->buttonExists('Apply')
->press();
$this
->assertSession()
->assertWaitOnAjaxRequest();
$this
->assertSession()
->pageTextNotContains('Luke');
$this
->assertSession()
->pageTextContains('Leia');
$this
->assertSession()
->pageTextNotContains('Darth');
$this
->assertSession()
->selectExists('Type')
->selectOption('shark');
$this
->assertSession()
->buttonExists('Apply')
->press();
$this
->assertSession()
->assertWaitOnAjaxRequest();
$this
->assertSession()
->pageTextContains('Luke');
$this
->assertSession()
->pageTextNotContains('Leia');
$this
->assertSession()
->pageTextNotContains('Darth');
$this
->assertSession()
->selectExists('Type')
->selectOption('All');
$this
->assertSession()
->buttonExists('Apply')
->press();
$this
->assertSession()
->assertWaitOnAjaxRequest();
$this
->assertSession()
->pageTextContains('Luke');
$this
->assertSession()
->pageTextContains('Leia');
$this
->assertSession()
->pageTextNotContains('Darth');
$embed_button = $this->container
->get('entity_type.manager')
->getStorage('embed_button')
->load('bundle_filter_test');
$type_settings = $embed_button
->getTypeSettings();
$type_settings['bundles'] = [
'article' => 'article',
];
$embed_button
->set('type_settings', $type_settings);
$embed_button
->save();
$this
->drupalGet('/node/add/test_entity_embed');
$this
->assertSession()
->waitForElement('css', 'a.cke_button__bundle_filter_test')
->click();
$this
->assertSession()
->waitForId('views-exposed-form-bundle-filter-entity-browser-1');
$this
->getSession()
->switchToIFrame('entity_browser_iframe_bundle_filter');
$this
->assertSession()
->responseNotContains('Luke');
$this
->assertSession()
->responseNotContains('Leia');
$this
->assertSession()
->responseContains('Darth');
$this
->assertSession()
->fieldNotExists('Type');
}
}