‪TYPO3CMS  9.5
WidgetContextTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
17 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
18 
22 class ‪WidgetContextTest extends UnitTestCase
23 {
27  protected ‪$widgetContext;
28 
32  protected function ‪setUp()
33  {
34  $this->widgetContext = new \TYPO3\CMS\Fluid\Core\Widget\WidgetContext();
35  }
36 
43  public function ‪getterMethodReturnsValue($name, $value)
44  {
45  $property = new \ReflectionProperty(WidgetContext::class, $name);
46  $property->setAccessible(true);
47  $property->setValue($this->widgetContext, $value);
48  $method = 'get' . ucfirst($name);
49  $this->assertEquals($value, call_user_func_array([$this->widgetContext, $method], []));
50  }
51 
58  public function ‪setterMethodSetsPropertyValue($name, $value)
59  {
60  $method = 'set' . ucfirst($name);
61  call_user_func_array([$this->widgetContext, $method], [$value]);
62  $this->assertAttributeEquals($value, $name, $this->widgetContext);
63  }
64 
68  public function ‪getSetterGetterTestValues()
69  {
70  return [
71  ['parentPluginNamespace', 'foo-bar'],
72  ['parentExtensionName', 'baz'],
73  ['parentPluginName', 'baz-foo'],
74  ['widgetViewHelperClassName', 'bar-foo'],
75  ];
76  }
77 
81  public function ‪widgetIdentifierCanBeReadAgain()
82  {
83  $this->widgetContext->setWidgetIdentifier('myWidgetIdentifier');
84  $this->assertEquals('myWidgetIdentifier', $this->widgetContext->getWidgetIdentifier());
85  }
86 
91  {
92  $this->widgetContext->setAjaxWidgetIdentifier(42);
93  $this->assertEquals(42, $this->widgetContext->getAjaxWidgetIdentifier());
94  }
95 
99  public function ‪widgetConfigurationCanBeReadAgain()
100  {
101  $this->widgetContext->setWidgetConfiguration(['key' => 'value']);
102  $this->assertEquals(['key' => 'value'], $this->widgetContext->getWidgetConfiguration());
103  }
104 
108  public function ‪controllerObjectNameCanBeReadAgain()
109  {
110  $this->widgetContext->setControllerObjectName('Tx_Fluid_Object_Name');
111  $this->assertEquals('Tx_Fluid_Object_Name', $this->widgetContext->getControllerObjectName());
112  }
113 
117  public function ‪viewHelperChildNodesCanBeReadAgain()
118  {
119  $viewHelperChildNodes = $this->createMock(\‪TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\RootNode::class);
120  $renderingContext = $this->createMock(\‪TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface::class);
121  $this->widgetContext->setViewHelperChildNodes($viewHelperChildNodes, $renderingContext);
122  $this->assertSame($viewHelperChildNodes, $this->widgetContext->getViewHelperChildNodes());
123  $this->assertSame($renderingContext, $this->widgetContext->getViewHelperChildNodeRenderingContext());
124  }
125 
129  public function ‪sleepReturnsExpectedPropertyNames()
130  {
131  $this->assertEquals(
132  [
133  'widgetIdentifier', 'ajaxWidgetIdentifier', 'widgetConfiguration', 'controllerObjectName',
134  'parentPluginNamespace', 'parentVendorName', 'parentExtensionName', 'parentPluginName',
135  'widgetViewHelperClassName'
136  ],
137  $this->widgetContext->__sleep()
138  );
139  }
140 }
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Widget\WidgetContextTest\widgetConfigurationCanBeReadAgain
‪widgetConfigurationCanBeReadAgain()
Definition: WidgetContextTest.php:98
‪TYPO3Fluid
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Widget\WidgetContextTest\$widgetContext
‪TYPO3 CMS Fluid Core Widget WidgetContext $widgetContext
Definition: WidgetContextTest.php:26
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Widget\WidgetContextTest
Definition: WidgetContextTest.php:23
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Widget\WidgetContextTest\setUp
‪setUp()
Definition: WidgetContextTest.php:31
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Widget\WidgetContextTest\setterMethodSetsPropertyValue
‪setterMethodSetsPropertyValue($name, $value)
Definition: WidgetContextTest.php:57
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Widget\WidgetContextTest\ajaxWidgetIdentifierCanBeReadAgain
‪ajaxWidgetIdentifierCanBeReadAgain()
Definition: WidgetContextTest.php:89
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Widget\WidgetContextTest\widgetIdentifierCanBeReadAgain
‪widgetIdentifierCanBeReadAgain()
Definition: WidgetContextTest.php:80
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Widget\WidgetContextTest\viewHelperChildNodesCanBeReadAgain
‪viewHelperChildNodesCanBeReadAgain()
Definition: WidgetContextTest.php:116
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Widget
Definition: AbstractWidgetControllerTest.php:2
‪TYPO3\CMS\Fluid\Core\Widget\WidgetContext
Definition: WidgetContext.php:29
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Widget\WidgetContextTest\controllerObjectNameCanBeReadAgain
‪controllerObjectNameCanBeReadAgain()
Definition: WidgetContextTest.php:107
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Widget\WidgetContextTest\getSetterGetterTestValues
‪array getSetterGetterTestValues()
Definition: WidgetContextTest.php:67
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Widget\WidgetContextTest\sleepReturnsExpectedPropertyNames
‪sleepReturnsExpectedPropertyNames()
Definition: WidgetContextTest.php:128
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Widget\WidgetContextTest\getterMethodReturnsValue
‪getterMethodReturnsValue($name, $value)
Definition: WidgetContextTest.php:42