TYPO3 CMS  TYPO3_8-7
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 
21 class WidgetContextTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
22 {
26  protected $widgetContext;
27 
31  protected function setUp()
32  {
33  $this->widgetContext = new \TYPO3\CMS\Fluid\Core\Widget\WidgetContext();
34  }
35 
42  public function getterMethodReturnsValue($name, $value)
43  {
44  $property = new \ReflectionProperty(WidgetContext::class, $name);
45  $property->setAccessible(true);
46  $property->setValue($this->widgetContext, $value);
47  $method = 'get' . ucfirst($name);
48  $this->assertEquals($value, call_user_func_array([$this->widgetContext, $method], []));
49  }
50 
57  public function setterMethodSetsPropertyValue($name, $value)
58  {
59  $method = 'set' . ucfirst($name);
60  call_user_func_array([$this->widgetContext, $method], [$value]);
61  $this->assertAttributeEquals($value, $name, $this->widgetContext);
62  }
63 
67  public function getSetterGetterTestValues()
68  {
69  return [
70  ['parentPluginNamespace', 'foo-bar'],
71  ['parentExtensionName', 'baz'],
72  ['parentPluginName', 'baz-foo'],
73  ['widgetViewHelperClassName', 'bar-foo'],
74  ];
75  }
76 
81  {
82  $this->widgetContext->setWidgetIdentifier('myWidgetIdentifier');
83  $this->assertEquals('myWidgetIdentifier', $this->widgetContext->getWidgetIdentifier());
84  }
85 
90  {
91  $this->widgetContext->setAjaxWidgetIdentifier(42);
92  $this->assertEquals(42, $this->widgetContext->getAjaxWidgetIdentifier());
93  }
94 
99  {
100  $this->widgetContext->setWidgetConfiguration(['key' => 'value']);
101  $this->assertEquals(['key' => 'value'], $this->widgetContext->getWidgetConfiguration());
102  }
103 
108  {
109  $this->widgetContext->setControllerObjectName('Tx_Fluid_Object_Name');
110  $this->assertEquals('Tx_Fluid_Object_Name', $this->widgetContext->getControllerObjectName());
111  }
112 
117  {
118  $viewHelperChildNodes = $this->createMock(\TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\RootNode::class);
119  $renderingContext = $this->createMock(\TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface::class);
120  $this->widgetContext->setViewHelperChildNodes($viewHelperChildNodes, $renderingContext);
121  $this->assertSame($viewHelperChildNodes, $this->widgetContext->getViewHelperChildNodes());
122  $this->assertSame($renderingContext, $this->widgetContext->getViewHelperChildNodeRenderingContext());
123  }
124 
129  {
130  $this->assertEquals(
131  [
132  'widgetIdentifier', 'ajaxWidgetIdentifier', 'widgetConfiguration', 'controllerObjectName',
133  'parentPluginNamespace', 'parentVendorName', 'parentExtensionName', 'parentPluginName',
134  'widgetViewHelperClassName'
135  ],
136  $this->widgetContext->__sleep()
137  );
138  }
139 }