[TASK] Improve code coverage of Scheduler/FieldProvider
authorAlexander Schnitzler <alex.schnitzler@typovision.de>
Fri, 18 Jan 2013 15:57:01 +0000 (16:57 +0100)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Sat, 19 Jan 2013 14:10:15 +0000 (15:10 +0100)
* Also fixed a small bug in Cli/Command.php

Releases: 6.1
Resolves: #44650
Change-Id: Ic9cc4ebb81a3926415223f6a7a8078198a39f1ab
Reviewed-on: https://review.typo3.org/17592
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
typo3/sysext/extbase/Classes/Mvc/Cli/Command.php
typo3/sysext/extbase/Tests/Unit/Scheduler/FieldProviderTest.php
typo3/sysext/extbase/Tests/Unit/Scheduler/Fixtures/MockACommandController.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Scheduler/Fixtures/MockBCommandController.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Scheduler/Fixtures/MockCCommandController.php [new file with mode: 0644]

index bad6116..3f121ca 100644 (file)
@@ -3,10 +3,10 @@ namespace TYPO3\CMS\Extbase\Mvc\Cli;
 
 /***************************************************************
  *  Copyright notice
- *  All rights reserved
  *
- *  This class is a backport of the corresponding class of TYPO3 Flow.
- *  All credits go to the TYPO3 Flow team.
+ *  (c) 2010-2012 Extbase Team (http://forge.typo3.org/projects/typo3v4-mvc)
+ *  Extbase is a backport of TYPO3 Flow. All credits go to the TYPO3 Flow team.
+ *  All rights reserved
  *
  *  This script is part of the TYPO3 project. The TYPO3 project is
  *  free software; you can redistribute it and/or modify
@@ -16,6 +16,9 @@ namespace TYPO3\CMS\Extbase\Mvc\Cli;
  *
  *  The GNU General Public License can be found at
  *  http://www.gnu.org/copyleft/gpl.html.
+ *  A copy is found in the textfile GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
+ *
  *
  *  This script is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -144,7 +147,7 @@ class Command {
         */
        public function getDescription() {
                $lines = explode(chr(10), $this->getCommandMethodReflection()->getDescription());
-               array_shift($lines);
+               array_pop($lines);
                $descriptionLines = array();
                foreach ($lines as $line) {
                        $trimmedLine = trim($line);
index d1d1ffb..06727b6 100644 (file)
@@ -1,10 +1,15 @@
 <?php
 namespace TYPO3\CMS\Extbase\Tests\Unit\Scheduler;
 
+require_once (__DIR__ . '/Fixtures/MockACommandController.php');
+require_once (__DIR__ . '/Fixtures/MockBCommandController.php');
+require_once (__DIR__ . '/Fixtures/MockCCommandController.php');
+
 /***************************************************************
  *  Copyright notice
  *
- *  (c) 2012 Stefan Neufeind <info@speedpartner.de>
+ *  (c) 2010-2012 Extbase Team (http://forge.typo3.org/projects/typo3v4-mvc)
+ *  Extbase is a backport of TYPO3 Flow. All credits go to the TYPO3 Flow team.
  *  All rights reserved
  *
  *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -15,6 +20,9 @@ namespace TYPO3\CMS\Extbase\Tests\Unit\Scheduler;
  *
  *  The GNU General Public License can be found at
  *  http://www.gnu.org/copyleft/gpl.html.
+ *  A copy is found in the textfile GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
+ *
  *
  *  This script is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -29,47 +37,83 @@ namespace TYPO3\CMS\Extbase\Tests\Unit\Scheduler;
 class FieldProviderTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
 
        /**
-        * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
+        * @var \TYPO3\CMS\Extbase\Object\ObjectManager|\PHPUnit_Framework_MockObject_MockObject
+        */
+       protected $objectManager;
+
+       /**
+        * @var \TYPO3\CMS\Extbase\Mvc\Cli\Command|\PHPUnit_Framework_MockObject_MockObject
         */
-       protected $mockObjectManager;
+       protected $command1;
 
        /**
-        * @var \TYPO3\CMS\Extbase\Mvc\Cli\CommandManager
+        * @var \TYPO3\CMS\Extbase\Mvc\Cli\Command|\PHPUnit_Framework_MockObject_MockObject
+        */
+       protected $command2;
+
+       /**
+        * @var \TYPO3\CMS\Extbase\Mvc\Cli\Command|\PHPUnit_Framework_MockObject_MockObject
+        */
+       protected $command3;
+
+       /**
+        * @var \TYPO3\CMS\Extbase\Mvc\Cli\CommandManager|\PHPUnit_Framework_MockObject_MockObject
         */
        protected $commandManager;
 
        /**
-        * @var \TYPO3\CMS\Extbase\Scheduler\FieldProvider
+        * @var \TYPO3\CMS\Extbase\Scheduler\FieldProvider|\PHPUnit_Framework_MockObject_MockObject|\Tx_Phpunit_Interface_AccessibleObject
         */
        protected $fieldProvider;
 
+       public function setUp() {
+               $this->objectManager = $this->getMock('TYPO3\CMS\Extbase\Object\ObjectManager', array('dummy'));
+               $this->commandManager = $this->getMock('TYPO3\CMS\Extbase\Mvc\Cli\CommandManager', array('getAvailableCommands'));
+
+               $this->fieldProvider = $this->getAccessibleMock(
+                       '\TYPO3\CMS\Extbase\Scheduler\FieldProvider',
+                       array('dummy'),
+                       array(),
+                       '',
+                       FALSE
+               );
+
+               $this->command1 = $this->getMock('TYPO3\CMS\Extbase\Mvc\Cli\Command', array('isInternal'), array('TYPO3\\CMS\\Extbase\\Tests\\MockACommandController', 'FuncA'));
+               $this->command1->injectObjectManager($this->objectManager);
+               $this->command1->injectReflectionService($this->objectManager->get('TYPO3\CMS\Extbase\Reflection\ReflectionService'));
+               $this->command1->expects($this->any())->method('isInternal')->will($this->returnValue(FALSE));
+
+               $this->command2 = $this->getMock('TYPO3\CMS\Extbase\Mvc\Cli\Command', array('isInternal'), array('Acme\\Mypkg\\Command\\MockBCommandController', 'FuncB'));
+               $this->command2->injectObjectManager($this->objectManager);
+               $this->command2->injectReflectionService($this->objectManager->get('TYPO3\CMS\Extbase\Reflection\ReflectionService'));
+               $this->command2->expects($this->any())->method('isInternal')->will($this->returnValue(FALSE));
+
+               $this->command3 = $this->getMock('TYPO3\CMS\Extbase\Mvc\Cli\Command', array('isInternal'), array('Tx_Extbase_Command_MockCCommandController', 'FuncC'));
+               $this->command3->injectObjectManager($this->objectManager);
+               $this->command3->injectReflectionService($this->objectManager->get('TYPO3\CMS\Extbase\Reflection\ReflectionService'));
+               $this->command3->expects($this->any())->method('isInternal')->will($this->returnValue(FALSE));
+
+               $this->commandManager->expects($this->any())->method('getAvailableCommands')->will($this->returnValue(array($this->command1, $this->command2, $this->command3)));
+
+               $this->fieldProvider->_set('objectManager', $this->objectManager);
+               $this->fieldProvider->_set('commandManager', $this->commandManager);
+               $this->fieldProvider->_set('reflectionService', $this->objectManager->get('TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService'));
+       }
+
        /**
-        *
         * @test
+        * @author Stefan Neufeind <info@speedpartner.de>
         */
        public function getCommandControllerActionFieldFetchesCorrectClassNames() {
-               $fieldProvider = $fieldProvider = $this->getMock($this->buildAccessibleProxy('\TYPO3\CMS\Extbase\Scheduler\FieldProvider'), array('dummy'));
-               $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['extbase']['commandControllers'] = array(
-                       'TYPO3\\CMS\\Extbase\\Tests\\MockACommandController',
-                       'Acme\\Mypkg\\Command\\MockCCommandController',
-                       'Tx_Extbase_Command_MockDCommandController'
-               );
-               eval('
-                       namespace TYPO3\\CMS\\Extbase\\Tests; class MockACommandController extends \TYPO3\CMS\Extbase\Mvc\Controller\CommandController { function mockBCommand() {} }
-                       namespace Acme\\Mypkg\\Command; class MockCCommandController extends \TYPO3\CMS\Extbase\Mvc\Controller\CommandController { function mockBCommand() {} }
-               ');
-               eval('
-                       class Tx_Extbase_Command_MockDCommandController extends Tx_Extbase_MVC_Controller_CommandController { function mockBCommand() {} }
-               ');
-
-               $actualResult = $fieldProvider->_call('getCommandControllerActionField', array());
-               $this->assertContains('<option title="test" value="extbase:mocka:mockb">Extbase MockA: mockB</option>', $actualResult['code']);
-               $this->assertContains('<option title="test" value="mypkg:mockc:mockb">Mypkg MockC: mockB</option>', $actualResult['code']);
-               $this->assertContains('<option title="test" value="extbase:mockd:mockb">Extbase MockD: mockB</option>', $actualResult['code']);
+               $actualResult = $this->fieldProvider->_call('getCommandControllerActionField', array());
+               $this->assertContains('<option title="test" value="extbase:mocka:funca">Extbase MockA: FuncA</option>', $actualResult['code']);
+               $this->assertContains('<option title="test" value="mypkg:mockb:funcb">Mypkg MockB: FuncB</option>', $actualResult['code']);
+               $this->assertContains('<option title="test" value="extbase:mockc:funcc">Extbase MockC: FuncC</option>', $actualResult['code']);
        }
 
        /**
         * @test
+        * @author Stefan Neufeind <info@speedpartner.de>
         */
        public function constructResolvesExtensionnameFromNamespaced() {
                $className = uniqid('DummyController');
@@ -80,6 +124,47 @@ class FieldProviderTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
                $actualResult = $mockController->getExtensionName();
                $this->assertSame($expectedResult, $actualResult);
        }
+
+       /**
+        * @test
+        * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
+        */
+       public function validateAdditionalFieldsReturnsTrue() {
+               $submittedData = array();
+               $this->assertTrue($this->fieldProvider->validateAdditionalFields($submittedData, new \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController()));
+       }
+
+       /**
+        * @test
+        * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
+        */
+       public function getAdditionalFieldsRendersRightHtml() {
+               $expectedAdditionalFields = array(
+                       'action' => array(
+                               'code' => '<select name="tx_scheduler[task_extbase][action]">' . LF
+                                       . '<option title="test" value="extbase:mocka:funca" selected="selected">Extbase MockA: FuncA</option>' . LF
+                                       . '<option title="test" value="mypkg:mockb:funcb">Mypkg MockB: FuncB</option>' . LF
+                                       . '<option title="test" value="extbase:mockc:funcc">Extbase MockC: FuncC</option>' . LF
+                                       . '</select>',
+                               'label' => 'CommandController Command. <em>Save and reopen to define command arguments</em>'
+                       ),
+                       'description' => array(
+                               'code' => '',
+                               'label' => '<strong></strong>'
+                       ),
+                       'arg' => array(
+                               'code' => '<input type="text" name="tx_scheduler[task_extbase][arguments][arg]" value="1" /> ',
+                               'label' => 'Argument: arg. <em>A not required argument</em>'
+                       )
+               );
+
+               $taskInfo = array();
+               $task = new \TYPO3\CMS\Extbase\Scheduler\Task();
+               $task->setCommandIdentifier($this->command1->getCommandIdentifier());
+               $schedulerModule = new \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController();
+
+               $this->assertEquals($expectedAdditionalFields, $this->fieldProvider->getAdditionalFields($taskInfo, $task, $schedulerModule));
+       }
 }
 
 ?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Scheduler/Fixtures/MockACommandController.php b/typo3/sysext/extbase/Tests/Unit/Scheduler/Fixtures/MockACommandController.php
new file mode 100644 (file)
index 0000000..b2da690
--- /dev/null
@@ -0,0 +1,44 @@
+<?php
+namespace TYPO3\CMS\Extbase\Tests;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2010-2012 Extbase Team (http://forge.typo3.org/projects/typo3v4-mvc)
+ *  Extbase is a backport of TYPO3 Flow. All credits go to the TYPO3 Flow team.
+ *  All rights reserved
+ *
+ *  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.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *  A copy is found in the textfile GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
+ *
+ *
+ *  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!
+ ***************************************************************/
+/**
+ * MockACommandController Fixture
+ */
+class MockACommandController extends \TYPO3\CMS\Extbase\Mvc\Controller\CommandController {
+
+       /**
+        * funcACommand
+        *
+        * @param integer $arg A not required argument
+        */
+       public function funcACommand($arg = 1) {
+       }
+}
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Scheduler/Fixtures/MockBCommandController.php b/typo3/sysext/extbase/Tests/Unit/Scheduler/Fixtures/MockBCommandController.php
new file mode 100644 (file)
index 0000000..dfe5310
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+namespace Acme\Mypkg\Command;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2010-2012 Extbase Team (http://forge.typo3.org/projects/typo3v4-mvc)
+ *  Extbase is a backport of TYPO3 Flow. All credits go to the TYPO3 Flow team.
+ *  All rights reserved
+ *
+ *  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.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *  A copy is found in the textfile GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
+ *
+ *
+ *  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!
+ ***************************************************************/
+/**
+ * MockBCommandController Fixture
+ */
+class MockBCommandController extends \TYPO3\CMS\Extbase\Mvc\Controller\CommandController {
+
+       /**
+        * funcBCommand
+        */
+       public function funcBCommand() {
+       }
+}
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Scheduler/Fixtures/MockCCommandController.php b/typo3/sysext/extbase/Tests/Unit/Scheduler/Fixtures/MockCCommandController.php
new file mode 100644 (file)
index 0000000..22e8db7
--- /dev/null
@@ -0,0 +1,41 @@
+<?php
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2010-2012 Extbase Team (http://forge.typo3.org/projects/typo3v4-mvc)
+ *  Extbase is a backport of TYPO3 Flow. All credits go to the TYPO3 Flow team.
+ *  All rights reserved
+ *
+ *  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.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *  A copy is found in the textfile GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
+ *
+ *
+ *  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!
+ ***************************************************************/
+/**
+ * MockCCommandController Fixture
+ */
+class Tx_Extbase_Command_MockCCommandController extends \TYPO3\CMS\Extbase\Mvc\Controller\CommandController {
+
+       /**
+        * funcCCommand
+        */
+       public function funcCCommand() {
+       }
+}
+
+?>
\ No newline at end of file