[TASK] Split DataHandler::copyRecord_procBasedOnFieldType
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / FunctionalTestCase.php
index 6b5d0e7..34e8535 100644 (file)
@@ -1,30 +1,20 @@
 <?php
 namespace TYPO3\CMS\Core\Tests;
 
-/***************************************************************
- * Copyright notice
+/*
+ * This file is part of the TYPO3 CMS project.
  *
- * (c) 2013 Christian Kuhn <lolli@schwarzbu.ch>
- * All rights reserved
+ * 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.
  *
- * This script is part of the TYPO3 project. The TYPO3 project is
- * free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
  *
- * The GNU General Public License can be found at
- * http://www.gnu.org/copyleft/gpl.html.
- *
- * This script is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * This copyright notice MUST APPEAR in all copies of the script!
- ***************************************************************/
+ * The TYPO3 project - inspiring people to share!
+ */
 
-use \TYPO3\CMS\Core\Tests\Functional\Framework\Frontend\Response;
+use TYPO3\CMS\Core\Tests\Functional\Framework\Frontend\Response;
 
 /**
  * Base test case class for functional tests, all TYPO3 CMS
@@ -183,7 +173,7 @@ abstract class FunctionalTestCase extends BaseTestCase {
         *
         * @return void
         */
-       public function setUp() {
+       protected function setUp() {
                if (!defined('ORIGINAL_ROOT')) {
                        $this->markTestSkipped('Functional tests must be called through phpunit on CLI');
                }
@@ -220,12 +210,12 @@ abstract class FunctionalTestCase extends BaseTestCase {
        protected function setUpBackendUserFromFixture($userUid) {
                $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/core/Tests/Functional/Fixtures/be_users.xml');
                $database = $this->getDatabaseConnection();
-               $userRow = $database->exec_SELECTgetSingleRow('*', 'be_users', 'uid = ' . $userUid);
+               $userRow = $database->exec_SELECTgetSingleRow('*', 'be_users', 'uid = ' . (int)$userUid);
 
                /** @var $backendUser \TYPO3\CMS\Core\Authentication\BackendUserAuthentication */
-               $backendUser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Authentication\\BackendUserAuthentication');
+               $backendUser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Authentication\BackendUserAuthentication::class);
                $sessionId = $backendUser->createSessionId();
-               $_SERVER['HTTP_COOKIE'] = 'be_typo_user=' . $sessionId . '; path=/';
+               $_COOKIE['be_typo_user'] = $sessionId;
                $backendUser->id = $sessionId;
                $backendUser->sendNoCacheHeaders = FALSE;
                $backendUser->dontSetCookie = TRUE;
@@ -279,7 +269,7 @@ abstract class FunctionalTestCase extends BaseTestCase {
                                } elseif (isset($column['is-NULL']) && ($column['is-NULL'] === 'yes')) {
                                        $columnValue = NULL;
                                } else {
-                                       $columnValue = (string) $table->$columnName;
+                                       $columnValue = (string)$table->$columnName;
                                }
 
                                $insertArray[$columnName] = $columnValue;
@@ -289,12 +279,12 @@ abstract class FunctionalTestCase extends BaseTestCase {
                        $result = $database->exec_INSERTquery($tableName, $insertArray);
                        if ($result === FALSE) {
                                throw new Exception(
-                                       'Error when processing fixture file: ' . $path . ' Can not insert data to table ' . $tableName,
+                                       'Error when processing fixture file: ' . $path . ' Can not insert data to table ' . $tableName . ': ' . $database->sql_error(),
                                        1376746262
                                );
                        }
                        if (isset($table['id'])) {
-                               $elementId = (string) $table['id'];
+                               $elementId = (string)$table['id'];
                                $foreignKeys[$tableName][$elementId] = $database->sql_insert_id();
                        }
                }
@@ -339,30 +329,18 @@ abstract class FunctionalTestCase extends BaseTestCase {
         * @param int $backendUserId
         * @param int $workspaceId
         * @param bool $failOnFailure
+        * @param int $frontendUserId
         * @return Response
         */
-       protected function getFrontendResponse($pageId, $languageId = 0, $backendUserId = 0, $workspaceId = 0, $failOnFailure = TRUE) {
+       protected function getFrontendResponse($pageId, $languageId = 0, $backendUserId = 0, $workspaceId = 0, $failOnFailure = TRUE, $frontendUserId = 0) {
                $pageId = (int)$pageId;
                $languageId = (int)$languageId;
 
-               $phpExecutable = 'php';
-               if (defined('PHP_BINARY')) {
-                       $phpExecutable = PHP_BINARY;
-               } elseif (TYPO3_OS !== 'WIN' && defined('PHP_BINDIR')) {
-                       $phpExecutable = rtrim(PHP_BINDIR, '/') . '/php';
-               } else {
-                       foreach(explode(';', $_SERVER['Path']) as $path) {
-                               $path = rtrim(strtr($path, '\\', '/'), '/') . '/';
-                               $phpFile = 'php' . (TYPO3_OS === 'WIN' ? '.exe' : '');
-                               if (file_exists($path . $phpFile) && is_file($path . $phpFile)) {
-                                       $phpExecutable = $path . $phpFile;
-                                       break;
-                               }
-                       }
-               }
-
                $additionalParameter = '';
 
+               if (!empty($frontendUserId)) {
+                       $additionalParameter .= '&frontendUserId=' . (int)$frontendUserId;
+               }
                if (!empty($backendUserId)) {
                        $additionalParameter .= '&backendUserId=' . (int)$backendUserId;
                }
@@ -375,25 +353,19 @@ abstract class FunctionalTestCase extends BaseTestCase {
                        'requestUrl' => 'http://localhost/?id=' . $pageId . '&L=' . $languageId . $additionalParameter,
                );
 
-               if (TYPO3_OS !== 'WIN') {
-                       $commandParts = array(
-                               escapeshellcmd($phpExecutable),
-                               escapeshellarg(ORIGINAL_ROOT . 'typo3/sysext/core/Tests/Functional/Framework/Scripts/Request.php'),
-                               escapeshellarg(json_encode($arguments)),
-                       );
-               } else {
-                       $commandParts = array(
-                               escapeshellcmd($phpExecutable),
-                               escapeshellarg(ORIGINAL_ROOT . 'typo3/sysext/core/Tests/Functional/Framework/Scripts/Request.php'),
-                               strtr(escapeshellarg(strtr(json_encode($arguments), array('&' => '^&', '"' => '"""'))), '   ', '"""'),
-                       );
-               }
+               $template = new \Text_Template(ORIGINAL_ROOT . 'typo3/sysext/core/Tests/Functional/Fixtures/Frontend/request.tpl');
+               $template->setVar(
+                       array(
+                               'arguments' => var_export($arguments, TRUE),
+                               'originalRoot' => ORIGINAL_ROOT,
+                       )
+               );
 
-               $command = trim(implode(' ', $commandParts));
-               $response = shell_exec($command);
-               $result = json_decode($response, TRUE);
+               $php = \PHPUnit_Util_PHP::factory();
+               $response = $php->runJob($template->render());
+               $result = json_decode($response['stdout'], TRUE);
 
-               if ($result === FALSE) {
+               if ($result === NULL) {
                        $this->fail('Frontend Response is empty');
                }