function EntityLinkSuggestionTest::setUp

Overrides KernelTestBase::setUp

File

core/modules/ckeditor5/tests/src/Kernel/EntityLinkSuggestionTest.php, line 60

Class

EntityLinkSuggestionTest
Tests entity link suggestions.

Namespace

Drupal\Tests\ckeditor5\Kernel

Code

protected function setUp() : void {
  parent::setUp();
  $this->installConfig([
    'system',
  ]);
  // Avoid needing to install the Stark theme.
  $this->config('system.theme')
    ->delete();
  // Create text format, associate CKEditor 5, validate.
  FilterFormat::create([
    'format' => 'test_format',
    'name' => 'Test format',
    'filters' => [
      'filter_html' => [
        'status' => TRUE,
        'settings' => [
          'allowed_html' => '<p> <br> <a href data-entity-type data-entity-uuid data-entity-metadata>',
        ],
      ],
      'entity_links' => [
        'status' => TRUE,
      ],
    ],
  ])->save();
  Editor::create([
    'format' => 'test_format',
    'editor' => 'ckeditor5',
    'image_upload' => [
      'status' => FALSE,
    ],
    'settings' => [
      'toolbar' => [
        'items' => [
          'link',
        ],
      ],
    ],
  ])->save();
  $this->assertExpectedCkeditor5Violations();
  // Create a node type for testing.
  $node_page_type = NodeType::create([
    'type' => 'page',
    'name' => 'Basic page',
  ]);
  $node_page_type->save();
  $node_article_type = NodeType::create([
    'type' => 'article',
    'name' => 'Article',
  ]);
  $node_article_type->save();
  $this->installEntitySchema('user');
  $this->installEntitySchema('node');
  $this->installEntitySchema('date_format');
  $this->installSchema('node', [
    'node_access',
  ]);
  $this->container
    ->get('content_translation.manager')
    ->setEnabled('node', $node_page_type->id(), TRUE);
  $this->container
    ->get('content_translation.manager')
    ->setEnabled('node', $node_article_type->id(), TRUE);
  $this->installEntitySchema('taxonomy_vocabulary');
  $this->installEntitySchema('taxonomy_term');
  $vocabulary = Vocabulary::create([
    'name' => 'Tags',
    'vid' => 'tags',
  ]);
  $vocabulary->save();
  // Create an account with "f" in the username.
  $user = User::create([
    'name' => 'sofie',
    'uuid' => '966e5967-f19c-44b0-87b1-697441385b08',
    'created' => '694702320',
  ]);
  $user->addRole('create page content');
  $user->addRole('use text format test_format');
  $user->activate()
    ->save();
  $this->container
    ->get('current_user')
    ->setAccount($user);
  // Create the translation language.
  $this->installConfig([
    'language',
  ]);
  ConfigurableLanguage::createFromLangcode('de')->save();
  // Load the test node entity.
  $nodePage = Node::create([
    'type' => 'page',
    'title' => 'foo',
    'uuid' => '36c25329-6c3b-452e-82fa-e20c502f69ed',
  ]);
  $nodePage->setCreatedTime(1695058272);
  $nodePage->save();
  $translation = $nodePage->addTranslation('de', [
    'title' => 'Deutsch foo',
  ])
    ->setCreatedTime(1695058272);
  $translation->save();
  $nodeArticle = Node::create([
    'type' => 'article',
    'title' => 'doo',
    'uuid' => '36c25329-6c3b-452e-82fa-e20c502f69ef',
  ]);
  $nodeArticle->setCreatedTime(1695058372);
  $nodeArticle->save();
  $nodeArticleTranslation = $nodeArticle->addTranslation('de', [
    'title' => 'Deutsch doo',
  ])
    ->setCreatedTime(1695058372);
  $nodeArticleTranslation->save();
  $term = Term::create([
    'vid' => $vocabulary->id(),
    'name' => 'tag',
    'uuid' => '966e5967-f19c-44b0-87b1-697441385b10',
  ]);
  $term->save();
  $termTranslation = $term->addTranslation('de', [
    'name' => 'tag DE',
  ]);
  $termTranslation->save();
  $term2 = Term::create([
    'vid' => $vocabulary->id(),
    'name' => 'doo term',
    'uuid' => '966e5967-f19c-44b0-87b1-697441385b11',
  ]);
  $term2->save();
  $termTranslation2 = $term2->addTranslation('de', [
    'name' => 'doo term DE',
  ]);
  $termTranslation2->save();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.