[~CONFIGURATION] Extbase: Set lockType to empty string instead of 'system'.
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / MVC / Controller / Argument_testcase.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
6 * All rights reserved
7 *
8 * This class is a backport of the corresponding class of FLOW3.
9 * All credits go to the v5 team.
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 class Tx_Extbase_MVC_Controller_Argument_testcase extends Tx_Extbase_BaseTestCase {
29
30 /**
31 * @test
32 * @expectedException InvalidArgumentException
33 */
34 public function constructingArgumentWithoutNameThrowsException() {
35 new Tx_Extbase_MVC_Controller_Argument(NULL, 'Text');
36 }
37
38 /**
39 * @test
40 * @expectedException InvalidArgumentException
41 */
42 public function constructingArgumentWithInvalidNameThrowsException() {
43 new Tx_Extbase_MVC_Controller_Argument(new ArrayObject(), 'Text');
44 }
45
46 /**
47 * @test
48 */
49 public function passingDataTypeToConstructorReallySetsTheDataType() {
50 $argument = new Tx_Extbase_MVC_Controller_Argument('dummy', 'Number');
51 $this->assertEquals('Number', $argument->getDataType(), 'The specified data type has not been set correctly.');
52 }
53
54 /**
55 * @test
56 */
57 public function setShortNameProvidesFluentInterface() {
58 $argument = new Tx_Extbase_MVC_Controller_Argument('dummy', 'Text');
59 $returnedArgument = $argument->setShortName('x');
60 $this->assertSame($argument, $returnedArgument, 'The returned argument is not the original argument.');
61 }
62
63 /**
64 * @test
65 */
66 public function setValueProvidesFluentInterface() {
67 $argument = new Tx_Extbase_MVC_Controller_Argument('dummy', 'Text');
68 $returnedArgument = $argument->setValue('x');
69 $this->assertSame($argument, $returnedArgument, 'The returned argument is not the original argument.');
70 }
71
72 /**
73 * @test
74 */
75 public function setValueTriesToConvertAnUIDIntoTheRealObjectIfTheDataTypeClassSchemaIsSet() {
76 $object = new StdClass();
77
78 $argument = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_Argument'), array('findObjectByUid'), array(), '', FALSE);
79 $argument->expects($this->once())->method('findObjectByUid')->with('42')->will($this->returnValue($object));
80 $argument->_set('dataTypeClassSchema', 'stdClass');
81 $argument->_set('dataType', 'stdClass');
82 // $argument->_set('queryFactory', $mockQueryFactory);
83 $argument->setValue('42');
84
85 $this->assertSame($object, $argument->_get('value'));
86 }
87
88
89 /**
90 * @test
91 */
92 public function toStringReturnsTheStringVersionOfTheArgumentsValue() {
93 $argument = new Tx_Extbase_MVC_Controller_Argument('dummy', 'Text');
94 $argument->setValue(123);
95
96 $this->assertSame((string)$argument, '123', 'The returned argument is not a string.');
97 $this->assertNotSame((string)$argument, 123, 'The returned argument is identical to the set value.');
98 }
99
100 /**
101 * @test
102 */
103 public function defaultDataTypeIsText() {
104 $argument = new Tx_Extbase_MVC_Controller_Argument('SomeArgument');
105 $this->assertSame('Text', $argument->getDataType());
106 }
107
108 /**
109 * @test
110 */
111 public function setNewValidatorConjunctionCreatesANewValidatorConjunctionObject() {
112 $argument = new Tx_Extbase_MVC_Controller_Argument('dummy', 'Text');
113 $argument->setNewValidatorConjunction(array());
114
115 $this->assertType('Tx_Extbase_Validation_Validator_ConjunctionValidator', $argument->getValidator(), 'The returned validator is not a conjunction as expected.');
116 }
117
118 /**
119 * @test
120 */
121 public function setNewValidatorConjunctionAddsThePassedValidatorsToTheCreatedValidatorChain() {
122 eval('class Validator1 implements Tx_Extbase_Validation_Validator_ValidatorInterface {
123 public function isValid($value) {}
124 public function setOptions(array $validationOptions) {}
125 public function getErrors() {}
126 }');
127 eval('class Validator2 implements Tx_Extbase_Validation_Validator_ValidatorInterface {
128 public function isValid($value) {}
129 public function setOptions(array $validationOptions) {}
130 public function getErrors() {}
131 }');
132
133 $validator1 = new Validator1;
134 $validator2 = new Validator2;
135
136 $mockValidatorConjunction = $this->getMock('Tx_Extbase_Validation_Validator_ConjunctionValidator');
137 $mockValidatorConjunction->expects($this->at(0))->method('addValidator')->with($validator1);
138 $mockValidatorConjunction->expects($this->at(1))->method('addValidator')->with($validator2);
139
140 $argument = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_Argument'), array('dummy'), array(), '', FALSE);
141 $argument->_set('validator', $mockValidatorConjunction);
142 $argument->setNewValidatorConjunction(array('Validator1', 'Validator2'));
143 }
144
145 /**
146 * @test
147 */
148 public function settingDefaultValueReallySetsDefaultValue() {
149 $argument = new Tx_Extbase_MVC_Controller_Argument('dummy', 'Text');
150 $argument->setDefaultValue(42);
151
152 $this->assertEquals(42, $argument->getValue(), 'The default value was not stored in the Argument.');
153 }
154
155 }
156 ?>