[TASK] Removes eval() in BackendUtilityTest 97/40497/3
authorWouter Wolters <typo3@wouterwolters.nl>
Sat, 20 Jun 2015 18:01:41 +0000 (20:01 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Sun, 21 Jun 2015 14:28:14 +0000 (16:28 +0200)
Resolves: #67651
Releases: master
Change-Id: Ib1199162a747c486bba60d0ec489ab07226425c1
Reviewed-on: http://review.typo3.org/40497
Reviewed-by: Benjamin Mack <benni@typo3.org>
Tested-by: Benjamin Mack <benni@typo3.org>
Reviewed-by: Susanne Moog <typo3@susannemoog.de>
Tested-by: Susanne Moog <typo3@susannemoog.de>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/backend/Tests/Unit/Utility/BackendUtilityTest.php
typo3/sysext/backend/Tests/Unit/Utility/Fixtures/ExcludeFieldsReturnsCorrectFieldListFixture.php [new file with mode: 0644]
typo3/sysext/backend/Tests/Unit/Utility/Fixtures/ExcludeFieldsReturnsCorrectListWithFlexFormFieldsFixture.php [new file with mode: 0644]
typo3/sysext/backend/Tests/Unit/Utility/Fixtures/LabelFromItemListMergedReturnsCorrectFieldsFixture.php [new file with mode: 0644]
typo3/sysext/backend/Tests/Unit/Utility/Fixtures/ProcessedValueForGroupWithMultipleAllowedTablesFixture.php [new file with mode: 0644]
typo3/sysext/backend/Tests/Unit/Utility/Fixtures/ProcessedValueForGroupWithOneAllowedTableFixture.php [new file with mode: 0644]
typo3/sysext/backend/Tests/Unit/Utility/Fixtures/ProcessedValueForSelectWithMMRelationFixture.php [new file with mode: 0644]

index 9271496..1561d1c 100644 (file)
@@ -15,6 +15,12 @@ namespace TYPO3\CMS\Backend\Tests\Unit\Utility;
  */
 
 use TYPO3\CMS\Backend\Utility\BackendUtility;
+use TYPO3\CMS\Backend\Tests\Unit\Utility\Fixtures\ProcessedValueForGroupWithOneAllowedTableFixture;
+use TYPO3\CMS\Backend\Tests\Unit\Utility\Fixtures\ProcessedValueForGroupWithMultipleAllowedTablesFixture;
+use TYPO3\CMS\Backend\Tests\Unit\Utility\Fixtures\ProcessedValueForSelectWithMMRelationFixture;
+use TYPO3\CMS\Backend\Tests\Unit\Utility\Fixtures\LabelFromItemListMergedReturnsCorrectFieldsFixture;
+use TYPO3\CMS\Backend\Tests\Unit\Utility\Fixtures\ExcludeFieldsReturnsCorrectFieldListFixture;
+use TYPO3\CMS\Backend\Tests\Unit\Utility\Fixtures\ExcludeFieldsReturnsCorrectListWithFlexFormFieldsFixture;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
@@ -157,36 +163,6 @@ class BackendUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function getProcessedValueForGroupWithOneAllowedTable() {
-               // Disable getRecordWSOL and getRecordTitle dependency by returning stable results
-               /** @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Backend\Utility\BackendUtility $subject */
-               $className = $this->getUniqueId('BackendUtility');
-               $subject = __NAMESPACE__ . '\\' . $className;
-               eval(
-                       'namespace ' . __NAMESPACE__ . ';' .
-                       'class ' . $className . ' extends \\TYPO3\\CMS\\Backend\\Utility\\BackendUtility {' .
-                       '  static public function getRecordWSOL() {' .
-                       '    static $called = 0;' .
-                       '    ++$called;' .
-                       '    if ($called === 1) {' .
-                       '      return array(\'title\' => \'Page 1\');' .
-                       '    }' .
-                       '    if ($called === 2) {' .
-                       '      return array(\'title\' => \'Page 2\');' .
-                       '    }' .
-                       '  }' .
-                       '  static public function getRecordTitle() {' .
-                       '    static $called = 0;' .
-                       '    ++$called;' .
-                       '    if ($called === 1) {' .
-                       '      return \'Page 1\';' .
-                       '    }' .
-                       '    if ($called === 2) {' .
-                       '      return \'Page 2\';' .
-                       '    }' .
-                       '  }' .
-                       '}'
-               );
-
                $GLOBALS['TCA'] = array(
                        'tt_content' => array(
                                'columns' => array(
@@ -205,43 +181,13 @@ class BackendUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                        ),
                );
 
-               $this->assertSame('Page 1, Page 2', $subject::getProcessedValue('tt_content', 'pages', '1,2'));
+               $this->assertSame('Page 1, Page 2', ProcessedValueForGroupWithOneAllowedTableFixture::getProcessedValue('tt_content', 'pages', '1,2'));
        }
 
        /**
         * @test
         */
        public function getProcessedValueForGroupWithMultipleAllowedTables() {
-               // Disable getRecordWSOL and getRecordTitle dependency by returning stable results
-               /** @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Backend\Utility\BackendUtility $subject */
-               $className = $this->getUniqueId('BackendUtility');
-               $subject = __NAMESPACE__ . '\\' . $className;
-               eval(
-                       'namespace ' . __NAMESPACE__ . ';' .
-                       'class ' . $className . ' extends \\TYPO3\\CMS\\Backend\\Utility\\BackendUtility {' .
-                       '  static public function getRecordWSOL() {' .
-                       '    static $called = 0;' .
-                       '    ++$called;' .
-                       '    if ($called === 1) {' .
-                       '      return array(\'title\' => \'Page 1\');' .
-                       '    }' .
-                       '    if ($called === 2) {' .
-                       '      return array(\'header\' => \'Configuration 2\');' .
-                       '    }' .
-                       '  }' .
-                       '  static public function getRecordTitle() {' .
-                       '    static $called = 0;' .
-                       '    ++$called;' .
-                       '    if ($called === 1) {' .
-                       '      return \'Page 1\';' .
-                       '    }' .
-                       '    if ($called === 2) {' .
-                       '      return \'Configuration 2\';' .
-                       '    }' .
-                       '  }' .
-                       '}'
-               );
-
                $GLOBALS['TCA'] = array(
                        'index_config' => array(
                                'columns' => array(
@@ -257,7 +203,7 @@ class BackendUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                        ),
                );
 
-               $this->assertSame('Page 1, Configuration 2', $subject::getProcessedValue('index_config', 'indexcfgs', 'pages_1,index_config_2'));
+               $this->assertSame('Page 1, Configuration 2', ProcessedValueForGroupWithMultipleAllowedTablesFixture::getProcessedValue('index_config', 'indexcfgs', 'pages_1,index_config_2'));
        }
 
        /**
@@ -309,19 +255,6 @@ class BackendUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                                }
                        ));
 
-               // Disable getRecordTitle dependency by returning stable results
-               /** @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Backend\Utility\BackendUtility $subject */
-               $className = $this->getUniqueId('BackendUtility');
-               $subject = __NAMESPACE__ . '\\' . $className;
-               eval(
-                       'namespace ' . __NAMESPACE__ . ';' .
-                       'class ' . $className . ' extends \\TYPO3\\CMS\\Backend\\Utility\\BackendUtility {' .
-                       '  static public function getRecordTitle($table, $row) {' .
-                       '    return $row["title"];' .
-                       '  }' .
-                       '}'
-               );
-
                $GLOBALS['TCA'] = array(
                        'pages' => array(
                                'columns' => array(
@@ -354,7 +287,7 @@ class BackendUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                        ),
                );
 
-               $this->assertSame('Category 1; Category 2', $subject::getProcessedValue('pages', 'categories', '2', 0, FALSE, FALSE, 1));
+               $this->assertSame('Category 1; Category 2', ProcessedValueForSelectWithMMRelationFixture::getProcessedValue('pages', 'categories', '2', 0, FALSE, FALSE, 1));
        }
 
        /**
@@ -611,22 +544,9 @@ class BackendUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @dataProvider getLabelFromItemListMergedReturnsCorrectFieldsDataProvider
         */
        public function getLabelFromItemListMergedReturnsCorrectFields($pageId, $table, $column = '', $key = '', array $tca, $expectedLabel = '') {
-               // Disable getPagesTSconfig by returning stable result
-               /** @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Backend\Utility\BackendUtility $subject */
-               $className = $this->getUniqueId('BackendUtility');
-               $subject = __NAMESPACE__ . '\\' . $className;
-               eval(
-                       'namespace ' . __NAMESPACE__ . ';' .
-                       'class ' . $className . ' extends \\TYPO3\\CMS\\Backend\\Utility\\BackendUtility {' .
-                       '  static public function getPagesTSconfig() {' .
-                       '    return array();' .
-                       '  }' .
-                       '}'
-               );
-
                $GLOBALS['TCA'][$table] = $tca;
 
-               $this->assertEquals($expectedLabel, $subject::getLabelFromItemListMerged($pageId, $table, $column, $key));
+               $this->assertEquals($expectedLabel, LabelFromItemListMergedReturnsCorrectFieldsFixture::getLabelFromItemListMerged($pageId, $table, $column, $key));
        }
 
        /**
@@ -860,18 +780,6 @@ class BackendUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @dataProvider getExcludeFieldsDataProvider
         */
        public function getExcludeFieldsReturnsCorrectFieldList($tca, $expected) {
-               /** @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Backend\Utility\BackendUtility $subject */
-               $className = $this->getUniqueId('BackendUtility');
-               $subject = __NAMESPACE__ . '\\' . $className;
-               eval(
-                       'namespace ' . __NAMESPACE__ . ';' .
-                       'class ' . $className . ' extends \\TYPO3\\CMS\\Backend\\Utility\\BackendUtility {' .
-                       '  static public function getRegisteredFlexForms() {' .
-                       '    return array();' .
-                       '  }' .
-                       '}'
-               );
-
                $GLOBALS['TCA'] = $tca;
 
                // Stub LanguageService and let sL() return the same value that came in again
@@ -883,7 +791,7 @@ class BackendUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                                }
                        ));
 
-               $this->assertSame($expected, $subject::getExcludeFields());
+               $this->assertSame($expected, ExcludeFieldsReturnsCorrectFieldListFixture::getExcludeFields());
        }
 
        /**
@@ -987,60 +895,7 @@ class BackendUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                                }
                        ));
 
-               /** @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Backend\Utility\BackendUtility $subject */
-               $className = $this->getUniqueId('BackendUtility');
-               $subject = __NAMESPACE__ . '\\' . $className;
-               eval(
-                       'namespace ' . __NAMESPACE__ . ';' .
-                       'class ' . $className . ' extends \\TYPO3\\CMS\\Backend\\Utility\\BackendUtility {' .
-                       '  static public function getRegisteredFlexForms($table) {' .
-                       '    static $called = 0;' .
-                       '    ++$called;' .
-                       '    if ($called === 1) {' .
-                       '      return array();' .
-                       '    }' .
-                       '    if ($called === 2) {' .
-                       '      if ($table !== \'tx_foo\') {' .
-                       '        throw new Exception(\'Expected tx_foo as argument on call 2\', 1399638572);' .
-                       '      }' .
-                       '      $parsedFlexForm = array(' .
-                       '        \'abarfoo\' => array(' .
-                       '          \'dummy\' => array(' .
-                       '            \'title\' => \'dummy\',' .
-                       '            \'ds\' => array(' .
-                       '              \'sheets\' => array(' .
-                       '                \'sGeneral\' => array(' .
-                       '                  \'ROOT\' => array(' .
-                       '                    \'type\' => \'array\',' .
-                       '                    \'el\' => array(' .
-                       '                      \'xmlTitle\' => array(' .
-                       '                        \'TCEforms\' => array(' .
-                       '                          \'exclude\' => 1,' .
-                       '                          \'label\' => \'The Title:\',' .
-                       '                          \'config\' => array(' .
-                       '                            \'type\' => \'input\',' .
-                       '                            \'size\' => 48,' .
-                       '                          ),' .
-                       '                        ),' .
-                       '                      ),' .
-                       '                    ),' .
-                       '                  ),' .
-                       '                ),' .
-                       '              ),' .
-                       '            ),' .
-                       '          ),' .
-                       '        ),' .
-                       '      );' .
-                       '      return $parsedFlexForm;' .
-                       '    }' .
-                       '    if ($called === 3) {' .
-                       '      return array();' .
-                       '    }' .
-                       '  }' .
-                       '}'
-               );
-
-               $this->assertSame($expectedResult, $subject::getExcludeFields());
+               $this->assertSame($expectedResult, ExcludeFieldsReturnsCorrectListWithFlexFormFieldsFixture::getExcludeFields());
        }
 
        /**
diff --git a/typo3/sysext/backend/Tests/Unit/Utility/Fixtures/ExcludeFieldsReturnsCorrectFieldListFixture.php b/typo3/sysext/backend/Tests/Unit/Utility/Fixtures/ExcludeFieldsReturnsCorrectFieldListFixture.php
new file mode 100644 (file)
index 0000000..46e9879
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+namespace TYPO3\CMS\Backend\Tests\Unit\Utility\Fixtures;
+
+/*
+ * 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!
+ */
+
+/**
+ * Disable getRecordWSOL and getRecordTitle dependency by returning stable results
+ */
+class ExcludeFieldsReturnsCorrectFieldListFixture extends \TYPO3\CMS\Backend\Utility\BackendUtility {
+
+       /**
+        * @return array
+        */
+       static public function getRegisteredFlexForms() {
+               return array();
+       }
+}
\ No newline at end of file
diff --git a/typo3/sysext/backend/Tests/Unit/Utility/Fixtures/ExcludeFieldsReturnsCorrectListWithFlexFormFieldsFixture.php b/typo3/sysext/backend/Tests/Unit/Utility/Fixtures/ExcludeFieldsReturnsCorrectListWithFlexFormFieldsFixture.php
new file mode 100644 (file)
index 0000000..244c845
--- /dev/null
@@ -0,0 +1,70 @@
+<?php
+namespace TYPO3\CMS\Backend\Tests\Unit\Utility\Fixtures;
+
+/*
+ * 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!
+ */
+
+/**
+ * Disable getRecordWSOL and getRecordTitle dependency by returning stable results
+ */
+class ExcludeFieldsReturnsCorrectListWithFlexFormFieldsFixture extends \TYPO3\CMS\Backend\Utility\BackendUtility {
+
+       /**
+        * @param string $table
+        * @return array
+        */
+       static public function getRegisteredFlexForms($table) {
+               static $called = 0;
+               ++$called;
+               if ($called === 1) {
+                       return array();
+               }
+               if ($called === 2) {
+                       if ($table !== 'tx_foo') {
+                               throw new Exception('Expected tx_foo as argument on call 2', 1399638572);
+                       }
+                       $parsedFlexForm = array(
+                               'abarfoo' => array(
+                                       'dummy' => array(
+                                               'title' => 'dummy',
+                                               'ds' => array(
+                                                       'sheets' => array(
+                                                               'sGeneral' => array(
+                                                                       'ROOT' => array(
+                                                                               'type' => 'array',
+                                                                               'el' => array(
+                                                                                       'xmlTitle' => array(
+                                                                                               'TCEforms' => array(
+                                                                                                       'exclude' => 1,
+                                                                                                       'label' => 'The Title:',
+                                                                                                       'config' => array(
+                                                                                                               'type' => 'input',
+                                                                                                               'size' => 48,
+                                                                                                       ),
+                                                                                               ),
+                                                                                       ),
+                                                                               ),
+                                                                       ),
+                                                               ),
+                                                       ),
+                                               ),
+                                       ),
+                               ),
+                       );
+                       return $parsedFlexForm;
+               }
+               if ($called === 3) {
+                       return array();
+               }
+       }
+}
\ No newline at end of file
diff --git a/typo3/sysext/backend/Tests/Unit/Utility/Fixtures/LabelFromItemListMergedReturnsCorrectFieldsFixture.php b/typo3/sysext/backend/Tests/Unit/Utility/Fixtures/LabelFromItemListMergedReturnsCorrectFieldsFixture.php
new file mode 100644 (file)
index 0000000..e8faf6f
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+namespace TYPO3\CMS\Backend\Tests\Unit\Utility\Fixtures;
+
+/*
+ * 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!
+ */
+
+/**
+ * Disable getRecordWSOL and getRecordTitle dependency by returning stable results
+ */
+class LabelFromItemListMergedReturnsCorrectFieldsFixture extends \TYPO3\CMS\Backend\Utility\BackendUtility {
+
+       /**
+        * @return array
+        */
+       static public function getPagesTSconfig() {
+               return array();
+       }
+}
\ No newline at end of file
diff --git a/typo3/sysext/backend/Tests/Unit/Utility/Fixtures/ProcessedValueForGroupWithMultipleAllowedTablesFixture.php b/typo3/sysext/backend/Tests/Unit/Utility/Fixtures/ProcessedValueForGroupWithMultipleAllowedTablesFixture.php
new file mode 100644 (file)
index 0000000..7647760
--- /dev/null
@@ -0,0 +1,49 @@
+<?php
+namespace TYPO3\CMS\Backend\Tests\Unit\Utility\Fixtures;
+
+/*
+ * 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!
+ */
+
+/**
+ * Disable getRecordWSOL and getRecordTitle dependency by returning stable results
+ */
+class ProcessedValueForGroupWithMultipleAllowedTablesFixture extends \TYPO3\CMS\Backend\Utility\BackendUtility {
+
+       /**
+        * Get record WSOL
+        */
+       static public function getRecordWSOL() {
+               static $called = 0;
+               ++$called;
+               if ($called === 1) {
+                       return array('title' => 'Page 1');
+               }
+               if ($called === 2) {
+                       return array('header' => 'Configuration 2');
+               }
+       }
+
+       /**
+        * Get record title
+        */
+       static public function getRecordTitle() {
+               static $called = 0;
+               ++$called;
+               if ($called === 1) {
+                       return 'Page 1';
+               }
+               if ($called === 2) {
+                       return 'Configuration 2';
+               }
+       }
+}
\ No newline at end of file
diff --git a/typo3/sysext/backend/Tests/Unit/Utility/Fixtures/ProcessedValueForGroupWithOneAllowedTableFixture.php b/typo3/sysext/backend/Tests/Unit/Utility/Fixtures/ProcessedValueForGroupWithOneAllowedTableFixture.php
new file mode 100644 (file)
index 0000000..985d23c
--- /dev/null
@@ -0,0 +1,49 @@
+<?php
+namespace TYPO3\CMS\Backend\Tests\Unit\Utility\Fixtures;
+
+/*
+ * 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!
+ */
+
+/**
+ * Disable getRecordWSOL and getRecordTitle dependency by returning stable results
+ */
+class ProcessedValueForGroupWithOneAllowedTableFixture extends \TYPO3\CMS\Backend\Utility\BackendUtility {
+
+       /**
+        * Get record WSOL
+        */
+       static public function getRecordWSOL() {
+               static $called = 0;
+               ++$called;
+               if ($called === 1) {
+                       return array('title' => 'Page 1');
+               }
+               if ($called === 2) {
+                       return array('title' => 'Page 2');
+               }
+       }
+
+       /**
+        * Get record title
+        */
+       static public function getRecordTitle() {
+               static $called = 0;
+               ++$called;
+               if ($called === 1) {
+                       return 'Page 1';
+               }
+               if ($called === 2) {
+                       return 'Page 2';
+               }
+       }
+}
\ No newline at end of file
diff --git a/typo3/sysext/backend/Tests/Unit/Utility/Fixtures/ProcessedValueForSelectWithMMRelationFixture.php b/typo3/sysext/backend/Tests/Unit/Utility/Fixtures/ProcessedValueForSelectWithMMRelationFixture.php
new file mode 100644 (file)
index 0000000..9dd6b63
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+namespace TYPO3\CMS\Backend\Tests\Unit\Utility\Fixtures;
+
+/*
+ * 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!
+ */
+
+/**
+ * Disable getRecordWSOL and getRecordTitle dependency by returning stable results
+ */
+class ProcessedValueForSelectWithMMRelationFixture extends \TYPO3\CMS\Backend\Utility\BackendUtility {
+
+       /**
+        * Get record title
+        *
+        * @param string $table
+        * @param array $row
+        *
+        * @return string
+        */
+       static public function getRecordTitle($table, $row) {
+               return $row['title'];
+       }
+}
\ No newline at end of file