class WikiTest in Freelinking 8.3
Same name and namespace in other branches
- 4.0.x tests/src/Unit/Plugin/freelinking/WikiTest.php \Drupal\Tests\freelinking\Unit\Plugin\freelinking\WikiTest
Test the freelinking wiki plugin.
@group freelinking
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\freelinking\Unit\Plugin\freelinking\WikiTest
Expanded class hierarchy of WikiTest
File
- tests/
src/ Unit/ Plugin/ freelinking/ WikiTest.php, line 18
Namespace
Drupal\Tests\freelinking\Unit\Plugin\freelinkingView source
class WikiTest extends UnitTestCase {
/**
* The translation interface.
*
* @var \Drupal\Core\StringTranslation\TranslationInterface
*/
protected $translationInterfaceMock;
/**
* The dependency injection container.
*
* @var \Symfony\Component\DependencyInjection\ContainerInterface
*/
protected $container;
/**
* {@inheritdoc}
*/
protected function setUp() {
// Mock the translation interface.
$tProphet = $this
->prophesize('\\Drupal\\Core\\StringTranslation\\TranslationInterface');
$tProphet
->translateString(Argument::any())
->willReturn('Click to view a wiki page.');
$this->translationInterfaceMock = $tProphet
->reveal();
$this->container = new ContainerBuilder();
$this->container
->set('string_translation', $this->translationInterfaceMock);
\Drupal::setContainer($this->container);
}
/**
* Asserts that getTip is functional.
*/
public function testGetTip() {
$plugin = $this
->getPlugin();
$this
->assertEquals('Click to view a wiki page.', $plugin
->getTip()
->render());
}
/**
* Asserts that getIndicator is functional.
*
* @param string $indicator
* The indicator string.
* @param int $expected
* The expected output from preg_match().
*
* @dataProvider indicatorProvider
*/
public function testGetIndicator($indicator, $expected) {
$plugin = $this
->getPlugin();
$this
->assertEquals($expected, preg_match($plugin
->getIndicator(), $indicator));
}
/**
* Asserts that buildLink is functional.
*
* @param string $indicator
* The wiki to test.
* @param string $destination
* The destination string.
* @param string $langcode
* The language code to test.
* @param string $expectedUrl
* The expected URL.
*
* @dataProvider buildLinkProvider
*/
public function testBuildLink($indicator, $destination, $langcode, $expectedUrl) {
$language = new Language([
'id' => $langcode,
]);
$expected = [
'#type' => 'link',
'#title' => 'Test Wiki',
'#url' => Url::fromUri($expectedUrl, [
'language' => $language,
'absolute' => TRUE,
]),
'#attributes' => [
'title' => new TranslatableMarkup('Click to view a wiki page.', [], [], $this->translationInterfaceMock),
],
];
$target = [
'indicator' => $indicator,
'text' => 'Test Wiki',
'target' => $indicator . ':' . $destination,
'dest' => $destination,
'language' => $language,
];
$plugin = $this
->getPlugin();
$this
->assertEquals($expected, $plugin
->buildLink($target));
}
/**
* Provide test parameters for ::testGetIndicator().
*
* @return array
* An array of test parameters.
*/
public function indicatorProvider() {
return [
[
'wikipedia',
1,
],
[
'wp',
1,
],
[
'wikiquote',
1,
],
[
'wq',
1,
],
[
'wiktionary',
1,
],
[
'wt',
1,
],
[
'wikinews',
1,
],
[
'wn',
1,
],
[
'wikisource',
1,
],
[
'ws',
1,
],
[
'wikibooks',
1,
],
[
'wb',
1,
],
];
}
/**
* Provide test parameters for ::testBuildLink().
*
* @return array
* An array of test parameters.
*/
public function buildLinkProvider() {
return [
[
'wikipedia',
'Main_Page',
'en',
'https://en.wikipedia.org/wiki/Main_Page',
],
[
'wikipedia',
'Portada',
'es',
'https://es.wikipedia.org/wiki/Portada',
],
[
'wp',
'Main_Page',
'en',
'https://en.wikipedia.org/wiki/Main_Page',
],
[
'wikiquote',
'Main_Page',
'en',
'https://en.wikiquote.org/wiki/Main_Page',
],
[
'wikiquote',
'Portada',
'es',
'https://es.wikiquote.org/wiki/Portada',
],
[
'wq',
'Main_Page',
'en',
'https://en.wikiquote.org/wiki/Main_Page',
],
[
'wiktionary',
'Main_Page',
'en',
'https://en.wiktionary.org/wiki/Main_Page',
],
[
'wiktionary',
'Portada',
'es',
'https://es.wiktionary.org/wiki/Portada',
],
[
'wt',
'Main_Page',
'en',
'https://en.wiktionary.org/wiki/Main_Page',
],
[
'wikisource',
'Main_Page',
'en',
'https://en.wikisource.org/wiki/Main_Page',
],
[
'wikisource',
'Portada',
'es',
'https://es.wikisource.org/wiki/Portada',
],
[
'ws',
'Main_Page',
'en',
'https://en.wikisource.org/wiki/Main_Page',
],
[
'wikinews',
'Main_Page',
'en',
'https://en.wikinews.org/wiki/Main_Page',
],
[
'wikinews',
'Portada',
'es',
'https://es.wikinews.org/wiki/Portada',
],
[
'wn',
'Main_Page',
'en',
'https://en.wikinews.org/wiki/Main_Page',
],
[
'wikibooks',
'Main_Page',
'en',
'https://en.wikibooks.org/wiki/Main_Page',
],
[
'wikibooks',
'Portada',
'es',
'https://es.wikibooks.org/wiki/Portada',
],
[
'wb',
'Main_Page',
'en',
'https://en.wikibooks.org/wiki/Main_Page',
],
];
}
/**
* Get the plugin instance.
*
* @return \Drupal\freelinking\Plugin\freelinking\Wiki
* The wiki plugin.
*/
protected function getPlugin() {
$definition = [
'id' => 'wiki',
'title' => 'Wiki',
'hidden' => FALSE,
'weight' => 0,
'settings' => [],
];
return new Wiki([], 'wiki', $definition);
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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. | |
WikiTest:: |
protected | property | The dependency injection container. | |
WikiTest:: |
protected | property | The translation interface. | |
WikiTest:: |
public | function | Provide test parameters for ::testBuildLink(). | |
WikiTest:: |
protected | function | Get the plugin instance. | |
WikiTest:: |
public | function | Provide test parameters for ::testGetIndicator(). | |
WikiTest:: |
protected | function |
Overrides UnitTestCase:: |
|
WikiTest:: |
public | function | Asserts that buildLink is functional. | |
WikiTest:: |
public | function | Asserts that getIndicator is functional. | |
WikiTest:: |
public | function | Asserts that getTip is functional. |