You are here

protected function LinkitDialogTest::setUp in Linkit 8.5

Overrides BrowserTestBase::setUp

File

tests/src/FunctionalJavascript/LinkitDialogTest.php, line 61

Class

LinkitDialogTest
Tests the linkit alterations on the drupallink plugin.

Namespace

Drupal\Tests\linkit\FunctionalJavascript

Code

protected function setUp() {
  parent::setUp();
  $matcherManager = $this->container
    ->get('plugin.manager.linkit.matcher');

  /** @var \Drupal\linkit\MatcherInterface $plugin */
  $this->linkitProfile = $this
    ->createProfile();
  $plugin = $matcherManager
    ->createInstance('entity:entity_test_mul');
  $this->linkitProfile
    ->addMatcher($plugin
    ->getConfiguration());
  $this->linkitProfile
    ->save();

  // Create text format, associate CKEditor.
  $llama_format = FilterFormat::create([
    'format' => 'llama',
    'name' => 'Llama',
    'weight' => 0,
    'filters' => [],
  ]);
  $llama_format
    ->save();
  $editor = Editor::create([
    'format' => 'llama',
    'editor' => 'ckeditor',
  ]);
  $editor
    ->save();

  // Create "CKEditor" text editor plugin instance.
  $this->ckeditor = $this->container
    ->get('plugin.manager.editor')
    ->createInstance('ckeditor');

  // Create a node type for testing.
  NodeType::create([
    'type' => 'page',
    'name' => 'page',
  ])
    ->save();

  // Create a body field instance for the 'page' node type.
  FieldConfig::create([
    'field_storage' => FieldStorageConfig::loadByName('node', 'body'),
    'bundle' => 'page',
    'label' => 'Body',
    'settings' => [
      'display_summary' => TRUE,
    ],
    'required' => TRUE,
  ])
    ->save();

  // Assign widget settings for the 'default' form mode.
  EntityFormDisplay::create([
    'targetEntityType' => 'node',
    'bundle' => 'page',
    'mode' => 'default',
    'status' => TRUE,
  ])
    ->setComponent('body', [
    'type' => 'text_textarea_with_summary',
  ])
    ->save();

  // Customize the configuration.
  $this->container
    ->get('plugin.manager.editor')
    ->clearCachedDefinitions();
  $this->ckeditor = $this->container
    ->get('plugin.manager.editor')
    ->createInstance('ckeditor');
  $this->container
    ->get('plugin.manager.ckeditor.plugin')
    ->clearCachedDefinitions();
  $settings = $editor
    ->getSettings();
  $settings['plugins']['drupallink']['linkit_enabled'] = TRUE;
  $settings['plugins']['drupallink']['linkit_profile'] = $this->linkitProfile
    ->id();
  $editor
    ->setSettings($settings);
  $editor
    ->save();
  $account = $this
    ->drupalCreateUser([
    'administer nodes',
    'create page content',
    'edit own page content',
    'use text format llama',
    'view test entity',
  ]);
  $this
    ->drupalLogin($account);
}