You are here

protected function QuickEditIntegrationTest::setUp in Drupal 8

Same name in this branch
  1. 8 core/modules/quickedit/tests/src/FunctionalJavascript/QuickEditIntegrationTest.php \Drupal\Tests\quickedit\FunctionalJavascript\QuickEditIntegrationTest::setUp()
  2. 8 core/modules/settings_tray/tests/src/FunctionalJavascript/QuickEditIntegrationTest.php \Drupal\Tests\settings_tray\FunctionalJavascript\QuickEditIntegrationTest::setUp()
  3. 8 core/modules/editor/tests/src/Kernel/QuickEditIntegrationTest.php \Drupal\Tests\editor\Kernel\QuickEditIntegrationTest::setUp()
Same name and namespace in other branches
  1. 9 core/modules/quickedit/tests/src/FunctionalJavascript/QuickEditIntegrationTest.php \Drupal\Tests\quickedit\FunctionalJavascript\QuickEditIntegrationTest::setUp()

Overrides BrowserTestBase::setUp

File

core/modules/quickedit/tests/src/FunctionalJavascript/QuickEditIntegrationTest.php, line 49

Class

QuickEditIntegrationTest
@group quickedit

Namespace

Drupal\Tests\quickedit\FunctionalJavascript

Code

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

  // Create text format, associate CKEditor.
  FilterFormat::create([
    'format' => 'some_format',
    'name' => 'Some format',
    'weight' => 0,
    'filters' => [
      'filter_html' => [
        'status' => 1,
        'settings' => [
          'allowed_html' => '<h2 id> <h3> <h4> <h5> <h6> <p> <br> <strong> <a href hreflang>',
        ],
      ],
    ],
  ])
    ->save();
  Editor::create([
    'format' => 'some_format',
    'editor' => 'ckeditor',
  ])
    ->save();

  // Create the Article node type.
  $this
    ->drupalCreateContentType([
    'type' => 'article',
    'name' => 'Article',
  ]);

  // Add "tags" vocabulary + field to the Article node type.
  $vocabulary = Vocabulary::create([
    'name' => 'Tags',
    'vid' => 'tags',
  ]);
  $vocabulary
    ->save();
  $field_name = 'field_' . $vocabulary
    ->id();
  $handler_settings = [
    'target_bundles' => [
      $vocabulary
        ->id() => $vocabulary
        ->id(),
    ],
    'auto_create' => TRUE,
  ];
  $this
    ->createEntityReferenceField('node', 'article', $field_name, 'Tags', 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);

  // Add formatter & widget for "tags" field.
  \Drupal::entityTypeManager()
    ->getStorage('entity_form_display')
    ->load('node.article.default')
    ->setComponent($field_name, [
    'type' => 'entity_reference_autocomplete_tags',
  ])
    ->save();
  \Drupal::entityTypeManager()
    ->getStorage('entity_view_display')
    ->load('node.article.default')
    ->setComponent($field_name, [
    'type' => 'entity_reference_label',
  ])
    ->save();
  $this
    ->drupalPlaceBlock('page_title_block');
  $this
    ->drupalPlaceBlock('system_main_block');

  // Log in as a content author who can use Quick Edit and edit Articles.
  $this->contentAuthorUser = $this
    ->drupalCreateUser([
    'access contextual links',
    'access toolbar',
    'access in-place editing',
    'access content',
    'create article content',
    'edit any article content',
    'use text format some_format',
    'edit terms in tags',
    'administer blocks',
  ]);
  $this
    ->drupalLogin($this->contentAuthorUser);
}