PluginBaseTest.php in Zircon Profile 8.0
File
core/modules/views/src/Tests/Plugin/PluginBaseTest.php
View source
<?php
namespace Drupal\views\Tests\Plugin;
use Drupal\Core\Render\RenderContext;
use Drupal\Core\Render\Markup;
use Drupal\simpletest\KernelTestBase;
use Drupal\views\Plugin\views\PluginBase;
class PluginBaseTest extends KernelTestBase {
var $testPluginBase;
public function setUp() {
parent::setUp();
$this->testPluginBase = new TestPluginBase();
}
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
->assertIdentical($result, 'en means English');
}
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
->assertIdentical($result, 'first comes before second');
}
public function testViewsTokenReplaceWithTwigTokens() {
$text = 'Just some text';
$tokens = [];
$result = $this->testPluginBase
->viewsTokenReplace($text, $tokens);
$this
->assertIdentical($result, 'Just some text');
}
}
class TestPluginBase extends PluginBase {
public function __construct() {
parent::__construct([], '', []);
}
public function viewsTokenReplace($text, $tokens) {
return parent::viewsTokenReplace($text, $tokens);
}
}