Upgraded drupal core with security updates
[yaffs-website] / web / core / tests / Drupal / Tests / Core / Menu / LocalActionDefaultTest.php
1 <?php
2
3 namespace Drupal\Tests\Core\Menu;
4
5 use Drupal\Core\Menu\LocalActionDefault;
6 use Drupal\Core\StringTranslation\TranslatableMarkup;
7 use Drupal\Tests\UnitTestCase;
8 use Symfony\Component\HttpFoundation\Request;
9
10 /**
11  * @coversDefaultClass \Drupal\Core\Menu\LocalActionDefault
12  * @group Menu
13  */
14 class LocalActionDefaultTest extends UnitTestCase {
15
16   /**
17    * The tested local action default plugin.
18    *
19    * @var \Drupal\Core\Menu\LocalActionDefault
20    */
21   protected $localActionDefault;
22
23   /**
24    * The used plugin configuration.
25    *
26    * @var array
27    */
28   protected $config = [];
29
30   /**
31    * The used plugin ID.
32    *
33    * @var string
34    */
35   protected $pluginId = 'local_action_default';
36
37   /**
38    * The used plugin definition.
39    *
40    * @var array
41    */
42   protected $pluginDefinition = [
43     'id' => 'local_action_default',
44   ];
45
46   /**
47    * The mocked translator.
48    *
49    * @var \Drupal\Core\StringTranslation\TranslationInterface|\PHPUnit_Framework_MockObject_MockObject
50    */
51   protected $stringTranslation;
52
53   /**
54    * The mocked route provider.
55    *
56    * @var \Drupal\Core\Routing\RouteProviderInterface|\PHPUnit_Framework_MockObject_MockObject
57    */
58   protected $routeProvider;
59
60   protected function setUp() {
61     parent::setUp();
62
63     $this->stringTranslation = $this->getMock('Drupal\Core\StringTranslation\TranslationInterface');
64     $this->routeProvider = $this->getMock('Drupal\Core\Routing\RouteProviderInterface');
65   }
66
67   /**
68    * Setups the local action default.
69    */
70   protected function setupLocalActionDefault() {
71     $this->localActionDefault = new LocalActionDefault($this->config, $this->pluginId, $this->pluginDefinition, $this->routeProvider);
72   }
73
74   /**
75    * Tests the getTitle method without a translation context.
76    *
77    * @see \Drupal\Core\Menu\LocalTaskDefault::getTitle()
78    */
79   public function testGetTitle() {
80     $this->pluginDefinition['title'] = (new TranslatableMarkup('Example', [], [], $this->stringTranslation));
81     $this->stringTranslation->expects($this->once())
82       ->method('translateString')
83       ->with($this->pluginDefinition['title'])
84       ->will($this->returnValue('Example translated'));
85
86     $this->setupLocalActionDefault();
87     $this->assertEquals('Example translated', $this->localActionDefault->getTitle());
88   }
89
90   /**
91    * Tests the getTitle method with a translation context.
92    *
93    * @see \Drupal\Core\Menu\LocalTaskDefault::getTitle()
94    */
95   public function testGetTitleWithContext() {
96     $this->pluginDefinition['title'] = (new TranslatableMarkup('Example', [], ['context' => 'context'], $this->stringTranslation));
97     $this->stringTranslation->expects($this->once())
98       ->method('translateString')
99       ->with($this->pluginDefinition['title'])
100       ->will($this->returnValue('Example translated with context'));
101
102     $this->setupLocalActionDefault();
103     $this->assertEquals('Example translated with context', $this->localActionDefault->getTitle());
104   }
105
106   /**
107    * Tests the getTitle method with title arguments.
108    */
109   public function testGetTitleWithTitleArguments() {
110     $this->pluginDefinition['title'] = (new TranslatableMarkup('Example @test', ['@test' => 'value'], [], $this->stringTranslation));
111     $this->stringTranslation->expects($this->once())
112       ->method('translateString')
113       ->with($this->pluginDefinition['title'])
114       ->will($this->returnValue('Example value'));
115
116     $this->setupLocalActionDefault();
117     $request = new Request();
118     $this->assertEquals('Example value', $this->localActionDefault->getTitle($request));
119   }
120
121 }