[BUGFIX] Tests: improve Mocking in ext:extbase 70/28370/3
authorAnja Leichsenring <aleichsenring@ab-softlab.de>
Thu, 13 Mar 2014 22:31:53 +0000 (23:31 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Fri, 14 Mar 2014 07:58:41 +0000 (08:58 +0100)
Unittests reveal some warnings which are caused by incomplete mocking.

Change-Id: I42089bb6c9016187d83382a2fa10450310993a84
Resolves: #56700
Related: #51436
Releases: 6.2
Reviewed-on: https://review.typo3.org/28370
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/extbase/Tests/Unit/Scheduler/FieldProviderTest.php

index 1106418..354f05e 100644 (file)
@@ -108,7 +108,18 @@ class FieldProviderTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
         * @author Stefan Neufeind <info@speedpartner.de>
         */
        public function getCommandControllerActionFieldFetchesCorrectClassNames() {
-               $actualResult = $this->fieldProvider->_call('getCommandControllerActionField', array());
+               $fieldProvider = $this->getAccessibleMock(
+                       '\TYPO3\CMS\Extbase\Scheduler\FieldProvider',
+                       array('getActionLabel'),
+                       array(),
+                       '',
+                       FALSE
+               );
+               $fieldProvider->_set('objectManager', $this->objectManager);
+               $fieldProvider->_set('commandManager', $this->commandManager);
+               $fieldProvider->_set('reflectionService', $this->objectManager->get('TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService'));
+               $fieldProvider->expects($this->once())->method('getActionLabel')->will($this->returnValue('some label'));
+               $actualResult = $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']);
@@ -134,7 +145,9 @@ class FieldProviderTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
         */
        public function validateAdditionalFieldsReturnsTrue() {
                $submittedData = array();
-               $this->assertTrue($this->fieldProvider->validateAdditionalFields($submittedData, new \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController()));
+               /** @var \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $schedulerModule */
+               $schedulerModule = $this->getMock('TYPO3\\CMS\\Scheduler\\Controller\\SchedulerModuleController', array(), array(), '', FALSE);
+               $this->assertTrue($this->fieldProvider->validateAdditionalFields($submittedData, $schedulerModule));
        }
 
        /**
@@ -142,6 +155,20 @@ class FieldProviderTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
         * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
         */
        public function getAdditionalFieldsRendersRightHtml() {
+               $fieldProvider = $this->getAccessibleMock(
+                       '\TYPO3\CMS\Extbase\Scheduler\FieldProvider',
+                       array('getActionLabel', 'getArgumentLabel'),
+                       array(),
+                       '',
+                       FALSE
+               );
+               $fieldProvider->_set('objectManager', $this->objectManager);
+               $fieldProvider->_set('commandManager', $this->commandManager);
+               $fieldProvider->_set('reflectionService', $this->objectManager->get('TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService'));
+               $actionLabel = 'action label string';
+               $argumentLabel = 'argument label string';
+               $fieldProvider->expects($this->any())->method('getActionLabel')->will($this->returnValue($actionLabel));
+               $fieldProvider->expects($this->any())->method('getArgumentLabel')->will($this->returnValue($argumentLabel));
                $expectedAdditionalFields = array(
                        'action' => array(
                                'code' => '<select name="tx_scheduler[task_extbase][action]">' . LF
@@ -149,7 +176,7 @@ class FieldProviderTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
                                        . '<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>'
+                               'label' => $actionLabel
                        ),
                        'description' => array(
                                'code' => '',
@@ -157,15 +184,16 @@ class FieldProviderTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
                        ),
                        'arg' => array(
                                'code' => '<input type="text" name="tx_scheduler[task_extbase][arguments][arg]" value="1" /> ',
-                               'label' => 'Argument: arg. <em>A not required argument</em>'
+                               'label' => $argumentLabel
                        )
                );
 
                $taskInfo = array();
                $task = new \TYPO3\CMS\Extbase\Scheduler\Task();
                $task->setCommandIdentifier($this->command1->getCommandIdentifier());
-               $schedulerModule = new \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController();
+               /** @var \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $schedulerModule */
+               $schedulerModule = $this->getMock('TYPO3\\CMS\\Scheduler\\Controller\\SchedulerModuleController', array(), array(), '', FALSE);
 
-               $this->assertEquals($expectedAdditionalFields, $this->fieldProvider->getAdditionalFields($taskInfo, $task, $schedulerModule));
+               $this->assertEquals($expectedAdditionalFields, $fieldProvider->getAdditionalFields($taskInfo, $task, $schedulerModule));
        }
 }