ContextualLinkDefaultTest.php in Zircon Profile 8.0
File
core/tests/Drupal/Tests/Core/Menu/ContextualLinkDefaultTest.php
View source
<?php
namespace Drupal\Tests\Core\Menu;
use Drupal\Core\Menu\ContextualLinkDefault;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\HttpFoundation\Request;
class ContextualLinkDefaultTest extends UnitTestCase {
protected $contextualLinkDefault;
protected $config = array();
protected $pluginId = 'contextual_link_default';
protected $pluginDefinition = array(
'id' => 'contextual_link_default',
);
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);
}
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());
}
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());
}
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));
}
public function testGetRouteName($route_name = 'test_route_name') {
$this->pluginDefinition['route_name'] = $route_name;
$this
->setupContextualLinkDefault();
$this
->assertEquals($route_name, $this->contextualLinkDefault
->getRouteName());
}
public function testGetGroup($group_name = 'test_group') {
$this->pluginDefinition['group'] = $group_name;
$this
->setupContextualLinkDefault();
$this
->assertEquals($group_name, $this->contextualLinkDefault
->getGroup());
}
public function testGetOptions($options = array(
'key' => 'value',
)) {
$this->pluginDefinition['options'] = $options;
$this
->setupContextualLinkDefault();
$this
->assertEquals($options, $this->contextualLinkDefault
->getOptions());
}
public function testGetWeight($weight = 5) {
$this->pluginDefinition['weight'] = $weight;
$this
->setupContextualLinkDefault();
$this
->assertEquals($weight, $this->contextualLinkDefault
->getWeight());
}
}