View source
<?php
namespace Drupal\Tests\freelinking\Unit\Plugin\freelinking;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\freelinking\Plugin\freelinking\Builtin;
use Drupal\Tests\UnitTestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
class BuiltinTest extends UnitTestCase {
use ProphecyTrait;
protected $translationInterfaceMock;
protected $configuration = [
'settings' => [],
];
protected $id = 'builtin';
protected $definition = [
'id' => 'builtin',
'title' => 'Built-in',
'weight' => -1,
'hidden' => TRUE,
'settings' => [],
];
protected function setUp() : void {
$tProphet = $this
->prophesize('\\Drupal\\Core\\StringTranslation\\TranslationInterface');
$tProphet
->translateString(Argument::any())
->willReturn('Redact, show text only, or display the indicator');
$this->translationInterfaceMock = $tProphet
->reveal();
$container = new ContainerBuilder();
$container
->set('string_translation', $tProphet
->reveal());
\Drupal::setContainer($container);
}
public function testGetTip() {
$accountProphet = $this
->prophesize('\\Drupal\\Core\\Session\\AccountProxyInterface');
$plugin = new Builtin($this->configuration, $this->id, $this->definition, $accountProphet
->reveal());
$this
->assertEquals('Redact, show text only, or display the indicator', $plugin
->getTip()
->render());
}
public function testGetIndicator($indicator, $expected) {
$accountProphet = $this
->prophesize('\\Drupal\\Core\\Session\\AccountProxyInterface');
$plugin = new Builtin($this->configuration, $this->id, $this->definition, $accountProphet
->reveal());
$this
->assertEquals($expected, preg_match($plugin
->getIndicator(), $indicator));
}
public function testBuildLink($indicator, $dest, $isAuthenticated, $text) {
$accountProphet = $this
->prophesize('\\Drupal\\Core\\Session\\AccountProxyInterface');
$accountProphet
->isAuthenticated()
->willReturn($isAuthenticated);
$target = [
'indicator' => $indicator,
'target' => '[[' . $indicator . '|' . $dest . ']]',
'dest' => $dest,
'text' => NULL,
];
$expected = [
'#markup' => $text,
];
$plugin = new Builtin($this->configuration, $this->id, $this->definition, $accountProphet
->reveal());
$this
->assertEquals($expected, $plugin
->buildLink($target));
}
public function testIsHidden() {
$accountProphet = $this
->prophesize('\\Drupal\\Core\\Session\\AccountProxyInterface');
$plugin = new Builtin($this->configuration, $this->id, $this->definition, $accountProphet
->reveal());
$this
->assertTrue($plugin
->isHidden());
}
public function buildLinkProvider() {
return [
[
'showtext',
'Show Text',
FALSE,
'Show Text',
],
[
'redact',
'Non Redacted',
FALSE,
'******',
],
[
'redact',
'Non Redacted',
TRUE,
'Non Redacted',
],
[
'nowiki',
'No Wiki',
FALSE,
'[[No Wiki]]',
],
];
}
public function getIndicatorProvider() {
return [
[
'nomatch',
0,
],
[
'showtext',
1,
],
[
'nowiki',
1,
],
[
'redact',
1,
],
];
}
}