You are here

protected function EntityBrowserWebDriverTestBase::getEntityBrowser in Entity Browser 8

Same name and namespace in other branches
  1. 8.2 tests/src/FunctionalJavascript/EntityBrowserWebDriverTestBase.php \Drupal\Tests\entity_browser\FunctionalJavascript\EntityBrowserWebDriverTestBase::getEntityBrowser()

Return an entity browser if it exists or creates a new one.

Parameters

string $browser_name: The entity browser name.

string $display_id: The display plugin id.

string $widget_selector_id: The widget selector id.

string $selection_display_id: The selection display id.

array $display_configuration: The display plugin configuration.

array $widget_selector_configuration: The widget selector configuration.

array $selection_display_configuration: The selection display configuration.

array $widget_configurations: Widget configurations. Have be provided with widget UUIDs.

Return value

\Drupal\entity_browser\EntityBrowserInterface Returns an Entity Browser.

4 calls to EntityBrowserWebDriverTestBase::getEntityBrowser()
MultiStepSelectionDisplayTest::testAjaxCommands in tests/src/FunctionalJavascript/MultiStepSelectionDisplayTest.php
Check that selection state in entity browser Inline Entity Form.
PluginsTest::testIframeDisplayPlugin in tests/src/FunctionalJavascript/PluginsTest.php
Tests the Entity browser iframe display plugin.
PluginsTest::testModalDisplay in tests/src/FunctionalJavascript/PluginsTest.php
Tests Entity browser modal display plugin.
PluginsTest::testStandaloneDisplay in tests/src/FunctionalJavascript/PluginsTest.php
Tests Entity browser standalone display plugin.

File

tests/src/FunctionalJavascript/EntityBrowserWebDriverTestBase.php, line 123

Class

EntityBrowserWebDriverTestBase
Base class for Entity browser Javascript functional tests.

Namespace

Drupal\Tests\entity_browser\FunctionalJavascript

Code

protected function getEntityBrowser($browser_name, $display_id, $widget_selector_id, $selection_display_id, array $display_configuration = [], array $widget_selector_configuration = [], array $selection_display_configuration = [], array $widget_configurations = []) {

  /** @var \Drupal\Core\Entity\EntityStorageInterface $storage */
  $storage = $this->container
    ->get('entity_type.manager')
    ->getStorage('entity_browser');

  /** @var \Drupal\entity_browser\EntityBrowserInterface $browser */
  $browser = $storage
    ->load($browser_name) ?: $storage
    ->create([
    'name' => $browser_name,
  ]);
  $browser
    ->setDisplay($display_id);
  if ($display_configuration) {
    $browser
      ->getDisplay()
      ->setConfiguration($display_configuration);
  }
  $browser
    ->setWidgetSelector($widget_selector_id);
  if ($widget_selector_configuration) {
    $browser
      ->getSelectionDisplay()
      ->setConfiguration($widget_selector_configuration);
  }
  $browser
    ->setSelectionDisplay($selection_display_id);
  if ($selection_display_configuration) {
    $browser
      ->getSelectionDisplay()
      ->setConfiguration($selection_display_configuration);
  }

  // Apply custom widget configurations.
  if ($widget_configurations) {
    foreach ($widget_configurations as $widget_uuid => $widget_config) {
      $view_widget = $browser
        ->getWidget($widget_uuid);
      $view_widget
        ->setConfiguration(NestedArray::mergeDeep($view_widget
        ->getConfiguration(), $widget_config));
    }
  }
  $browser
    ->save();

  // Clear caches after new browser is saved to remove old cached states.
  drupal_flush_all_caches();
  return $browser;
}