LocalActionDefaultTest.php in Drupal 8
File
core/tests/Drupal/Tests/Core/Menu/LocalActionDefaultTest.php
View source
<?php
namespace Drupal\Tests\Core\Menu;
use Drupal\Core\Menu\LocalActionDefault;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\HttpFoundation\Request;
class LocalActionDefaultTest extends UnitTestCase {
protected $localActionDefault;
protected $config = [];
protected $pluginId = 'local_action_default';
protected $pluginDefinition = [
'id' => 'local_action_default',
];
protected $stringTranslation;
protected $routeProvider;
protected function setUp() {
parent::setUp();
$this->stringTranslation = $this
->createMock('Drupal\\Core\\StringTranslation\\TranslationInterface');
$this->routeProvider = $this
->createMock('Drupal\\Core\\Routing\\RouteProviderInterface');
}
protected function setupLocalActionDefault() {
$this->localActionDefault = new LocalActionDefault($this->config, $this->pluginId, $this->pluginDefinition, $this->routeProvider);
}
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());
}
public function testGetTitleWithContext() {
$this->pluginDefinition['title'] = new TranslatableMarkup('Example', [], [
'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());
}
public function testGetTitleWithTitleArguments() {
$this->pluginDefinition['title'] = new TranslatableMarkup('Example @test', [
'@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));
}
}