TYPO3 CMS  TYPO3_6-2
ArgumentBehaviorBeforeExtbase14Test.php
Go to the documentation of this file.
1 <?php
3 
23 
29  new \TYPO3\CMS\Extbase\Mvc\Controller\Argument(NULL, 'Text');
30  }
31 
37  new \TYPO3\CMS\Extbase\Mvc\Controller\Argument(new \ArrayObject(), 'Text');
38  }
39 
44  $argument = new \TYPO3\CMS\Extbase\Mvc\Controller\Argument('dummy', 'Number');
45  $this->assertEquals('Number', $argument->getDataType(), 'The specified data type has not been set correctly.');
46  }
47 
52  $argument = new \TYPO3\CMS\Extbase\Mvc\Controller\Argument('dummy', 'Text');
53  $returnedArgument = $argument->setShortName('x');
54  $this->assertSame($argument, $returnedArgument, 'The returned argument is not the original argument.');
55  }
56 
60  public function setValueProvidesFluentInterface() {
61  $argument = $this->getAccessibleMock('TYPO3\CMS\Extbase\Mvc\Controller\Argument', array('dummy'), array('dummy', 'Text'));
63  $returnedArgument = $argument->setValue('x');
64  $this->assertSame($argument, $returnedArgument, 'The returned argument is not the original argument.');
65  }
66 
71  public function setValueUsesNullAsIs() {
72  $argument = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\Argument', array('transformValue'), array('dummy', 'ArrayObject'));
74  $argument->expects($this->never())->method('transformValue');
75  $argument->setValue(NULL);
76  }
77 
83  $argument = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\Argument', array('transformValue'), array('dummy', 'ArrayObject'));
85  $argument->expects($this->never())->method('transformValue');
86  $argument->setValue(new \ArrayObject());
87  }
88 
93  $object = new \StdClass();
94  $argument = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\Argument', array('findObjectByUid'), array(), '', FALSE);
96  $argument->expects($this->once())->method('findObjectByUid')->with('42')->will($this->returnValue($object));
97  $argument->_set('dataTypeClassSchema', 'stdClass');
98  $argument->_set('dataType', 'stdClass');
99  // $argument->_set('queryFactory', $mockQueryFactory);
100  $argument->setValue('42');
101  $this->assertSame($object, $argument->_get('value'));
102  $this->assertSame(\TYPO3\CMS\Extbase\Mvc\Controller\Argument::ORIGIN_PERSISTENCE, $argument->getOrigin());
103  }
104 
109  $argument = $this->getAccessibleMock('TYPO3\CMS\Extbase\Mvc\Controller\Argument', array('dummy'), array('dummy', 'Text'));
111  $argument->setValue(123);
112  $this->assertSame((string) $argument, '123', 'The returned argument is not a string.');
113  $this->assertNotSame((string) $argument, 123, 'The returned argument is identical to the set value.');
114  }
115 
120  $argument = $this->getAccessibleMock('TYPO3\CMS\Extbase\Mvc\Controller\Argument', array('dummy'), array('dummy', 'Text'));
121  $mockConjunctionValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ConjunctionValidator');
122  $mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
123  $mockObjectManager->expects($this->once())->method('get')->with('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ConjunctionValidator')->will($this->returnValue($mockConjunctionValidator));
124  $argument->_set('objectManager', $mockObjectManager);
125  $argument->setNewValidatorConjunction(array());
126  $this->assertSame($mockConjunctionValidator, $argument->getValidator());
127  }
128 
133  eval('class Validator1 implements TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface {
134  public function isValid($value) {}
135  public function setOptions(array $validationOptions) {}
136  public function getErrors() {}
137  }');
138  eval('class Validator2 implements TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface {
139  public function isValid($value) {}
140  public function setOptions(array $validationOptions) {}
141  public function getErrors() {}
142  }');
143  $validator1 = new \Validator1();
144  $validator2 = new \Validator2();
145  $mockValidatorConjunction = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ConjunctionValidator');
146  $mockValidatorConjunction->expects($this->at(0))->method('addValidator')->with($validator1);
147  $mockValidatorConjunction->expects($this->at(1))->method('addValidator')->with($validator2);
148  $argument = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\Argument', array('dummy'), array(), '', FALSE);
149  $mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
150  $mockObjectManager->expects($this->never())->method('create');
151  $mockObjectManager->expects($this->at(0))->method('get')->with('Validator1')->will($this->returnValue($validator1));
152  $mockObjectManager->expects($this->at(1))->method('get')->with('Validator2')->will($this->returnValue($validator2));
153  $argument->_set('objectManager', $mockObjectManager);
154  $argument->_set('validator', $mockValidatorConjunction);
155  $argument->setNewValidatorConjunction(array('Validator1', 'Validator2'));
156  }
157 
162  $argument = new \TYPO3\CMS\Extbase\Mvc\Controller\Argument('dummy', 'Text');
163  $argument->setDefaultValue(42);
164  $this->assertEquals(42, $argument->getValue(), 'The default value was not stored in the Argument.');
165  }
166 
172  protected function enableDeprecatedPropertyMapperInArgument(\TYPO3\CMS\Extbase\Mvc\Controller\Argument $argument) {
173  $mockConfigurationManager = $this->getMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface');
174  $mockConfigurationManager->expects($this->any())->method('isFeatureEnabled')->with('rewrittenPropertyMapper')->will($this->returnValue(FALSE));
175  $argument->_set('configurationManager', $mockConfigurationManager);
176  }
177 }
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)