[TASK] Remove further evaluations of pid=-1
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Mvc / Controller / MvcPropertyMappingConfigurationServiceTest.php
index b52d12c..a705b11 100644 (file)
@@ -1,31 +1,26 @@
 <?php
 namespace TYPO3\CMS\Extbase\Tests\Unit\Mvc\Controller;
 
-/*                                                                        *
- * This script belongs to the Extbase framework                           *
- *                                                                        *
- * It is free software; you can redistribute it and/or modify it under    *
- * the terms of the GNU Lesser General Public License as published by the *
- * Free Software Foundation, either version 3 of the License, or (at your *
- * option) any later version.                                             *
- *                                                                        *
- * This script is distributed in the hope that it will be useful, but     *
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-    *
- * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser       *
- * General Public License for more details.                               *
- *                                                                        *
- * You should have received a copy of the GNU Lesser General Public       *
- * License along with the script.                                         *
- * If not, see http://www.gnu.org/licenses/lgpl.html                      *
- *                                                                        *
- * The TYPO3 project - inspiring people to share!                         *
- *                                                                        */
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
 use TYPO3\CMS\Extbase\Security\Exception\InvalidArgumentForHashGenerationException;
+use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
 
 /**
  * Test case
  */
-class MvcPropertyMappingConfigurationServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
+class MvcPropertyMappingConfigurationServiceTest extends UnitTestCase
 {
     /**
      * Data provider for generating the list of trusted properties
@@ -34,56 +29,56 @@ class MvcPropertyMappingConfigurationServiceTest extends \TYPO3\CMS\Core\Tests\U
      */
     public function dataProviderForgenerateTrustedPropertiesToken()
     {
-        return array(
-            'Simple Case - Empty' => array(
-                array(),
-                array(),
-            ),
-            'Simple Case - Single Value' => array(
-                array('field1'),
-                array('field1' => 1),
-            ),
-            'Simple Case - Two Values' => array(
-                array('field1', 'field2'),
-                array(
+        return [
+            'Simple Case - Empty' => [
+                [],
+                [],
+            ],
+            'Simple Case - Single Value' => [
+                ['field1'],
+                ['field1' => 1],
+            ],
+            'Simple Case - Two Values' => [
+                ['field1', 'field2'],
+                [
                     'field1' => 1,
                     'field2' => 1
-                ),
-            ),
-            'Recursion' => array(
-                array('field1', 'field[subfield1]', 'field[subfield2]'),
-                array(
+                ],
+            ],
+            'Recursion' => [
+                ['field1', 'field[subfield1]', 'field[subfield2]'],
+                [
                     'field1' => 1,
-                    'field' => array(
+                    'field' => [
                         'subfield1' => 1,
                         'subfield2' => 1
-                    )
-                ),
-            ),
-            'recursion with duplicated field name' => array(
-                array('field1', 'field[subfield1]', 'field[subfield2]', 'field1'),
-                array(
+                    ]
+                ],
+            ],
+            'recursion with duplicated field name' => [
+                ['field1', 'field[subfield1]', 'field[subfield2]', 'field1'],
+                [
                     'field1' => 1,
-                    'field' => array(
+                    'field' => [
                         'subfield1' => 1,
                         'subfield2' => 1
-                    )
-                ),
-            ),
-            'Recursion with un-named fields at the end (...[]). There, they should be made explicit by increasing the counter' => array(
-                array('field1', 'field[subfield1][]', 'field[subfield1][]', 'field[subfield2]'),
-                array(
+                    ]
+                ],
+            ],
+            'Recursion with un-named fields at the end (...[]). There, they should be made explicit by increasing the counter' => [
+                ['field1', 'field[subfield1][]', 'field[subfield1][]', 'field[subfield2]'],
+                [
                     'field1' => 1,
-                    'field' => array(
-                        'subfield1' => array(
+                    'field' => [
+                        'subfield1' => [
                             0 => 1,
                             1 => 1
-                        ),
+                        ],
                         'subfield2' => 1
-                    )
-                ),
-            ),
-        );
+                    ]
+                ],
+            ],
+        ];
     }
 
     /**
@@ -94,29 +89,29 @@ class MvcPropertyMappingConfigurationServiceTest extends \TYPO3\CMS\Core\Tests\U
      */
     public function dataProviderForgenerateTrustedPropertiesTokenWithUnallowedValues()
     {
-        return array(
-            'Overriding form fields (string overridden by array) - 1' => array(
-                array('field1', 'field2', 'field2[bla]', 'field2[blubb]'),
+        return [
+            'Overriding form fields (string overridden by array) - 1' => [
+                ['field1', 'field2', 'field2[bla]', 'field2[blubb]'],
                 1255072196
-            ),
-            'Overriding form fields (string overridden by array) - 2' => array(
-                array('field1', 'field2[bla]', 'field2[bla][blubb][blubb]'),
+            ],
+            'Overriding form fields (string overridden by array) - 2' => [
+                ['field1', 'field2[bla]', 'field2[bla][blubb][blubb]'],
                 1255072196
-            ),
-            'Overriding form fields (array overridden by string) - 1' => array(
-                array('field1', 'field2[bla]', 'field2[blubb]', 'field2'),
+            ],
+            'Overriding form fields (array overridden by string) - 1' => [
+                ['field1', 'field2[bla]', 'field2[blubb]', 'field2'],
                 1255072587
-            ),
-            'Overriding form fields (array overridden by string) - 2' => array(
-                array('field1', 'field2[bla][blubb][blubb]', 'field2[bla]'),
+            ],
+            'Overriding form fields (array overridden by string) - 2' => [
+                ['field1', 'field2[bla][blubb][blubb]', 'field2[bla]'],
                 1255072587
-            ),
-            'Empty [] not as last argument' => array(
-                array('field1', 'field2[][bla]'),
+            ],
+            'Empty [] not as last argument' => [
+                ['field1', 'field2[][bla]'],
                 1255072832
-            )
+            ]
 
-        );
+        ];
     }
 
     /**
@@ -125,7 +120,9 @@ class MvcPropertyMappingConfigurationServiceTest extends \TYPO3\CMS\Core\Tests\U
      */
     public function generateTrustedPropertiesTokenGeneratesTheCorrectHashesInNormalOperation($input, $expected)
     {
-        $requestHashService = $this->getMock(\TYPO3\CMS\Extbase\Mvc\Controller\MvcPropertyMappingConfigurationService::class, array('serializeAndHashFormFieldArray'));
+        $requestHashService = $this->getMockBuilder(\TYPO3\CMS\Extbase\Mvc\Controller\MvcPropertyMappingConfigurationService::class)
+            ->setMethods(['serializeAndHashFormFieldArray'])
+            ->getMock();
         $requestHashService->expects($this->once())->method('serializeAndHashFormFieldArray')->with($expected);
         $requestHashService->generateTrustedPropertiesToken($input);
     }
@@ -140,7 +137,9 @@ class MvcPropertyMappingConfigurationServiceTest extends \TYPO3\CMS\Core\Tests\U
     {
         $this->expectException(InvalidArgumentForHashGenerationException::class);
         $this->expectExceptionCode($expectExceptionCode);
-        $requestHashService = $this->getMock(\TYPO3\CMS\Extbase\Mvc\Controller\MvcPropertyMappingConfigurationService::class, array('serializeAndHashFormFieldArray'));
+        $requestHashService = $this->getMockBuilder(\TYPO3\CMS\Extbase\Mvc\Controller\MvcPropertyMappingConfigurationService::class)
+            ->setMethods(['serializeAndHashFormFieldArray'])
+            ->getMock();
         $requestHashService->generateTrustedPropertiesToken($input);
     }
 
@@ -149,21 +148,25 @@ class MvcPropertyMappingConfigurationServiceTest extends \TYPO3\CMS\Core\Tests\U
      */
     public function serializeAndHashFormFieldArrayWorks()
     {
-        $formFieldArray = array(
-            'bla' => array(
+        $formFieldArray = [
+            'bla' => [
                 'blubb' => 1,
                 'hu' => 1
-            )
-        );
+            ]
+        ];
         $mockHash = '12345';
 
-        $hashService = $this->getMock($this->buildAccessibleProxy(\TYPO3\CMS\Extbase\Mvc\Controller\MvcPropertyMappingConfigurationService::class), array('appendHmac'));
-        $hashService->expects($this->once())->method('appendHmac')->with(serialize($formFieldArray))->will($this->returnValue(serialize($formFieldArray) . $mockHash));
+        $hashService = $this->getMockBuilder($this->buildAccessibleProxy(\TYPO3\CMS\Extbase\Mvc\Controller\MvcPropertyMappingConfigurationService::class))
+            ->setMethods(['appendHmac'])
+            ->getMock();
+        $hashService->expects($this->once())->method('appendHmac')->with(json_encode($formFieldArray))->will($this->returnValue(json_encode($formFieldArray) . $mockHash));
 
-        $requestHashService = $this->getMock($this->buildAccessibleProxy(\TYPO3\CMS\Extbase\Mvc\Controller\MvcPropertyMappingConfigurationService::class), array('dummy'));
+        $requestHashService = $this->getMockBuilder($this->buildAccessibleProxy(\TYPO3\CMS\Extbase\Mvc\Controller\MvcPropertyMappingConfigurationService::class))
+            ->setMethods(['dummy'])
+            ->getMock();
         $requestHashService->_set('hashService', $hashService);
 
-        $expected = serialize($formFieldArray) . $mockHash;
+        $expected = json_encode($formFieldArray) . $mockHash;
         $actual = $requestHashService->_call('serializeAndHashFormFieldArray', $formFieldArray);
         $this->assertEquals($expected, $actual);
     }
@@ -173,7 +176,7 @@ class MvcPropertyMappingConfigurationServiceTest extends \TYPO3\CMS\Core\Tests\U
      */
     public function initializePropertyMappingConfigurationDoesNothingIfTrustedPropertiesAreNotSet()
     {
-        $request = $this->getMockBuilder(\TYPO3\CMS\Extbase\Mvc\Request::class)->setMethods(array('getInternalArgument'))->disableOriginalConstructor()->getMock();
+        $request = $this->getMockBuilder(\TYPO3\CMS\Extbase\Mvc\Request::class)->setMethods(['getInternalArgument'])->disableOriginalConstructor()->getMock();
         $request->expects($this->any())->method('getInternalArgument')->with('__trustedProperties')->will($this->returnValue(null));
         $arguments = new \TYPO3\CMS\Extbase\Mvc\Controller\Arguments();
 
@@ -186,9 +189,9 @@ class MvcPropertyMappingConfigurationServiceTest extends \TYPO3\CMS\Core\Tests\U
      */
     public function initializePropertyMappingConfigurationReturnsEarlyIfNoTrustedPropertiesAreSet()
     {
-        $trustedProperties = array(
+        $trustedProperties = [
             'foo' => 1
-        );
+        ];
         $this->initializePropertyMappingConfiguration($trustedProperties);
     }
 
@@ -197,9 +200,9 @@ class MvcPropertyMappingConfigurationServiceTest extends \TYPO3\CMS\Core\Tests\U
      */
     public function initializePropertyMappingConfigurationReturnsEarlyIfArgumentIsUnknown()
     {
-        $trustedProperties = array(
+        $trustedProperties = [
             'nonExistingArgument' => 1
-        );
+        ];
         $arguments = $this->initializePropertyMappingConfiguration($trustedProperties);
         $this->assertFalse($arguments->hasArgument('nonExistingArgument'));
     }
@@ -209,14 +212,14 @@ class MvcPropertyMappingConfigurationServiceTest extends \TYPO3\CMS\Core\Tests\U
      */
     public function initializePropertyMappingConfigurationSetsModificationAllowedIfIdentityPropertyIsSet()
     {
-        $trustedProperties = array(
-            'foo' => array(
+        $trustedProperties = [
+            'foo' => [
                 '__identity' => 1,
-                'nested' => array(
+                'nested' => [
                     '__identity' => 1,
-                )
-            )
-        );
+                ]
+            ]
+        ];
         $arguments = $this->initializePropertyMappingConfiguration($trustedProperties);
         $propertyMappingConfiguration = $arguments->getArgument('foo')->getPropertyMappingConfiguration();
         $this->assertTrue($propertyMappingConfiguration->getConfigurationValue(\TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter::class, \TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter::CONFIGURATION_MODIFICATION_ALLOWED), 'ConfigurationValue is not CONFIGURATION_MODIFICATION_ALLOWED at line ' . __LINE__);
@@ -233,11 +236,11 @@ class MvcPropertyMappingConfigurationServiceTest extends \TYPO3\CMS\Core\Tests\U
      */
     public function initializePropertyMappingConfigurationSetsCreationAllowedIfIdentityPropertyIsNotSet()
     {
-        $trustedProperties = array(
-            'foo' => array(
-                'bar' => array()
-            )
-        );
+        $trustedProperties = [
+            'foo' => [
+                'bar' => []
+            ]
+        ];
         $arguments = $this->initializePropertyMappingConfiguration($trustedProperties);
         $propertyMappingConfiguration = $arguments->getArgument('foo')->getPropertyMappingConfiguration();
         $this->assertNull($propertyMappingConfiguration->getConfigurationValue(\TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter::class, \TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter::CONFIGURATION_MODIFICATION_ALLOWED));
@@ -254,11 +257,11 @@ class MvcPropertyMappingConfigurationServiceTest extends \TYPO3\CMS\Core\Tests\U
      */
     public function initializePropertyMappingConfigurationSetsAllowedFields()
     {
-        $trustedProperties = array(
-            'foo' => array(
+        $trustedProperties = [
+            'foo' => [
                 'bar' => 1
-            )
-        );
+            ]
+        ];
         $arguments = $this->initializePropertyMappingConfiguration($trustedProperties);
         $propertyMappingConfiguration = $arguments->getArgument('foo')->getPropertyMappingConfiguration();
         $this->assertFalse($propertyMappingConfiguration->shouldMap('someProperty'));
@@ -270,13 +273,13 @@ class MvcPropertyMappingConfigurationServiceTest extends \TYPO3\CMS\Core\Tests\U
      */
     public function initializePropertyMappingConfigurationSetsAllowedFieldsRecursively()
     {
-        $trustedProperties = array(
-            'foo' => array(
-                'bar' => array(
+        $trustedProperties = [
+            'foo' => [
+                'bar' => [
                     'foo' => 1
-                )
-            )
-        );
+                ]
+            ]
+        ];
         $arguments = $this->initializePropertyMappingConfiguration($trustedProperties);
         $propertyMappingConfiguration = $arguments->getArgument('foo')->getPropertyMappingConfiguration();
         $this->assertFalse($propertyMappingConfiguration->shouldMap('someProperty'));
@@ -293,17 +296,19 @@ class MvcPropertyMappingConfigurationServiceTest extends \TYPO3\CMS\Core\Tests\U
      */
     protected function initializePropertyMappingConfiguration(array $trustedProperties)
     {
-        $request = $this->getMockBuilder(\TYPO3\CMS\Extbase\Mvc\Request::class)->setMethods(array('getInternalArgument'))->disableOriginalConstructor()->getMock();
+        $request = $this->getMockBuilder(\TYPO3\CMS\Extbase\Mvc\Request::class)->setMethods(['getInternalArgument'])->disableOriginalConstructor()->getMock();
         $request->expects($this->any())->method('getInternalArgument')->with('__trustedProperties')->will($this->returnValue('fooTrustedProperties'));
 
-        $mockHashService = $this->getMock(\TYPO3\CMS\Extbase\Security\Cryptography\HashService::class, array('validateAndStripHmac'));
-        $mockHashService->expects($this->once())->method('validateAndStripHmac')->with('fooTrustedProperties')->will($this->returnValue(serialize($trustedProperties)));
+        $mockHashService = $this->getMockBuilder(\TYPO3\CMS\Extbase\Security\Cryptography\HashService::class)
+            ->setMethods(['validateAndStripHmac'])
+            ->getMock();
+        $mockHashService->expects($this->once())->method('validateAndStripHmac')->with('fooTrustedProperties')->will($this->returnValue(json_encode($trustedProperties)));
 
-        $requestHashService = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Mvc\Controller\MvcPropertyMappingConfigurationService::class, array('dummy'));
+        $requestHashService = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Mvc\Controller\MvcPropertyMappingConfigurationService::class, ['dummy']);
         $requestHashService->_set('hashService', $mockHashService);
 
-        $mockObjectManager = $this->getMock(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface::class);
-        $mockArgument = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Mvc\Controller\Argument::class, array('getName'), array(), '', false);
+        $mockObjectManager = $this->createMock(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface::class);
+        $mockArgument = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Mvc\Controller\Argument::class, ['getName'], [], '', false);
 
         $propertyMappingConfiguration = new \TYPO3\CMS\Extbase\Mvc\Controller\MvcPropertyMappingConfiguration();
 
@@ -311,7 +316,7 @@ class MvcPropertyMappingConfigurationServiceTest extends \TYPO3\CMS\Core\Tests\U
         $mockArgument->expects($this->any())->method('getName')->will($this->returnValue('foo'));
         $mockObjectManager->expects($this->once())->method('get')->with(\TYPO3\CMS\Extbase\Mvc\Controller\Argument::class)->will($this->returnValue($mockArgument));
 
-        $arguments = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Mvc\Controller\Arguments::class, array('dummy'));
+        $arguments = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Mvc\Controller\Arguments::class, ['dummy']);
         $arguments->_set('objectManager', $mockObjectManager);
         $arguments->addNewArgument('foo');