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