class LocalActionDefaultTest in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/tests/Drupal/Tests/Core/Menu/LocalActionDefaultTest.php \Drupal\Tests\Core\Menu\LocalActionDefaultTest
@coversDefaultClass \Drupal\Core\Menu\LocalActionDefault @group Menu
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\Core\Menu\LocalActionDefaultTest
Expanded class hierarchy of LocalActionDefaultTest
File
- core/
tests/ Drupal/ Tests/ Core/ Menu/ LocalActionDefaultTest.php, line 19 - Contains \Drupal\Tests\Core\Menu\LocalActionDefaultTest.
Namespace
Drupal\Tests\Core\MenuView source
class LocalActionDefaultTest extends UnitTestCase {
/**
* The tested local action default plugin.
*
* @var \Drupal\Core\Menu\LocalActionDefault
*/
protected $localActionDefault;
/**
* The used plugin configuration.
*
* @var array
*/
protected $config = array();
/**
* The used plugin ID.
*
* @var string
*/
protected $pluginId = 'local_action_default';
/**
* The used plugin definition.
*
* @var array
*/
protected $pluginDefinition = array(
'id' => 'local_action_default',
);
/**
* The mocked translator.
*
* @var \Drupal\Core\StringTranslation\TranslationInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $stringTranslation;
/**
* The mocked route provider.
*
* @var \Drupal\Core\Routing\RouteProviderInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $routeProvider;
protected function setUp() {
parent::setUp();
$this->stringTranslation = $this
->getMock('Drupal\\Core\\StringTranslation\\TranslationInterface');
$this->routeProvider = $this
->getMock('Drupal\\Core\\Routing\\RouteProviderInterface');
}
/**
* Setups the local action default.
*/
protected function setupLocalActionDefault() {
$this->localActionDefault = new LocalActionDefault($this->config, $this->pluginId, $this->pluginDefinition, $this->routeProvider);
}
/**
* Tests the getTitle method without a translation context.
*
* @see \Drupal\Core\Menu\LocalTaskDefault::getTitle()
*/
public function testGetTitle() {
$this->pluginDefinition['title'] = new TranslatableMarkup('Example', [], [], $this->stringTranslation);
$this->stringTranslation
->expects($this
->once())
->method('translateString')
->with($this->pluginDefinition['title'])
->will($this
->returnValue('Example translated'));
$this
->setupLocalActionDefault();
$this
->assertEquals('Example translated', $this->localActionDefault
->getTitle());
}
/**
* Tests the getTitle method with a translation context.
*
* @see \Drupal\Core\Menu\LocalTaskDefault::getTitle()
*/
public function testGetTitleWithContext() {
$this->pluginDefinition['title'] = new TranslatableMarkup('Example', 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
->setupLocalActionDefault();
$this
->assertEquals('Example translated with context', $this->localActionDefault
->getTitle());
}
/**
* Tests the getTitle method with title arguments.
*/
public function testGetTitleWithTitleArguments() {
$this->pluginDefinition['title'] = new TranslatableMarkup('Example @test', array(
'@test' => 'value',
), [], $this->stringTranslation);
$this->stringTranslation
->expects($this
->once())
->method('translateString')
->with($this->pluginDefinition['title'])
->will($this
->returnValue('Example value'));
$this
->setupLocalActionDefault();
$request = new Request();
$this
->assertEquals('Example value', $this->localActionDefault
->getTitle($request));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LocalActionDefaultTest:: |
protected | property | The used plugin configuration. | |
LocalActionDefaultTest:: |
protected | property | The tested local action default plugin. | |
LocalActionDefaultTest:: |
protected | property | The used plugin definition. | |
LocalActionDefaultTest:: |
protected | property | The used plugin ID. | |
LocalActionDefaultTest:: |
protected | property | The mocked route provider. | |
LocalActionDefaultTest:: |
protected | property | The mocked translator. | |
LocalActionDefaultTest:: |
protected | function |
Overrides UnitTestCase:: |
|
LocalActionDefaultTest:: |
protected | function | Setups the local action default. | |
LocalActionDefaultTest:: |
public | function | Tests the getTitle method without a translation context. | |
LocalActionDefaultTest:: |
public | function | Tests the getTitle method with a translation context. | |
LocalActionDefaultTest:: |
public | function | Tests the getTitle method with title arguments. | |
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. |