protected function FreelinkingTest::setUp in Freelinking 4.0.x
Same name and namespace in other branches
- 8.3 tests/src/Unit/Plugin/Filter/FreelinkingTest.php \Drupal\Tests\freelinking\Unit\Plugin\Filter\FreelinkingTest::setUp()
Overrides UnitTestCase::setUp
File
- tests/
src/ Unit/ Plugin/ Filter/ FreelinkingTest.php, line 39
Class
- FreelinkingTest
- Tests the freelinking plugin.
Namespace
Drupal\Tests\freelinking\Unit\Plugin\FilterCode
protected function setUp() : void {
// 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'));
}