class PluginBaseTest in Drupal 10
Same name in this branch
- 10 core/tests/Drupal/Tests/Component/Plugin/PluginBaseTest.php \Drupal\Tests\Component\Plugin\PluginBaseTest
- 10 core/modules/views/tests/src/Unit/PluginBaseTest.php \Drupal\Tests\views\Unit\PluginBaseTest
- 10 core/modules/views/tests/src/Kernel/Plugin/PluginBaseTest.php \Drupal\Tests\views\Kernel\Plugin\PluginBaseTest
Same name and namespace in other branches
- 8 core/modules/views/tests/src/Kernel/Plugin/PluginBaseTest.php \Drupal\Tests\views\Kernel\Plugin\PluginBaseTest
- 9 core/modules/views/tests/src/Kernel/Plugin/PluginBaseTest.php \Drupal\Tests\views\Kernel\Plugin\PluginBaseTest
Tests the PluginBase class.
@group views
Hierarchy
- class \Drupal\Tests\views\Kernel\Plugin\PluginBaseTest extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of PluginBaseTest
File
- core/
modules/ views/ tests/ src/ Kernel/ Plugin/ PluginBaseTest.php, line 20 - Contains \Drupal\views\Tests\Plugin\PluginBaseTest.
Namespace
Drupal\Tests\views\Kernel\PluginView source
class PluginBaseTest extends KernelTestBase {
/**
* @var TestPluginBase
*/
protected $testPluginBase;
protected function setUp() : void {
parent::setUp();
$this->testPluginBase = new TestPluginBase();
}
/**
* Tests that the token replacement in views works correctly.
*/
public function testViewsTokenReplace() {
$text = '{{ langcode__value }} means {{ langcode }}';
$tokens = [
'{{ langcode }}' => Markup::create('English'),
'{{ langcode__value }}' => 'en',
];
$result = \Drupal::service('renderer')
->executeInRenderContext(new RenderContext(), function () use ($text, $tokens) {
return $this->testPluginBase
->viewsTokenReplace($text, $tokens);
});
$this
->assertSame('en means English', $result);
}
/**
* Tests that the token replacement in views works correctly with dots.
*/
public function testViewsTokenReplaceWithDots() {
$text = '{{ argument.first }} comes before {{ argument.second }}';
$tokens = [
'{{ argument.first }}' => 'first',
'{{ argument.second }}' => 'second',
];
$result = \Drupal::service('renderer')
->executeInRenderContext(new RenderContext(), function () use ($text, $tokens) {
return $this->testPluginBase
->viewsTokenReplace($text, $tokens);
});
$this
->assertSame('first comes before second', $result);
// Test tokens with numeric indexes.
$text = '{{ argument.0.first }} comes before {{ argument.1.second }}';
$tokens = [
'{{ argument.0.first }}' => 'first',
'{{ argument.1.second }}' => 'second',
];
$result = \Drupal::service('renderer')
->executeInRenderContext(new RenderContext(), function () use ($text, $tokens) {
return $this->testPluginBase
->viewsTokenReplace($text, $tokens);
});
$this
->assertSame('first comes before second', $result);
}
/**
* Tests viewsTokenReplace without any twig tokens.
*/
public function testViewsTokenReplaceWithTwigTokens() {
$text = 'Just some text';
$tokens = [];
$result = $this->testPluginBase
->viewsTokenReplace($text, $tokens);
$this
->assertSame('Just some text', $result);
}
}