class ShortcutEntityLinksTest
Same name and namespace in other branches
- 11.x core/modules/shortcut/tests/src/Kernel/ShortcutEntityLinksTest.php \Drupal\Tests\shortcut\Kernel\ShortcutEntityLinksTest
Tests the entity_links filter with shortcut entities.
Attributes
#[Group('shortcut')]
#[CoversClass(EntityLinks::class)]
#[RunTestsInSeparateProcesses]
Hierarchy
- class \Drupal\KernelTests\KernelTestBase implements \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\Tests\DrupalTestCaseTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\shortcut\Kernel\ShortcutEntityLinksTest extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of ShortcutEntityLinksTest
File
-
core/
modules/ shortcut/ tests/ src/ Kernel/ ShortcutEntityLinksTest.php, line 21
Namespace
Drupal\Tests\shortcut\KernelView source
class ShortcutEntityLinksTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'filter',
'shortcut',
'link',
'user',
'system',
];
/**
* The entity_links filter.
*
* @var \Drupal\filter\Plugin\Filter\EntityLinks
*/
protected EntityLinks $filter;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->installConfig('system');
$this->installEntitySchema('user');
$this->installEntitySchema('shortcut');
$this->installConfig([
'shortcut',
]);
/** @var \Drupal\Component\Plugin\PluginManagerInterface $manager */
$manager = $this->container
->get('plugin.manager.filter');
$bag = new FilterPluginCollection($manager, []);
$this->filter = $bag->get('entity_links');
}
/**
* @legacy-covers ::getUrl
* @legacy-covers \Drupal\shortcut\Entity\ShortcutLinkTarget
*/
public function testShortcutEntity() : void {
// cspell:disable-next-line
$path = '/user/logout?token=fzL0Ox4jS6qafdt6gzGzjWGb_hsR6kJ8L8E0D4hC5Mo';
$shortcut = Shortcut::create([
'shortcut_set' => 'default',
'title' => 'Comments',
'weight' => -20,
'link' => [
'uri' => "internal:{$path}",
],
]);
$shortcut->save();
$result = $this->filter
->process(sprintf('<a data-entity-type="shortcut" data-entity-uuid="%s" href="something?query=string#fragment">Link text</a>', $shortcut->uuid()), 'en');
$expected_result = (new FilterProcessResult())->setProcessedText(sprintf('<a href="%s?query=string#fragment">Link text</a>', $path))
->setCacheTags([
'config:shortcut.set.default',
])
->setCacheContexts([])
->setCacheMaxAge(Cache::PERMANENT);
$this->assertSame($expected_result->getProcessedText(), $result->getProcessedText());
$this->assertEquals(CacheableMetadata::createFromObject($expected_result), CacheableMetadata::createFromObject($result));
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.