View source
<?php
namespace Drupal\Tests\freelinking\Unit;
use Drupal\Core\Cache\NullBackend;
use Drupal\freelinking\FreelinkingManager;
use Drupal\Tests\UnitTestCase;
use Prophecy\PhpUnit\ProphecyTrait;
class FreelinkingManagerTest extends UnitTestCase {
use ProphecyTrait;
protected $pluginManager;
protected $language;
protected function setUp() : void {
$cacheBackend = new NullBackend('freelinking');
$moduleProphet = $this
->prophesize('\\Drupal\\Core\\Extension\\ModuleHandlerInterface');
$moduleHandler = $moduleProphet
->reveal();
$languageProphet = $this
->prophesize('\\Drupal\\Core\\Language\\LanguageInterface');
$this->language = $languageProphet
->reveal();
$languageManagerProphet = $this
->prophesize('\\Drupal\\Core\\Language\\LanguageManagerInterface');
$languageManagerProphet
->getLanguage('en')
->willReturn($this->language);
$languageManager = $languageManagerProphet
->reveal();
$namespaces = new \ArrayObject();
$this->pluginManager = new FreelinkingManager($namespaces, $cacheBackend, $moduleHandler, $languageManager);
}
public function testParseTarget(array $expected, $target) {
$expected['target'] = $target;
$expected['language'] = $this->language;
$this
->assertEquals($expected, $this->pluginManager
->parseTarget($target, 'en'));
}
public function parseTargetProvider() {
return [
[
[
'dest' => 'nid:2',
'text' => 'Special title',
'tooltip' => 'tooltip',
'other' => [],
],
'nid:2|Special title|tooltip',
],
[
[
'dest' => 'nid:2',
'text' => NULL,
'tooltip' => NULL,
'other' => [],
],
'nid:2',
],
[
[
'dest' => 'external:http://example.com?id=12345',
'text' => '1',
'tooltip' => NULL,
'other' => [],
],
'external:http://example.com?id=12345|1',
],
[
[
'dest' => 'external:http://example.com?id=12345&q=%E2%99%A5#fragment',
'text' => 'Title',
'tooltip' => 'Tooltip',
'arbitrary' => 'value',
'other' => [
'Other',
],
],
'external:http://example.com?id=12345&q=%E2%99%A5#fragment|Title|Tooltip|arbitrary=value|Other',
],
];
}
}