class FreelinkingTest in Freelinking 8.3
Same name and namespace in other branches
- 4.0.x tests/src/Unit/Plugin/Filter/FreelinkingTest.php \Drupal\Tests\freelinking\Unit\Plugin\Filter\FreelinkingTest
Tests the freelinking plugin.
@group freelinking
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\freelinking\Unit\Plugin\Filter\FreelinkingTest
Expanded class hierarchy of FreelinkingTest
File
- tests/
src/ Unit/ Plugin/ Filter/ FreelinkingTest.php, line 17
Namespace
Drupal\Tests\freelinking\Unit\Plugin\FilterView source
class FreelinkingTest extends UnitTestCase {
/**
* Freelinking filter plugin.
*
* @var \Drupal\freelinking\Plugin\Filter\Freelinking
*/
protected $filter;
/**
* Translation interface mock.
*
* @var \Drupal\Core\StringTranslation\TranslationInterface
*/
protected $translationInterfaceMock;
/**
* {@inheritdoc}
*/
protected function setUp() {
// Mock string translation service.
$tProphet = $this
->prophesize('\\Drupal\\Core\\StringTranslation\\TranslationInterface');
$tProphet
->translateString(Argument::type('string'))
->will(function ($args) {
return $args[0];
});
$this->translationInterfaceMock = $tProphet
->reveal();
// Create a freelinking plugin mock.
$pluginProphet = $this
->prophesize('\\Drupal\\freelinking\\Plugin\\FreelinkingPluginInterface');
$pluginProphet
->getPluginDefinition()
->willReturn([
'title' => 'Dummy',
]);
$pluginProphet
->getIndicator()
->willReturn('indicator');
$pluginProphet
->getTip()
->willReturn('tip');
$mockPlugin = $pluginProphet
->reveal();
// Create a mock of the freelinking plugin manager.
$managerProphet = $this
->prophesize('\\Drupal\\freelinking\\FreelinkingManagerInterface');
$managerProphet
->createInstance(Argument::type('string'), Argument::type('array'))
->willReturn($mockPlugin);
// Create a mock of the current user.
$userProphet = $this
->prophesize('\\Drupal\\Core\\Session\\AccountProxyInterface');
$container = new ContainerBuilder();
$container
->set('string_translation', $this->translationInterfaceMock);
$container
->set('freelinking.manager', $managerProphet
->reveal());
$container
->set('current_user', $userProphet
->reveal());
\Drupal::setContainer($container);
$definition = [
'id' => 'freelinking',
'title' => 'Freelinking',
'description' => 'Allowms for a flexible format for linking content.',
'type' => FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
'provider' => 'freelinking',
'status' => FALSE,
'settings' => [
'default' => 'nodetitle',
'global_options' => [
'ignore_upi' => FALSE,
],
'plugins' => [],
'external_http_request' => FALSE,
],
'weight' => 0,
];
$configuration = [
'settings' => [
'plugins' => [
'dummy' => [
'plugin' => 'dummy',
'enabled' => TRUE,
],
],
],
'weight' => 0,
'status' => TRUE,
];
$this->filter = new Freelinking($configuration, 'freelinking', $definition, $container
->get('freelinking.manager'), $container
->get('current_user'));
}
/**
* Asserts that a short tip is returned.
*/
public function testShortTip() {
$expected = new TranslatableMarkup('Freelinking helps you easily create HTML links. Links take the form of <code>[[indicator:target|Title]].</code>', [], [], $this->translationInterfaceMock);
$this
->assertEquals($expected, $this->filter
->tips());
}
/**
* Asserts that a long tip is returned.
*/
public function testLongTip() {
$expectedText = <<<EOF
<p>Freelinking helps you easily create HTML links. Links take the form of <code>[[indicator:target|Title]].</code><br />
Below is a list of available types of freelinks you may use, organized as <strong>Plugin Name</strong>: [<em>indicator</em>].</p>
<ul><li><strong>Dummy</strong> [<em>indicator</em>]: tip</li></ul>
EOF;
$expected = new TranslatableMarkup($expectedText, [], [], $this->translationInterfaceMock);
$this
->assertEquals($expected, $this->filter
->tips(TRUE));
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FreelinkingTest:: |
protected | property | Freelinking filter plugin. | |
FreelinkingTest:: |
protected | property | Translation interface mock. | |
FreelinkingTest:: |
protected | function |
Overrides UnitTestCase:: |
|
FreelinkingTest:: |
public | function | Asserts that a long tip is returned. | |
FreelinkingTest:: |
public | function | Asserts that a short tip is returned. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |