TYPO3 CMS  TYPO3_6-2
FieldProviderTest.php
Go to the documentation of this file.
1 <?php
3 
21 
25  public function getCommandControllerActionFieldFetchesCorrectClassNames() {
26 
28  $command1 = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Cli\\Command', array(), array(), '', FALSE);
29  $command1->expects($this->once())->method('isInternal')->will($this->returnValue(FALSE));
30  $command1->expects($this->once())->method('getControllerClassName')->will($this->returnValue('TYPO3\\CMS\\Extbase\\Tests\\MockACommandController'));
31  $command1->expects($this->once())->method('getControllerCommandName')->will($this->returnValue('FuncA'));
32  $command1->expects($this->once())->method('getCommandIdentifier')->will($this->returnValue('extbase:mocka:funca'));
33 
35  $command2 = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Cli\\Command', array(), array(), '', FALSE);
36  $command2->expects($this->once())->method('isInternal')->will($this->returnValue(FALSE));
37  $command2->expects($this->once())->method('getControllerClassName')->will($this->returnValue('Acme\\Mypkg\\Command\\MockBCommandController'));
38  $command2->expects($this->once())->method('getControllerCommandName')->will($this->returnValue('FuncB'));
39  $command2->expects($this->once())->method('getCommandIdentifier')->will($this->returnValue('mypkg:mockb:funcb'));
40 
42  $command3 = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Cli\\Command', array(), array(), '', FALSE);
43  $command3->expects($this->once())->method('isInternal')->will($this->returnValue(FALSE));
44  $command3->expects($this->once())->method('getControllerClassName')->will($this->returnValue('Tx_Extbase_Command_MockCCommandController'));
45  $command3->expects($this->once())->method('getControllerCommandName')->will($this->returnValue('FuncC'));
46  $command3->expects($this->once())->method('getCommandIdentifier')->will($this->returnValue('extbase:mockc:funcc'));
47 
49  $commandManager = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Cli\\CommandManager', array('getAvailableCommands'));
50  $commandManager->expects($this->any())->method('getAvailableCommands')->will($this->returnValue(array($command1, $command2, $command3)));
51 
53  $fieldProvider = $this->getAccessibleMock(
54  '\TYPO3\CMS\Extbase\Scheduler\FieldProvider',
55  array('getActionLabel'),
56  array(),
57  '',
58  FALSE
59  );
60  $fieldProvider->_set('commandManager', $commandManager);
61  $fieldProvider->expects($this->once())->method('getActionLabel')->will($this->returnValue('some label'));
62  $actualResult = $fieldProvider->_call('getCommandControllerActionField', array());
63  $this->assertContains('<option title="test" value="extbase:mocka:funca">Extbase MockA: FuncA</option>', $actualResult['code']);
64  $this->assertContains('<option title="test" value="mypkg:mockb:funcb">Mypkg MockB: FuncB</option>', $actualResult['code']);
65  $this->assertContains('<option title="test" value="extbase:mockc:funcc">Extbase MockC: FuncC</option>', $actualResult['code']);
66  }
67 
73  $className = $this->getUniqueId('DummyController');
74  eval('namespace ' . __NAMESPACE__ . '; class ' . $className . ' extends \\TYPO3\\CMS\\Extbase\\Mvc\\Controller\\AbstractController { function getExtensionName() { return $this->extensionName; } }');
75  $classNameNamespaced = __NAMESPACE__ . '\\' . $className;
76  $mockController = new $classNameNamespaced();
77  $expectedResult = 'Extbase';
78  $actualResult = $mockController->getExtensionName();
79  $this->assertSame($expectedResult, $actualResult);
80  }
81 
86  public function validateAdditionalFieldsReturnsTrue() {
88  $fieldProvider = $this->getAccessibleMock(
89  '\TYPO3\CMS\Extbase\Scheduler\FieldProvider',
90  array('dummy'),
91  array(),
92  '',
93  FALSE
94  );
95  $submittedData = array();
97  $schedulerModule = $this->getMock('TYPO3\\CMS\\Scheduler\\Controller\\SchedulerModuleController', array(), array(), '', FALSE);
98  $this->assertTrue($fieldProvider->validateAdditionalFields($submittedData, $schedulerModule));
99  }
100 
105  public function getAdditionalFieldsRendersRightHtml() {
106  $this->markTestSkipped('Incomplete mocking in a complex scenario. This should be a functional test');
107 
109  $command1 = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Cli\\Command', array(), array(), '', FALSE);
110  $command1->expects($this->once())->method('isInternal')->will($this->returnValue(FALSE));
111  $command1->expects($this->once())->method('getControllerClassName')->will($this->returnValue('TYPO3\\CMS\\Extbase\\Tests\\MockACommandController'));
112  $command1->expects($this->once())->method('getControllerCommandName')->will($this->returnValue('FuncA'));
113  $command1->expects($this->any())->method('getCommandIdentifier')->will($this->returnValue('extbase:mocka:funca'));
114  $command1->expects($this->once())->method('getArgumentDefinitions')->will($this->returnValue(array()));
115 
117  $command2 = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Cli\\Command', array(), array(), '', FALSE);
118  $command2->expects($this->once())->method('isInternal')->will($this->returnValue(FALSE));
119  $command2->expects($this->once())->method('getControllerClassName')->will($this->returnValue('Acme\\Mypkg\\Command\\MockBCommandController'));
120  $command2->expects($this->once())->method('getControllerCommandName')->will($this->returnValue('FuncB'));
121  $command2->expects($this->any())->method('getCommandIdentifier')->will($this->returnValue('mypkg:mockb:funcb'));
122 
124  $command3 = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Cli\\Command', array(), array(), '', FALSE);
125  $command3->expects($this->once())->method('isInternal')->will($this->returnValue(FALSE));
126  $command3->expects($this->once())->method('getControllerClassName')->will($this->returnValue('Tx_Extbase_Command_MockCCommandController'));
127  $command3->expects($this->once())->method('getControllerCommandName')->will($this->returnValue('FuncC'));
128  $command3->expects($this->any())->method('getCommandIdentifier')->will($this->returnValue('extbase:mockc:funcc'));
129 
131  $commandManager = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Cli\\CommandManager', array('getAvailableCommands'));
132  $commandManager->expects($this->any())->method('getAvailableCommands')->will($this->returnValue(array($command1, $command2, $command3)));
133 
135  $fieldProvider = $this->getAccessibleMock(
136  '\TYPO3\CMS\Extbase\Scheduler\FieldProvider',
137  array('getActionLabel', 'getArgumentLabel', 'getCommandControllerActionArgumentFields'),
138  array(),
139  '',
140  FALSE
141  );
142  $fieldProvider->_set('commandManager', $commandManager);
143  $actionLabel = 'action label string';
144  $argumentLabel = 'argument label string';
145  $fieldProvider->expects($this->any())->method('getActionLabel')->will($this->returnValue($actionLabel));
146  $fieldProvider->expects($this->any())->method('getArgumentLabel')->will($this->returnValue($argumentLabel));
147  $argArray['arg'] = array(
148  'code' => '<input type="text" name="tx_scheduler[task_extbase][arguments][arg]" value="1" /> ',
149  'label' => $argumentLabel
150  );
151  $fieldProvider->expects($this->any())->method('getCommandControllerActionArgumentFields')->will($this->returnValue($argArray));
152  $expectedAdditionalFields = array(
153  'action' => array(
154  'code' => '<select name="tx_scheduler[task_extbase][action]">' . LF
155  . '<option title="test" value="extbase:mocka:funca" selected="selected">Extbase MockA: FuncA</option>' . LF
156  . '<option title="test" value="mypkg:mockb:funcb">Mypkg MockB: FuncB</option>' . LF
157  . '<option title="test" value="extbase:mockc:funcc">Extbase MockC: FuncC</option>' . LF
158  . '</select>',
159  'label' => $actionLabel
160  ),
161  'description' => array(
162  'code' => '',
163  'label' => '<strong></strong>'
164  ),
165  'arg' => array(
166  'code' => '<input type="text" name="tx_scheduler[task_extbase][arguments][arg]" value="1" /> ',
167  'label' => $argumentLabel
168  )
169  );
170 
171  $taskInfo = array();
173  $task = new \TYPO3\CMS\Extbase\Scheduler\Task();
174  $task->setCommandIdentifier($command1->getCommandIdentifier());
176  $schedulerModule = $this->getMock('TYPO3\\CMS\\Scheduler\\Controller\\SchedulerModuleController', array(), array(), '', FALSE);
177 
178  $this->assertEquals($expectedAdditionalFields, $fieldProvider->getAdditionalFields($taskInfo, $task, $schedulerModule));
179  }
180 }
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)