only in patch2: unchanged: --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Menu/LocalActionDefaultTest.php @@ -0,0 +1,124 @@ + '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; + + public static function getInfo() { + return array( + 'name' => 'Local actions default plugin.', + 'description' => 'Tests the local action default class.', + 'group' => 'Menu', + ); + } + + 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() { + $container = new ContainerBuilder(); + $container->set('string_translation', $this->stringTranslation); + \Drupal::setContainer($container); + + $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'] = 'Example'; + $this->stringTranslation->expects($this->once()) + ->method('translate') + ->with($this->pluginDefinition['title'], array(), array()) + ->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'] = 'Example'; + $this->pluginDefinition['title_context'] = 'context'; + $this->stringTranslation->expects($this->once()) + ->method('translate') + ->with($this->pluginDefinition['title'], array(), array('context' => 'context')) + ->will($this->returnValue('Example translated with context')); + + $this->setupLocalActionDefault(); + $this->assertEquals('Example translated with context', $this->localActionDefault->getTitle()); + } + +}