function EntityLinkSuggestionTest::testEntityLinkSuggestions

Test the generated entity link suggestions based on editor configuration.

Attributes

#[DataProvider('providerEntityLinkSuggestions')]

File

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

Class

EntityLinkSuggestionTest
Tests entity link suggestions.

Namespace

Drupal\Tests\ckeditor5\Kernel

Code

public function testEntityLinkSuggestions(string $search, string $host_entity_type_id, string $host_entity_langcode, array $expected) : void {
  // Set the given configuration for the entity link suggestions plugin.
  $editor = Editor::load('test_format');
  // Whatever configuration it is, it must be valid.
  $this->assertExpectedCkeditor5Violations();
  $controller = EntityLinkSuggestionsController::create($this->container);
  $request = Request::create("/irrelevant-in-kernel-test");
  $request->query
    ->set('q', $search);
  $request->query
    ->set('hostEntityTypeId', $host_entity_type_id);
  $request->query
    ->set('hostEntityLangcode', $host_entity_langcode);
  $response = $controller->suggestions($request, $editor);
  $this->assertInstanceOf(JsonResponse::class, $response);
  $data = json_decode($response->getContent(), TRUE);
  // Perform assertions on the response data.
  $this->assertArrayHasKey('suggestions', $data);
  $this->assertIsArray($data['suggestions']);
  $this->assertSame($expected, $data['suggestions']);
}

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