class ContextualLinkDefaultTest in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/tests/Drupal/Tests/Core/Menu/ContextualLinkDefaultTest.php \Drupal\Tests\Core\Menu\ContextualLinkDefaultTest
@group Menu @coversDefaultClass \Drupal\Core\Menu\ContextualLinkDefault
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\Core\Menu\ContextualLinkDefaultTest
Expanded class hierarchy of ContextualLinkDefaultTest
File
- core/
tests/ Drupal/ Tests/ Core/ Menu/ ContextualLinkDefaultTest.php, line 19 - Contains \Drupal\Tests\Core\Menu\ContextualLinkDefaultTest.
Namespace
Drupal\Tests\Core\MenuView source
class ContextualLinkDefaultTest extends UnitTestCase {
/**
* The tested contextual link default plugin.
*
* @var \Drupal\Core\Menu\ContextualLinkDefault
*/
protected $contextualLinkDefault;
/**
* The used plugin configuration.
*
* @var array
*/
protected $config = array();
/**
* The used plugin ID.
*
* @var string
*/
protected $pluginId = 'contextual_link_default';
/**
* The used plugin definition.
*
* @var array
*/
protected $pluginDefinition = array(
'id' => 'contextual_link_default',
);
/**
* The mocked translator.
*
* @var \Drupal\Core\StringTranslation\TranslationInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $stringTranslation;
protected function setUp() {
parent::setUp();
$this->stringTranslation = $this
->getMock('Drupal\\Core\\StringTranslation\\TranslationInterface');
}
protected function setupContextualLinkDefault() {
$this->contextualLinkDefault = new ContextualLinkDefault($this->config, $this->pluginId, $this->pluginDefinition);
}
/**
* @covers ::getTitle
*/
public function testGetTitle() {
$title = 'Example';
$this->pluginDefinition['title'] = new TranslatableMarkup($title, [], [], $this->stringTranslation);
$this->stringTranslation
->expects($this
->once())
->method('translateString')
->with($this->pluginDefinition['title'])
->will($this
->returnValue('Example translated'));
$this
->setupContextualLinkDefault();
$this
->assertEquals('Example translated', $this->contextualLinkDefault
->getTitle());
}
/**
* @covers ::getTitle
*/
public function testGetTitleWithContext() {
$title = 'Example';
$this->pluginDefinition['title'] = new TranslatableMarkup($title, array(), array(
'context' => 'context',
), $this->stringTranslation);
$this->stringTranslation
->expects($this
->once())
->method('translateString')
->with($this->pluginDefinition['title'])
->will($this
->returnValue('Example translated with context'));
$this
->setupContextualLinkDefault();
$this
->assertEquals('Example translated with context', $this->contextualLinkDefault
->getTitle());
}
/**
* @covers ::getTitle
*/
public function testGetTitleWithTitleArguments() {
$title = 'Example @test';
$this->pluginDefinition['title'] = new TranslatableMarkup($title, array(
'@test' => 'value',
), [], $this->stringTranslation);
$this->stringTranslation
->expects($this
->once())
->method('translateString')
->with($this->pluginDefinition['title'])
->will($this
->returnValue('Example value'));
$this
->setupContextualLinkDefault();
$request = new Request();
$this
->assertEquals('Example value', $this->contextualLinkDefault
->getTitle($request));
}
/**
* @covers ::getRouteName
*/
public function testGetRouteName($route_name = 'test_route_name') {
$this->pluginDefinition['route_name'] = $route_name;
$this
->setupContextualLinkDefault();
$this
->assertEquals($route_name, $this->contextualLinkDefault
->getRouteName());
}
/**
* @covers ::getGroup
*/
public function testGetGroup($group_name = 'test_group') {
$this->pluginDefinition['group'] = $group_name;
$this
->setupContextualLinkDefault();
$this
->assertEquals($group_name, $this->contextualLinkDefault
->getGroup());
}
/**
* @covers ::getOptions
*/
public function testGetOptions($options = array(
'key' => 'value',
)) {
$this->pluginDefinition['options'] = $options;
$this
->setupContextualLinkDefault();
$this
->assertEquals($options, $this->contextualLinkDefault
->getOptions());
}
/**
* @covers ::getWeight
*/
public function testGetWeight($weight = 5) {
$this->pluginDefinition['weight'] = $weight;
$this
->setupContextualLinkDefault();
$this
->assertEquals($weight, $this->contextualLinkDefault
->getWeight());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ContextualLinkDefaultTest:: |
protected | property | The used plugin configuration. | |
ContextualLinkDefaultTest:: |
protected | property | The tested contextual link default plugin. | |
ContextualLinkDefaultTest:: |
protected | property | The used plugin definition. | |
ContextualLinkDefaultTest:: |
protected | property | The used plugin ID. | |
ContextualLinkDefaultTest:: |
protected | property | The mocked translator. | |
ContextualLinkDefaultTest:: |
protected | function |
Overrides UnitTestCase:: |
|
ContextualLinkDefaultTest:: |
protected | function | ||
ContextualLinkDefaultTest:: |
public | function | @covers ::getGroup | |
ContextualLinkDefaultTest:: |
public | function | @covers ::getOptions | |
ContextualLinkDefaultTest:: |
public | function | @covers ::getRouteName | |
ContextualLinkDefaultTest:: |
public | function | @covers ::getTitle | |
ContextualLinkDefaultTest:: |
public | function | @covers ::getTitle | |
ContextualLinkDefaultTest:: |
public | function | @covers ::getTitle | |
ContextualLinkDefaultTest:: |
public | function | @covers ::getWeight | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed in 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. |