class FreelinkingManagerTest in Freelinking 8.3
Same name and namespace in other branches
- 4.0.x tests/src/Unit/FreelinkingManagerTest.php \Drupal\Tests\freelinking\Unit\FreelinkingManagerTest
Tests the freelinking plugin manager.
@group freelinking
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\freelinking\Unit\FreelinkingManagerTest
Expanded class hierarchy of FreelinkingManagerTest
File
- tests/
src/ Unit/ FreelinkingManagerTest.php, line 14
Namespace
Drupal\Tests\freelinking\UnitView source
class FreelinkingManagerTest extends UnitTestCase {
/**
* Freelinking Manager object to run tests on.
*
* @var \Drupal\freelinking\FreelinkingManagerInterface
* The Freelinking Manager.
*/
protected $pluginManager;
/**
* Mock language object.
*
* @var \Drupal\Core\Language\LanguageInterface
* A language object.
*/
protected $language;
/**
* {@inheritdoc}
*/
protected function setUp() {
// Use a null cache backend to prevent caching.
$cacheBackend = new NullBackend('freelinking');
// Mock the module handler and language objects.
$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);
}
/**
* Tests parseTarget method.
*
* @param array $expected
* The expected destination string.
* @param string $target
* The target string.
*
* @dataProvider parseTargetProvider
*/
public function testParseTarget(array $expected, $target) {
$expected['target'] = $target;
$expected['language'] = $this->language;
$this
->assertEquals($expected, $this->pluginManager
->parseTarget($target, 'en'));
}
/**
* Provide test parameters and expected values for testParseTarget().
*
* @return array
* An array of test parameters and expected values.
*/
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',
],
];
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FreelinkingManagerTest:: |
protected | property | Mock language object. | |
FreelinkingManagerTest:: |
protected | property | Freelinking Manager object to run tests on. | |
FreelinkingManagerTest:: |
public | function | Provide test parameters and expected values for testParseTarget(). | |
FreelinkingManagerTest:: |
protected | function |
Overrides UnitTestCase:: |
|
FreelinkingManagerTest:: |
public | function | Tests parseTarget method. | |
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. |