You are here

protected function DrupalNbspTest::setUp in CKEditor Non-breaking space Plugin ( ) 8

Same name and namespace in other branches
  1. 8.2 tests/src/FunctionalJavascript/DrupalNbspTest.php \Drupal\Tests\nbsp\FunctionalJavascript\DrupalNbspTest::setUp()

Overrides BrowserTestBase::setUp

File

tests/src/FunctionalJavascript/DrupalNbspTest.php, line 69

Class

DrupalNbspTest
Ensure the NBSP CKeditor dialog works.

Namespace

Drupal\Tests\nbsp\FunctionalJavascript

Code

protected function setUp() {
  parent::setUp();

  // Create text format.
  $this->editorFilterFormat = FilterFormat::create([
    'format' => 'full_html',
    'name' => 'Full HTML',
    'weight' => 0,
    'filters' => [],
  ]);
  $this->editorFilterFormat
    ->save();
  $this->editor = Editor::create([
    'format' => 'full_html',
    'editor' => 'ckeditor',
  ]);
  $settings = [
    'toolbar' => [
      'rows' => [
        [
          [
            'name' => 'All the things',
            'items' => [
              'Source',
              'Bold',
              'Italic',
              'DrupalNbsp',
            ],
          ],
        ],
      ],
    ],
    'plugins' => [],
  ];
  $this->editor
    ->setSettings($settings);
  $this->editor
    ->save();

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

  // Create a body field instance for the 'page' node type.
  FieldConfig::create([
    'field_storage' => $field_storage,
    '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();

  // Create a user for tests.
  $this->adminUser = $this
    ->drupalCreateUser([
    'administer nodes',
    'create page content',
    'use text format full_html',
  ]);
  $this
    ->drupalLogin($this->adminUser);
}