[BUGFIX] Tests: Improve mocking in ext:extbase 07/28407/6
authorAnja Leichsenring <aleichsenring@ab-softlab.de>
Fri, 14 Mar 2014 23:02:15 +0000 (00:02 +0100)
committerWouter Wolters <typo3@wouterwolters.nl>
Sat, 15 Mar 2014 12:00:07 +0000 (13:00 +0100)
Unit tests reveal some warnings which are caused by incomplete
mocking. They all belong to $GLOBALS['LANG']

Change-Id: Ic2adda9984a530b82e259c1d8931015996f167ba
Resolves: #56700
Related: #51436
Releases: 6.2
Reviewed-on: https://review.typo3.org/28407
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
39 files changed:
typo3/sysext/extbase/Classes/Validation/Validator/AbstractValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/AlphanumericValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/DateTimeValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/EmailAddressValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/FloatValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/GenericObjectValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/IntegerValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/NotEmptyValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/NumberRangeValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/NumberValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/RegularExpressionValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/StringLengthValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/StringValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/TextValidator.php
typo3/sysext/extbase/Tests/Unit/Utility/LocalizationUtilityTest.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/AlphanumericValidatorTest.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/AlphanumericValidatorTest.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/DateTimeValidatorTest.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/EmailAddressValidatorTest.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/FloatValidatorTest.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/GenericObjectValidatorTest.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/IntegerValidatorTest.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/NotEmptyValidatorTest.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/NumberRangeValidatorTest.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/NumberValidatorTest.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/RegularExpressionValidatorTest.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/StringLengthValidatorTest.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/TextValidatorTest.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/CollectionValidatorTest.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/EmailAddressValidatorTest.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/FloatValidatorTest.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/IntegerValidatorTest.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/NotEmptyValidatorTest.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/NumberRangeValidatorTest.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/NumberValidatorTest.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/RegularExpressionValidatorTest.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/StringLengthValidatorTest.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/StringValidatorTest.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/TextValidatorTest.php

index 3b40e4d..60f3ff5 100644 (file)
@@ -156,4 +156,21 @@ abstract class AbstractValidator implements \TYPO3\CMS\Extbase\Validation\Valida
        final protected function isEmpty($value) {
                return $value === NULL || $value === '';
        }
+
+       /**
+        * Wrap static call to LocalizationUtility to simplify unit testing
+        *
+        * @param string $translateKey
+        * @param string $extensionName
+        * @param array $arguments
+        *
+        * @return NULL|string
+        */
+       protected function translateErrorMessage($translateKey, $extensionName, $arguments = array()) {
+               return \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                       $translateKey,
+                       $extensionName,
+                       $arguments
+               );
+       }
 }
index 63b2724..033a389 100644 (file)
@@ -43,11 +43,7 @@ class AlphanumericValidator extends AbstractValidator {
         */
        public function isValid($value) {
                if (!is_string($value) || preg_match('/^[\pL\d]*$/u', $value) !== 1) {
-                       $this->addError(
-                               \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
-                                       'validator.alphanumeric.notvalid',
-                                       'extbase'
-                               ), 1221551320);
+                       $this->addError($this->translateErrorMessage('validator.alphanumeric.notvalid', 'extbase'), 1221551320);
                }
        }
 }
index 8248f77..451187d 100644 (file)
@@ -49,7 +49,7 @@ class DateTimeValidator extends AbstractValidator {
                        return;
                }
                $this->addError(
-                       \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                       $this->translateErrorMessage(
                                'validator.datetime.notvalid',
                                'extbase',
                                array(
index 2adf944..84e5578 100644 (file)
@@ -45,7 +45,7 @@ class EmailAddressValidator extends AbstractValidator {
        public function isValid($value) {
                if (!is_string($value) || !$this->validEmail($value)) {
                        $this->addError(
-                               \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                               $this->translateErrorMessage(
                                        'validator.emailaddress.notvalid',
                                        'extbase'
                                ), 1221559976);
index 4f5a607..4dfe2d2 100644 (file)
@@ -49,7 +49,7 @@ class FloatValidator extends AbstractValidator {
 
                if (!is_string($value) || strpos($value, '.') === FALSE || preg_match('/^[0-9.e+-]+$/', $value) !== 1) {
                        $this->addError(
-                               \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                               $this->translateErrorMessage(
                                'validator.float.notvalid',
                                'extbase'
                                ), 1221560288);
index 609274c..0343e3b 100644 (file)
@@ -125,7 +125,7 @@ class GenericObjectValidator extends AbstractValidator implements ObjectValidato
                        /* @deprecated since Extbase 1.4.0, will be removed two versions after Extbase 6.1 */
                        if (!is_object($object)) {
                                $this->addError(
-                                       \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                                       $this->translateErrorMessage(
                                                'validator.genericobject.noobject',
                                                'extbase'
                                        ), 1241099148);
index 02118c0..b832907 100644 (file)
@@ -45,7 +45,7 @@ class IntegerValidator extends AbstractValidator {
        public function isValid($value) {
                if (filter_var($value, FILTER_VALIDATE_INT) === FALSE) {
                        $this->addError(
-                               \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                               $this->translateErrorMessage(
                                'validator.integer.notvalid',
                                'extbase'
                                ), 1221560494);
index 8605659..7ce5fbc 100644 (file)
@@ -54,28 +54,28 @@ class NotEmptyValidator extends AbstractValidator {
        public function isValid($value) {
                if ($value === NULL) {
                        $this->addError(
-                               \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                               $this->translateErrorMessage(
                                        'validator.notempty.null',
                                        'extbase'
                                ), 1221560910);
                }
                if ($value === '') {
                        $this->addError(
-                               \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                               $this->translateErrorMessage(
                                        'validator.notempty.empty',
                                        'extbase'
                                ), 1221560718);
                }
                if (is_array($value) && empty($value)) {
                        $this->addError(
-                               \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                               $this->translateErrorMessage(
                                        'validator.notempty.empty',
                                        'extbase'
                                ), 1347992400);
                }
                if (is_object($value) && $value instanceof \Countable && $value->count() === 0) {
                        $this->addError(
-                               \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                               $this->translateErrorMessage(
                                        'validator.notempty.empty',
                                        'extbase'
                                ), 1347992453);
index b9691aa..6b84a21 100644 (file)
@@ -53,7 +53,7 @@ class NumberRangeValidator extends AbstractValidator {
        public function isValid($value) {
                if (!is_numeric($value)) {
                        $this->addError(
-                               \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                               $this->translateErrorMessage(
                                        'validator.numberrange.notvalid',
                                        'extbase'
                                ), 1221563685);
@@ -81,7 +81,7 @@ class NumberRangeValidator extends AbstractValidator {
                        $maximum = $x;
                }
                if ($value < $minimum || $value > $maximum) {
-                       $this->addError(\TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                       $this->addError($this->translateErrorMessage(
                                'validator.numberrange.range',
                                'extbase',
                                array(
index 01fa8e7..523b144 100644 (file)
@@ -46,7 +46,7 @@ class NumberValidator extends AbstractValidator {
        public function isValid($value) {
                if (!is_numeric($value)) {
                        $this->addError(
-                       \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                       $this->translateErrorMessage(
                                'validator.number.notvalid',
                                'extbase'
                        ), 1221563685);
index 544b6e7..8e1fd6a 100644 (file)
@@ -55,7 +55,7 @@ class RegularExpressionValidator extends AbstractValidator {
                $result = preg_match($this->options['regularExpression'], $value);
                if ($result === 0) {
                        $this->addError(
-                               \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                               $this->translateErrorMessage(
                                        'validator.regularexpression.nomatch',
                                        'extbase'
                                ), 1221565130);
index c33eb98..deb8945 100644 (file)
@@ -81,7 +81,7 @@ class StringLengthValidator extends AbstractValidator {
                if ($isValid === FALSE) {
                        if ($this->options['minimum'] > 0 && $this->options['maximum'] < PHP_INT_MAX) {
                                $this->addError(
-                                       \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                                       $this->translateErrorMessage(
                                                'validator.stringlength.between',
                                                'extbase',
                                                array (
@@ -91,7 +91,7 @@ class StringLengthValidator extends AbstractValidator {
                                        ), 1238108067, array($this->options['minimum'], $this->options['maximum']));
                        } elseif ($this->options['minimum'] > 0) {
                                $this->addError(
-                                       \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                                       $this->translateErrorMessage(
                                                'validator.stringlength.less',
                                                'extbase',
                                                array(
@@ -100,7 +100,7 @@ class StringLengthValidator extends AbstractValidator {
                                        ), 1238108068, array($this->options['minimum']));
                        } else {
                                $this->addError(
-                                       \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                                       $this->translateErrorMessage(
                                                'validator.stringlength.exceed',
                                                'extbase',
                                                array(
index e53c250..e2a1745 100644 (file)
@@ -45,7 +45,7 @@ class StringValidator extends AbstractValidator {
        public function isValid($value) {
                if (!is_string($value)) {
                        $this->addError(
-                               \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                               $this->translateErrorMessage(
                                        'validator.string.notvalid',
                                        'extbase'
                                ), 1238108067);
index 8368570..06e2d37 100644 (file)
@@ -51,7 +51,7 @@ class TextValidator extends AbstractValidator {
        public function isValid($value) {
                if ($value !== filter_var($value, FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES)) {
                        $this->addError(
-                               \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                               $this->translateErrorMessage(
                                        'validator.text.notvalid',
                                        'extbase'
                                ), 1221565786);
index 979ad26..22b3268 100644 (file)
@@ -183,14 +183,20 @@ class LocalizationUtilityTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase
         * @test
         */
        public function translateForEmptyStringKeyReturnsNull() {
-               $this->assertNull(\TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('', 'extbase'));
+               $this->localization->_setStatic('LOCAL_LANG', array());
+               $configurationManager = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager', array('getConfiguration'));
+               $this->localization->staticExpects($this->atLeastOnce())->method('getConfigurationManager')->will($this->returnValue($configurationManager));
+               $this->assertNull($this->localization->translate('', 'extbase'));
        }
 
        /**
         * @test
         */
        public function translateForEmptyStringKeyWithArgumentsReturnsNull() {
-               $this->assertNull(\TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('', 'extbase', array('argument')));
+               $this->localization->_setStatic('LOCAL_LANG', array());
+               $configurationManager = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager', array('getConfiguration'));
+               $this->localization->staticExpects($this->atLeastOnce())->method('getConfigurationManager')->will($this->returnValue($configurationManager));
+               $this->assertNull($this->localization->translate('', 'extbase', array('argument')));
        }
 
        /**
index 00d57f3..3008256 100644 (file)
@@ -22,43 +22,44 @@ namespace TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator;
  *                                                                        */
 
 /**
- * Testcase for the alphanumeric validator
+ * Test case
  *
- * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
  */
-class AlphanumericValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\AbstractValidatorTestcase {
-
-       protected $validatorClassName = 'TYPO3\\CMS\\Extbase\\Validation\\Validator\\AlphanumericValidator';
+class AlphanumericValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
 
        /**
         * @test
-        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
        public function alphanumericValidatorShouldReturnNoErrorsForAnAlphanumericString() {
-               $this->assertFalse($this->validator->validate('12ssDF34daweidf')->hasErrors());
+               /** @var \TYPO3\CMS\Extbase\Validation\Validator\AlphanumericValidator|\PHPUnit_Framework_MockObject_MockObject $subject */
+               $subject = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\AlphanumericValidator', array('translateErrorMessage'));
+               $this->assertFalse($subject->validate('12ssDF34daweidf')->hasErrors());
        }
 
        /**
         * @test
-        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
        public function alphanumericValidatorReturnsErrorsForAStringWithSpecialCharacters() {
-               $this->assertTrue($this->validator->validate('adsf%&/$jklsfdö')->hasErrors());
+               /** @var \TYPO3\CMS\Extbase\Validation\Validator\AlphanumericValidator|\PHPUnit_Framework_MockObject_MockObject $subject */
+               $subject = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\AlphanumericValidator', array('translateErrorMessage'));
+               $this->assertTrue($subject->validate('adsf%&/$jklsfdö')->hasErrors());
        }
 
        /**
         * @test
-        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
        public function alphanumericValidatorCreatesTheCorrectErrorForAnInvalidSubject() {
-               $this->assertEquals(1, count($this->validator->validate('adsf%&/$jklsfdö')->getErrors()));
+               /** @var \TYPO3\CMS\Extbase\Validation\Validator\AlphanumericValidator|\PHPUnit_Framework_MockObject_MockObject $subject */
+               $subject = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\AlphanumericValidator', array('translateErrorMessage'));
+               $this->assertEquals(1, count($subject->validate('adsf%&/$jklsfdö')->getErrors()));
        }
 
        /**
         * @test
-        * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
         */
        public function alphanumericValidatorShouldReturnNoErrorsForAnAlphanumericUnicodeString() {
-               $this->assertFalse($this->validator->validate('12ssDF34daweidfäøüößØœ你好')->hasErrors());
+               /** @var \TYPO3\CMS\Extbase\Validation\Validator\AlphanumericValidator|\PHPUnit_Framework_MockObject_MockObject $subject */
+               $subject = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\AlphanumericValidator', array('translateErrorMessage'));
+               $this->assertFalse($subject->validate('12ssDF34daweidfäøüößØœ你好')->hasErrors());
        }
 }
index 44a6f22..222d4a7 100644 (file)
@@ -49,7 +49,7 @@ class AlphanumericValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCa
         */
        public function alphanumericValidatorReturnsFalseForAStringWithSpecialCharacters() {
                /** @var \TYPO3\CMS\Extbase\Validation\Validator\AlphanumericValidator $alphanumericValidator */
-               $alphanumericValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\AlphanumericValidator', array('dummy'), array(), '', FALSE);
+               $alphanumericValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\AlphanumericValidator', array('translateErrorMessage'), array(), '', FALSE);
                $alphanumericValidator->expects($this->never())->method('addError');
                $alphanumericValidator->isValid('adsf%&/$jklsfdö');
        }
@@ -58,8 +58,9 @@ class AlphanumericValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCa
         * @test
         */
        public function alphanumericValidatorCreatesTheCorrectErrorForAnInvalidSubject() {
-               $alphanumericValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\AlphanumericValidator', array('addError'), array(), '', FALSE);
-               $alphanumericValidator->expects($this->once())->method('addError')->with('The given subject was not a valid alphanumeric string.', 1221551320);
+               $alphanumericValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\AlphanumericValidator', array('addError', 'translateErrorMessage'), array(), '', FALSE);
+               // we only test for the error key, after the translation method is mocked.
+               $alphanumericValidator->expects($this->once())->method('addError')->with(NULL, 1221551320);
                $alphanumericValidator->isValid('adsf%&/$jklsfdö');
        }
 }
index a4b28dd..2674a0b 100644 (file)
@@ -48,7 +48,7 @@ class DateTimeValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
         * @test
         */
        public function dateTimeValidatorReturnsFalseForAnInvalidDateTimeObject() {
-               $dateTimeValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\DateTimeValidator', array('addError'), array(), '', FALSE);
+               $dateTimeValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\DateTimeValidator', array('addError', 'translateErrorMessage'), array(), '', FALSE);
                $dateTimeValidator->expects($this->once())->method('addError');
                $dateTimeValidator->isValid('blah');
        }
index a0853ad..45f1beb 100644 (file)
@@ -84,7 +84,7 @@ class EmailAddressValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCa
         * @param mixed $address
         */
        public function emailAddressValidatorReturnsFalseForAnInvalidEmailAddress($address) {
-               $emailAddressValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\EmailAddressValidator', array('addError'), array(), '', FALSE);
+               $emailAddressValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\EmailAddressValidator', array('addError', 'translateErrorMessage'), array(), '', FALSE);
                $emailAddressValidator->expects($this->once())->method('addError');
                $emailAddressValidator->isValid($address);
        }
@@ -93,8 +93,9 @@ class EmailAddressValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCa
         * @test
         */
        public function emailValidatorCreatesTheCorrectErrorForAnInvalidEmailAddress() {
-               $emailAddressValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\EmailAddressValidator', array('addError'), array(), '', FALSE);
-               $emailAddressValidator->expects($this->once())->method('addError')->with('The given subject was not a valid email address.', 1221559976);
+               $emailAddressValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\EmailAddressValidator', array('addError', 'translateErrorMessage'), array(), '', FALSE);
+               // we only test for the error key, after the translation method is mocked.
+               $emailAddressValidator->expects($this->once())->method('addError')->with(NULL, 1221559976);
                $emailAddressValidator->isValid('notAValidMail@Address');
        }
 }
index 77d2ca2..9135c76 100644 (file)
@@ -84,7 +84,7 @@ class FloatValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
         * @param mixed $number
         */
        public function floatValidatorReturnsFalseForAnInvalidFloat($number) {
-               $floatValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\FloatValidator', array('addError'), array(), '', FALSE);
+               $floatValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\FloatValidator', array('addError', 'translateErrorMessage'), array(), '', FALSE);
                $floatValidator->expects($this->once())->method('addError');
                $floatValidator->isValid($number);
        }
@@ -93,11 +93,9 @@ class FloatValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
         * @test
         */
        public function floatValidatorCreatesTheCorrectErrorForAnInvalidSubject() {
-               $floatValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\FloatValidator', array('addError'), array(), '', FALSE);
-
-               $translatedMessage = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('validator.float.notvalid', 'extbase');
-
-               $floatValidator->expects($this->once())->method('addError')->with($translatedMessage, 1221560288);
+               $floatValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\FloatValidator', array('addError', 'translateErrorMessage'), array(), '', FALSE);
+               // we only test for the error key, after the translation method is mocked.
+               $floatValidator->expects($this->once())->method('addError')->with(NULL, 1221560288);
                $floatValidator->isValid(123456);
        }
 }
index 65ad053..439c850 100644 (file)
@@ -41,7 +41,7 @@ class GenericObjectValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestC
        public function isValidReturnsFalseIfTheValueIsNoObject() {
                $configurationManager = $this->getMock('TYPO3\CMS\Extbase\Configuration\ConfigurationManager', array('isFeatureEnabled'), array(), '', FALSE);
                $configurationManager->expects($this->any())->method('isFeatureEnabled')->with('rewrittenPropertyMapper')->will($this->returnValue(FALSE));
-               $validator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\GenericObjectValidator', array('addError'), array(), '', FALSE);
+               $validator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\GenericObjectValidator', array('addError', 'translateErrorMessage'), array(), '', FALSE);
                $validator->injectConfigurationManager($configurationManager);
                $this->assertFalse($validator->isValid('foo'));
        }
index 353c401..f972954 100644 (file)
@@ -82,7 +82,7 @@ class IntegerValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
         * @param mixed $number
         */
        public function integerValidatorReturnsFalseForAnInvalidInteger($number) {
-               $integerValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\IntegerValidator', array('addError'), array(), '', FALSE);
+               $integerValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\IntegerValidator', array('addError', 'translateErrorMessage'), array(), '', FALSE);
                $integerValidator->expects($this->once())->method('addError');
                $integerValidator->isValid($number);
        }
@@ -91,10 +91,9 @@ class IntegerValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
         * @test
         */
        public function integerValidatorCreatesTheCorrectErrorForAnInvalidSubject() {
-               $integerValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\IntegerValidator', array('addError'), array(), '', FALSE);
-
-               $translatedMessage = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('validator.integer.notvalid', 'extbase');
-               $integerValidator->expects($this->once())->method('addError')->with($translatedMessage, 1221560494);
+               $integerValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\IntegerValidator', array('addError', 'translateErrorMessage'), array(), '', FALSE);
+               // we only test for the error key, after the translation method is mocked.
+               $integerValidator->expects($this->once())->method('addError')->with(NULL, 1221560494);
                $integerValidator->isValid('not a number');
        }
 }
index e47b468..a50153d 100644 (file)
@@ -48,7 +48,7 @@ class NotEmptyValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
         * @test
         */
        public function notEmptyValidatorReturnsFalseForAnEmptyString() {
-               $notEmptyValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\NotEmptyValidator', array('addError'), array(), '', FALSE);
+               $notEmptyValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\NotEmptyValidator', array('addError', 'translateErrorMessage'), array(), '', FALSE);
                $notEmptyValidator->expects($this->once())->method('addError');
                $notEmptyValidator->isValid('');
        }
@@ -57,7 +57,7 @@ class NotEmptyValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
         * @test
         */
        public function notEmptyValidatorReturnsFalseForANullValue() {
-               $notEmptyValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\NotEmptyValidator', array('addError'), array(), '', FALSE);
+               $notEmptyValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\NotEmptyValidator', array('addError', 'translateErrorMessage'), array(), '', FALSE);
                $notEmptyValidator->expects($this->once())->method('addError');
                $notEmptyValidator->isValid(NULL);
        }
@@ -66,8 +66,9 @@ class NotEmptyValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
         * @test
         */
        public function notEmptyValidatorCreatesTheCorrectErrorForAnEmptySubject() {
-               $notEmptyValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\NotEmptyValidator', array('addError'), array(), '', FALSE);
-               $notEmptyValidator->expects($this->once())->method('addError')->with('The given subject was empty.', 1221560718);
+               $notEmptyValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\NotEmptyValidator', array('addError', 'translateErrorMessage'), array(), '', FALSE);
+               // we only test for the error key, after the translation method is mocked.
+               $notEmptyValidator->expects($this->once())->method('addError')->with(NULL, 1221560718);
                $notEmptyValidator->isValid('');
        }
 
@@ -75,8 +76,9 @@ class NotEmptyValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
         * @test
         */
        public function notEmptyValidatorCreatesTheCorrectErrorForANullValue() {
-               $notEmptyValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\NotEmptyValidator', array('addError'), array(), '', FALSE);
-               $notEmptyValidator->expects($this->once())->method('addError')->with('The given subject was NULL.', 1221560910);
+               $notEmptyValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\NotEmptyValidator', array('addError', 'translateErrorMessage'), array(), '', FALSE);
+               // we only test for the error key, after the translation method is mocked.
+               $notEmptyValidator->expects($this->once())->method('addError')->with(NULL, 1221560910);
                $notEmptyValidator->isValid(NULL);
        }
 }
index 869af0b..bac1c16 100644 (file)
@@ -49,7 +49,7 @@ class NumberRangeValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCas
         * @test
         */
        public function numberRangeValidatorReturnsFalseForANumberOutOfRange() {
-               $numberRangeValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\NumberRangeValidator', array('addError'), array(), '', FALSE);
+               $numberRangeValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\NumberRangeValidator', array('addError', 'translateErrorMessage'), array(), '', FALSE);
                $numberRangeValidator->expects($this->once())->method('addError');
                $numberRangeValidator->setOptions(array('startRange' => 0, 'endRange' => 1000));
                $numberRangeValidator->isValid(1000.1);
@@ -69,7 +69,7 @@ class NumberRangeValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCas
         * @test
         */
        public function numberRangeValidatorReturnsFalseForAString() {
-               $numberRangeValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\NumberRangeValidator', array('addError'), array(), '', FALSE);
+               $numberRangeValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\NumberRangeValidator', array('addError', 'translateErrorMessage'), array(), '', FALSE);
                $numberRangeValidator->expects($this->once())->method('addError');
                $numberRangeValidator->setOptions(array('startRange' => 0, 'endRange' => 1000));
                $numberRangeValidator->isValid('not a number');
@@ -81,10 +81,10 @@ class NumberRangeValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCas
        public function numberRangeValidatorCreatesTheCorrectErrorForANumberOutOfRange() {
                $startRange = 1;
                $endRange = 42;
-               $translatedMessage = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('validator.numberrange.range', 'extbase', array($startRange, $endRange));
 
-               $numberRangeValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\NumberRangeValidator', array('addError'), array(), '', FALSE);
-               $numberRangeValidator->expects($this->once())->method('addError')->with($translatedMessage, 1221561046, array(1, 42));
+               $numberRangeValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\NumberRangeValidator', array('addError', 'translateErrorMessage'), array(), '', FALSE);
+               // we only test for the error key, after the translation method is mocked.
+               $numberRangeValidator->expects($this->once())->method('addError')->with(NULL, 1221561046, array(1, 42));
                $numberRangeValidator->setOptions(array('startRange' => $startRange, 'endRange' => $endRange));
                $numberRangeValidator->isValid(4711);
        }
@@ -93,8 +93,9 @@ class NumberRangeValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCas
         * @test
         */
        public function numberRangeValidatorCreatesTheCorrectErrorForAStringSubject() {
-               $numberRangeValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\NumberRangeValidator', array('addError'), array(), '', FALSE);
-               $numberRangeValidator->expects($this->once())->method('addError')->with('The given subject was not a valid number.', 1221563685);
+               $numberRangeValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\NumberRangeValidator', array('addError', 'translateErrorMessage'), array(), '', FALSE);
+               // we only test for the error key, after the translation method is mocked.
+               $numberRangeValidator->expects($this->once())->method('addError')->with(NULL, 1221563685);
                $numberRangeValidator->setOptions(array('startRange' => 0, 'endRange' => 42));
                $numberRangeValidator->isValid('this is not between 0 an 42');
        }
index 1942fbc..a59fe89 100644 (file)
@@ -48,7 +48,7 @@ class NumberValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
         * @test
         */
        public function numberValidatorReturnsFalseForAString() {
-               $numberValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\NumberValidator', array('addError'), array(), '', FALSE);
+               $numberValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\NumberValidator', array('addError', 'translateErrorMessage'), array(), '', FALSE);
                $numberValidator->expects($this->once())->method('addError');
                $numberValidator->isValid('not a number');
        }
@@ -57,8 +57,9 @@ class NumberValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
         * @test
         */
        public function numberValidatorCreatesTheCorrectErrorForAnInvalidSubject() {
-               $numberValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\NumberValidator', array('addError'), array(), '', FALSE);
-               $numberValidator->expects($this->once())->method('addError')->with('The given subject was not a valid number.', 1221563685);
+               $numberValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\NumberValidator', array('addError', 'translateErrorMessage'), array(), '', FALSE);
+               // we only test for the error key, after the translation method is mocked.
+               $numberValidator->expects($this->once())->method('addError')->with(NULL, 1221563685);
                $numberValidator->isValid('this is not a number');
        }
 }
index fcc58c7..d370cfa 100644 (file)
@@ -39,7 +39,7 @@ class RegularExpressionValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseT
         * @test
         */
        public function regularExpressionValidatorMatchesABasicExpressionCorrectly() {
-               $regularExpressionValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\RegularExpressionValidator', array('addError'), array(), '', FALSE);
+               $regularExpressionValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\RegularExpressionValidator', array('addError', 'translateErrorMessage'), array(), '', FALSE);
                $regularExpressionValidator->expects($this->once())->method('addError');
                $regularExpressionValidator->setOptions(array('regularExpression' => '/^simple[0-9]expression$/'));
                $regularExpressionValidator->isValid('simple1expression');
@@ -50,8 +50,9 @@ class RegularExpressionValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseT
         * @test
         */
        public function regularExpressionValidatorCreatesTheCorrectErrorIfTheExpressionDidNotMatch() {
-               $regularExpressionValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\RegularExpressionValidator', array('addError'), array(), '', FALSE);
-               $regularExpressionValidator->expects($this->once())->method('addError')->with('The given subject did not match the pattern.', 1221565130);
+               $regularExpressionValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\RegularExpressionValidator', array('addError', 'translateErrorMessage'), array(), '', FALSE);
+               // we only test for the error key, after the translation method is mocked.
+               $regularExpressionValidator->expects($this->once())->method('addError')->with(NULL, 1221565130);
                $regularExpressionValidator->setOptions(array('regularExpression' => '/^simple[0-9]expression$/'));
                $regularExpressionValidator->isValid('some subject that will not match');
        }
index d4d0dde..9a6121c 100644 (file)
@@ -49,7 +49,7 @@ class StringLengthValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCa
         * @test
         */
        public function stringLengthValidatorReturnsFalseForAStringShorterThanThanMinLength() {
-               $stringLengthValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\StringLengthValidator', array('addError'), array(), '', FALSE);
+               $stringLengthValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\StringLengthValidator', array('addError', 'translateErrorMessage'), array(), '', FALSE);
                $stringLengthValidator->expects($this->once())->method('addError');
                $stringLengthValidator->setOptions(array('minimum' => 50, 'maximum' => 100));
                $stringLengthValidator->isValid('this is a very short string');
@@ -59,7 +59,7 @@ class StringLengthValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCa
         * @test
         */
        public function stringLengthValidatorReturnsFalseForAStringLongerThanThanMaxLength() {
-               $stringLengthValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\StringLengthValidator', array('addError'), array(), '', FALSE);
+               $stringLengthValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\StringLengthValidator', array('addError', 'translateErrorMessage'), array(), '', FALSE);
                $stringLengthValidator->expects($this->once())->method('addError');
                $stringLengthValidator->setOptions(array('minimum' => 5, 'maximum' => 10));
                $stringLengthValidator->isValid('this is a very short string');
@@ -148,7 +148,7 @@ class StringLengthValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCa
         * @test
         */
        public function stringLengthValidatorInsertsAnErrorObjectIfValidationFails() {
-               $stringLengthValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\StringLengthValidator', array('addError'), array(), '', FALSE);
+               $stringLengthValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\StringLengthValidator', array('addError', 'translateErrorMessage'), array(), '', FALSE);
                $stringLengthValidator->expects($this->once())->method('addError');
                $stringLengthValidator->setOptions(array('minimum' => 50, 'maximum' => 100));
                $stringLengthValidator->isValid('this is a very short string');
@@ -177,7 +177,7 @@ class StringLengthValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCa
         * @test
         */
        public function stringLengthValidatorAddsAnErrorIfTheGivenObjectCanNotBeConvertedToAString() {
-               $stringLengthValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\StringLengthValidator', array('addError'), array(), '', FALSE);
+               $stringLengthValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\StringLengthValidator', array('addError', 'translateErrorMessage'), array(), '', FALSE);
                $stringLengthValidator->expects($this->once())->method('addError');
                $stringLengthValidator->setOptions(array('minimum' => 5, 'maximum' => 100));
                $className = uniqid('TestClass');
index 32d8f1b..df9f533 100644 (file)
@@ -70,7 +70,7 @@ Ke kille Minutt d\'Kirmes net. Hir Wand Lann Gaas da, wär hu Heck Gart zën
         * @test
         */
        public function textValidatorReturnsFalseForAStringWithHtml() {
-               $textValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\TextValidator', array('addError'), array(), '', FALSE);
+               $textValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\TextValidator', array('addError', 'translateErrorMessage'), array(), '', FALSE);
                $textValidator->expects($this->once())->method('addError');
                $textValidator->isValid('<span style="color: #BBBBBB;">a nice text</span>');
        }
@@ -79,8 +79,9 @@ Ke kille Minutt d\'Kirmes net. Hir Wand Lann Gaas da, wär hu Heck Gart zën
         * @test
         */
        public function textValidatorCreatesTheCorrectErrorIfTheSubjectContainsHtmlEntities() {
-               $textValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\TextValidator', array('addError'), array(), '', FALSE);
-               $textValidator->expects($this->once())->method('addError')->with('The given subject was not a valid text (e.g. contained XML tags).', 1221565786);
+               $textValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\TextValidator', array('addError', 'translateErrorMessage'), array(), '', FALSE);
+               // we only test for the error key, after the translation method is mocked.
+               $textValidator->expects($this->once())->method('addError')->with(NULL, 1221565786);
                $textValidator->isValid('<span style="color: #BBBBBB;">a nice text</span>');
        }
 }
index 3b225d4..42024b1 100644 (file)
@@ -53,7 +53,7 @@ class CollectionValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase
         * @param array $mockedMethods
         * @return \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
         */
-       protected function getValidator(array $options = array(), array $mockedMethods = array('dummy')) {
+       protected function getValidator(array $options = array(), array $mockedMethods = array('translateErrorMessage')) {
                return $this->getAccessibleMock($this->validatorClassName, $mockedMethods, array($options), '', TRUE);
        }
 
@@ -103,7 +103,7 @@ class CollectionValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase
                $this->mockValidatorResolver->expects($this->exactly(4))
                        ->method('createValidator')
                        ->with('EmailAddress')
-                       ->will($this->returnValue(new \TYPO3\CMS\Extbase\Validation\Validator\EmailAddressValidator()));
+                       ->will($this->returnValue($this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\EmailAddressValidator', array('translateErrorMessage'))));
                $this->validator->_set('validatorResolver', $this->mockValidatorResolver);
                $arrayOfEmailAddresses = array(
                        'foo@bar.de',
@@ -132,26 +132,27 @@ class CollectionValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase
                $B->a = $A;
                $B->c = array($A);
 
+
+               // Create validators
+               $aValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\GenericObjectValidator', array('translateErrorMessage'), array(array()));
+               $aValidator->injectConfigurationManager($this->configurationManager);
+               $this->validator->_set('options', array('elementValidator' => 'Integer'));
+               $integerValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\IntegerValidator', array('translateErrorMessage'), array(array()));
+
                $this->mockValidatorResolver->expects($this->any())
                        ->method('createValidator')
                        ->with('Integer')
-                       ->will($this->returnValue(new \TYPO3\CMS\Extbase\Validation\Validator\IntegerValidator()));
+                       ->will($this->returnValue($integerValidator));
                $this->mockValidatorResolver->expects($this->any())
                        ->method('buildBaseValidatorConjunction')
-                       ->will($this->returnValue(new \TYPO3\CMS\Extbase\Validation\Validator\GenericObjectValidator()));
-
-                       // Create validators
-               $aValidator = new \TYPO3\CMS\Extbase\Validation\Validator\GenericObjectValidator(array());
-               $aValidator->injectConfigurationManager($this->configurationManager);
-               $this->validator->_set('options', array('elementValidator' => 'Integer'));
-               $integerValidator = new \TYPO3\CMS\Extbase\Validation\Validator\IntegerValidator(array());
+                       ->will($this->returnValue($aValidator));
 
                        // Add validators to properties
                $aValidator->addPropertyValidator('b', $this->validator);
                $aValidator->addPropertyValidator('integer', $integerValidator);
 
                $result = $aValidator->validate($A)->getFlattenedErrors();
-               $this->assertEquals('The given subject was not a valid integer', $result['b.0'][0]->getMessage());
+               $this->assertEquals(1221560494, $result['b.0'][0]->getCode());
        }
 
        /**
@@ -196,4 +197,4 @@ class CollectionValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase
                $this->validator->validate($objectStorage);
        }
 
-}
\ No newline at end of file
+}
index fbe4da3..4e4bd74 100644 (file)
@@ -22,19 +22,15 @@ namespace TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator;
  *                                                                        */
 
 /**
- * Testcase for the email address validator
+ * Test case
  *
- * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
  */
-class EmailAddressValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\AbstractValidatorTestcase {
-
-       protected $validatorClassName = 'TYPO3\\CMS\\Extbase\\Validation\\Validator\\EmailAddressValidator';
+class EmailAddressValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
 
        /**
         * Data provider with valid email addresses
         *
         * @return array
-        * @author Karsten Dambekalns <karsten@typo3.org>
         */
        public function validAddresses() {
                return array(
@@ -42,25 +38,25 @@ class EmailAddressValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation
                        array('user@localhost.localdomain'),
                        array('info@guggenheim.museum'),
                        array('just@test.invalid'),
-                       array('just+spam@test.de')
+                       array('just+spam@test.de'),
                );
        }
 
        /**
-        * @author Karsten Dambekalns <karsten@typo3.org>
         * @test
         * @dataProvider validAddresses
         * @param mixed $address
         */
        public function emailAddressValidatorReturnsNoErrorsForAValidEmailAddress($address) {
-               $this->assertFalse($this->validator->validate($address)->hasErrors());
+               /** @var \TYPO3\CMS\Extbase\Validation\Validator\EmailAddressValidator|\PHPUnit_Framework_MockObject_MockObject $subject */
+               $subject = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\EmailAddressValidator', array('translateErrorMessage'));
+               $this->assertFalse($subject->validate($address)->hasErrors());
        }
 
        /**
         * Data provider with invalid email addresses
         *
         * @return array
-        * @author Karsten Dambekalns <karsten@typo3.org>
         */
        public function invalidAddresses() {
                return array(
@@ -77,20 +73,22 @@ class EmailAddressValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation
        }
 
        /**
-        * @author Karsten Dambekalns <karsten@typo3.org>
         * @test
         * @dataProvider invalidAddresses
         * @param mixed $address
         */
        public function emailAddressValidatorReturnsFalseForAnInvalidEmailAddress($address) {
-               $this->assertTrue($this->validator->validate($address)->hasErrors());
+               /** @var \TYPO3\CMS\Extbase\Validation\Validator\EmailAddressValidator|\PHPUnit_Framework_MockObject_MockObject $subject */
+               $subject = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\EmailAddressValidator', array('translateErrorMessage'));
+               $this->assertTrue($subject->validate($address)->hasErrors());
        }
 
        /**
         * @test
-        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
        public function emailValidatorCreatesTheCorrectErrorForAnInvalidEmailAddress() {
-               $this->assertEquals(1, count($this->validator->validate('notAValidMail@Address')->getErrors()));
+               /** @var \TYPO3\CMS\Extbase\Validation\Validator\EmailAddressValidator|\PHPUnit_Framework_MockObject_MockObject $subject */
+               $subject = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\EmailAddressValidator', array('translateErrorMessage'));
+               $this->assertEquals(1, count($subject->validate('notAValidMail@Address')->getErrors()));
        }
 }
index 0fcd973..a2c024a 100644 (file)
@@ -30,6 +30,10 @@ class FloatValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation\Valida
 
        protected $validatorClassName = 'TYPO3\\CMS\\Extbase\\Validation\\Validator\\FloatValidator';
 
+       public function setup() {
+               $this->validator = $this->getMock($this->validatorClassName, array('translateErrorMessage'));
+       }
+
        /**
         * Data provider with valid floats
         *
index 8d46cde..bdeaf29 100644 (file)
@@ -30,6 +30,10 @@ class IntegerValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation\Vali
 
        protected $validatorClassName = 'TYPO3\\CMS\\Extbase\\Validation\\Validator\\IntegerValidator';
 
+       public function setup() {
+               $this->validator = $this->getMock($this->validatorClassName, array('translateErrorMessage'));
+       }
+
        /**
         * Data provider with valid integers
         *
index 4de1801..19e88c2 100644 (file)
@@ -30,6 +30,10 @@ class NotEmptyValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation\Val
 
        protected $validatorClassName = 'TYPO3\\CMS\\Extbase\\Validation\\Validator\\NotEmptyValidator';
 
+       public function setup() {
+               $this->validator = $this->getMock($this->validatorClassName, array('translateErrorMessage'));
+       }
+
        /**
         * @test
         * @author Andreas Förthner <andreas.foerthner@netlogix.de>
index 6797fb6..101c6d8 100644 (file)
@@ -26,7 +26,7 @@ namespace TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator;
  *
  * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
  */
-class NumberRangeValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\AbstractValidatorTestcase {
+class NumberRangeValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
 
        protected $validatorClassName = 'TYPO3\\CMS\\Extbase\\Validation\\Validator\\NumberRangeValidator';
 
@@ -35,8 +35,9 @@ class NumberRangeValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation\
         * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
        public function numberRangeValidatorReturnsNoErrorForASimpleIntegerInRange() {
-               $this->validatorOptions(array('minimum' => 0, 'maximum' => 1000));
-               $this->assertFalse($this->validator->validate(10.5)->hasErrors());
+               $options = array('minimum' => 0, 'maximum' => 1000);
+               $validator = $this->getMock($this->validatorClassName, array('dummy'), array($options));
+               $this->assertFalse($validator->validate(10.5)->hasErrors());
        }
 
        /**
@@ -44,8 +45,9 @@ class NumberRangeValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation\
         * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
        public function numberRangeValidatorReturnsErrorForANumberOutOfRange() {
-               $this->validatorOptions(array('minimum' => 0, 'maximum' => 1000));
-               $this->assertTrue($this->validator->validate(1000.1)->hasErrors());
+               $options = array('minimum' => 0, 'maximum' => 1000);
+               $validator = $this->getMock($this->validatorClassName, array('translateErrorMessage'), array($options));
+               $this->assertTrue($validator->validate(1000.1)->hasErrors());
        }
 
        /**
@@ -53,8 +55,9 @@ class NumberRangeValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation\
         * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
        public function numberRangeValidatorReturnsNoErrorForANumberInReversedRange() {
-               $this->validatorOptions(array('minimum' => 1000, 'maximum' => 0));
-               $this->assertFalse($this->validator->validate(100)->hasErrors());
+               $options = array('minimum' => 1000, 'maximum' => 0);
+               $validator = $this->getMock($this->validatorClassName, array('dummy'), array($options));
+               $this->assertFalse($validator->validate(100)->hasErrors());
        }
 
        /**
@@ -62,7 +65,8 @@ class NumberRangeValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation\
         * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
        public function numberRangeValidatorReturnsErrorForAString() {
-               $this->validatorOptions(array('minimum' => 0, 'maximum' => 1000));
-               $this->assertTrue($this->validator->validate('not a number')->hasErrors());
+               $options = array('minimum' => 0, 'maximum' => 1000);
+               $validator = $this->getMock($this->validatorClassName, array('translateErrorMessage'), array($options));
+               $this->assertTrue($validator->validate('not a number')->hasErrors());
        }
 }
index d609204..cf36a4b 100644 (file)
@@ -26,16 +26,24 @@ namespace TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator;
  *
  * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
  */
-class NumberValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\AbstractValidatorTestcase {
+class NumberValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
 
        protected $validatorClassName = 'TYPO3\\CMS\\Extbase\\Validation\\Validator\\NumberValidator';
 
        /**
+        * @var \TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface
+        */
+       protected $validator;
+
+       public function setup() {
+               $this->validator = $this->getMock($this->validatorClassName, array('translateErrorMessage'));
+       }
+
+       /**
         * @test
         */
        public function numberValidatorReturnsTrueForASimpleInteger() {
-               $numberValidator = new \TYPO3\CMS\Extbase\Validation\Validator\NumberValidator();
-               $this->assertFalse($numberValidator->validate(1029437)->hasErrors());
+               $this->assertFalse($this->validator->validate(1029437)->hasErrors());
        }
 
        /**
@@ -43,8 +51,8 @@ class NumberValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation\Valid
         */
        public function numberValidatorReturnsFalseForAString() {
                $expectedResult = new \TYPO3\CMS\Extbase\Error\Result();
-               $expectedResult->addError(new \TYPO3\CMS\Extbase\Validation\Error('The given subject was not a valid number.', 1221563685));
-               $numberValidator = new \TYPO3\CMS\Extbase\Validation\Validator\NumberValidator();
-               $this->assertEquals($expectedResult, $numberValidator->validate('not a number'));
+               // we only test for the error code, after the message translation method is mocked
+               $expectedResult->addError(new \TYPO3\CMS\Extbase\Validation\Error(NULL, 1221563685));
+               $this->assertEquals($expectedResult, $this->validator->validate('not a number'));
        }
 }
index e72e2ec..f667e4e 100644 (file)
@@ -26,18 +26,20 @@ namespace TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator;
  *
  * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
  */
-class RegularExpressionValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\AbstractValidatorTestcase {
+class RegularExpressionValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
 
        protected $validatorClassName = 'TYPO3\\CMS\\Extbase\\Validation\\Validator\\RegularExpressionValidator';
 
+
        /**
         * @test
         * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
        public function regularExpressionValidatorMatchesABasicExpressionCorrectly() {
-               $this->validatorOptions(array('regularExpression' => '/^simple[0-9]expression$/'));
-               $this->assertFalse($this->validator->validate('simple1expression')->hasErrors());
-               $this->assertTrue($this->validator->validate('simple1expressions')->hasErrors());
+               $options = array('regularExpression' => '/^simple[0-9]expression$/');
+               $validator = $this->getMock($this->validatorClassName, array('translateErrorMessage'), array($options));
+               $this->assertFalse($validator->validate('simple1expression')->hasErrors());
+               $this->assertTrue($validator->validate('simple1expressions')->hasErrors());
        }
 
        /**
@@ -45,8 +47,10 @@ class RegularExpressionValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Valid
         * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
        public function regularExpressionValidatorCreatesTheCorrectErrorIfTheExpressionDidNotMatch() {
-               $this->validatorOptions(array('regularExpression' => '/^simple[0-9]expression$/'));
-               $errors = $this->validator->validate('some subject that will not match')->getErrors();
-               $this->assertEquals(array(new \TYPO3\CMS\Extbase\Validation\Error('The given subject did not match the pattern.', 1221565130)), $errors);
+               $options = array('regularExpression' => '/^simple[0-9]expression$/');
+               $validator = $this->getMock($this->validatorClassName, array('translateErrorMessage'), array($options));
+               $errors = $validator->validate('some subject that will not match')->getErrors();
+               // we only test for the error code, after the translation Method for message is mocked anyway
+               $this->assertEquals(array(new \TYPO3\CMS\Extbase\Validation\Error(NULL, 1221565130)), $errors);
        }
 }
index a92e953..bd36176 100644 (file)
@@ -26,12 +26,16 @@ namespace TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator;
  *
  * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
  */
-class StringLengthValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\AbstractValidatorTestcase {
+class StringLengthValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
 
        protected $validatorClassName = 'TYPO3\\CMS\\Extbase\\Validation\\Validator\\StringLengthValidator';
 
+       public function setup() {
+               $this->validator = $this->getMock($this->validatorClassName, array('translateErrorMessage'));
+       }
+
        /**
-        * @var \TYPO3\Flow\Validation\Validator\StringLengthValidator
+        * @var \TYPO3\CMS\Extbase\Validation\Validator\StringLengthValidator
         */
        protected $validator;
 
@@ -53,24 +57,27 @@ class StringLengthValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation
         * @test
         */
        public function stringLengthValidatorReturnsNoErrorForAStringShorterThanMaxLengthAndLongerThanMinLength() {
-               $this->validatorOptions(array('minimum' => 0, 'maximum' => 50));
-               $this->assertFalse($this->validator->validate('this is a very simple string')->hasErrors());
+               $options = array('minimum' => 0, 'maximum' => 50);
+               $validator = $this->getMock($this->validatorClassName, array('dummy'), array($options));
+               $this->assertFalse($validator->validate('this is a very simple string')->hasErrors());
        }
 
        /**
         * @test
         */
        public function stringLengthValidatorReturnsErrorForAStringShorterThanThanMinLength() {
-               $this->validatorOptions(array('minimum' => 50, 'maximum' => 100));
-               $this->assertTrue($this->validator->validate('this is a very short string')->hasErrors());
+               $options = array('minimum' => 50, 'maximum' => 100);
+               $validator = $this->getMock($this->validatorClassName, array('translateErrorMessage'), array($options));
+               $this->assertTrue($validator->validate('this is a very short string')->hasErrors());
        }
 
        /**
         * @test
         */
        public function stringLengthValidatorReturnsErrorsForAStringLongerThanThanMaxLength() {
-               $this->validatorOptions(array('minimum' => 5, 'maximum' => 10));
-               $this->assertTrue($this->validator->validate('this is a very short string')->hasErrors());
+               $options = array('minimum' => 5, 'maximum' => 10);
+               $validator = $this->getMock($this->validatorClassName, array('translateErrorMessage'), array($options));
+               $this->assertTrue($validator->validate('this is a very short string')->hasErrors());
        }
 
        /**
@@ -78,24 +85,27 @@ class StringLengthValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation
         * @expectedException \TYPO3\CMS\Extbase\Validation\Exception\InvalidValidationOptionsException
         */
        public function stringLengthValidatorReturnsNoErrorsForAStringLongerThanThanMinLengthAndMaxLengthNotSpecified() {
-               $this->validatorOptions(array('minimum' => 5));
-               $this->assertFalse($this->validator->validate('this is a very short string')->hasErrors());
+               $options = array('minimum' => 5);
+               $validator = $this->getMock($this->validatorClassName, array('dummy'), array($options));
+               $this->assertFalse($validator->validate('this is a very short string')->hasErrors());
        }
 
        /**
         * @test
         */
        public function stringLengthValidatorReturnsNoErrorsForAStringShorterThanThanMaxLengthAndMinLengthNotSpecified() {
-               $this->validatorOptions(array('maximum' => 100));
-               $this->assertFalse($this->validator->validate('this is a very short string')->hasErrors());
+               $options = array('maximum' => 100);
+               $validator = $this->getMock($this->validatorClassName, array('dummy'), array($options));
+               $this->assertFalse($validator->validate('this is a very short string')->hasErrors());
        }
 
        /**
         * @test
         */
        public function stringLengthValidatorReturnsNoErrorsForAStringLengthEqualToMaxLengthAndMinLengthNotSpecified() {
-               $this->validatorOptions(array('maximum' => 10));
-               $this->assertFalse($this->validator->validate('1234567890')->hasErrors());
+               $options = array('maximum' => 10);
+               $validator = $this->getMock($this->validatorClassName, array('dummy'), array($options));
+               $this->assertFalse($validator->validate('1234567890')->hasErrors());
        }
 
        /**
@@ -103,32 +113,36 @@ class StringLengthValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation
         * @expectedException \TYPO3\CMS\Extbase\Validation\Exception\InvalidValidationOptionsException
         */
        public function stringLengthValidatorReturnsNoErrorForAStringLengthEqualToMinLengthAndMaxLengthNotSpecified() {
-               $this->validatorOptions(array('minimum' => 10));
-               $this->assertFalse($this->validator->validate('1234567890')->hasErrors());
+               $options = array('minimum' => 10);
+               $validator = $this->getMock($this->validatorClassName, array('dummy'), array($options));
+               $this->assertFalse($validator->validate('1234567890')->hasErrors());
        }
 
        /**
         * @test
         */
        public function stringLengthValidatorReturnsNoErrorIfMinLengthAndMaxLengthAreEqualAndTheGivenStringMatchesThisValue() {
-               $this->validatorOptions(array('minimum' => 10, 'maximum' => 10));
-               $this->assertFalse($this->validator->validate('1234567890')->hasErrors());
+               $options = array('minimum' => 10, 'maximum' => 10);
+               $validator = $this->getMock($this->validatorClassName, array('dummy'), array($options));
+               $this->assertFalse($validator->validate('1234567890')->hasErrors());
        }
 
        /**
         * @test
         */
        public function stringLengthValidatorReturnsNoErrorsfTheStringLengthIsEqualToMaxLength() {
-               $this->validatorOptions(array('minimum' => 1, 'maximum' => 10));
-               $this->assertFalse($this->validator->validate('1234567890')->hasErrors());
+               $options = array('minimum' => 1, 'maximum' => 10);
+               $validator = $this->getMock($this->validatorClassName, array('dummy'), array($options));
+               $this->assertFalse($validator->validate('1234567890')->hasErrors());
        }
 
        /**
         * @test
         */
        public function stringLengthValidatorReturnsNoErrorIfTheStringLengthIsEqualToMinLength() {
-               $this->validatorOptions(array('minimum' => 10, 'maximum' => 100));
-               $this->assertFalse($this->validator->validate('1234567890')->hasErrors());
+               $options = array('minimum' => 10, 'maximum' => 100);
+               $validator = $this->getMock($this->validatorClassName, array('dummy'), array($options));
+               $this->assertFalse($validator->validate('1234567890')->hasErrors());
        }
 
        /**
@@ -136,26 +150,26 @@ class StringLengthValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation
         * @expectedException \TYPO3\CMS\Extbase\Validation\Exception\InvalidValidationOptionsException
         */
        public function stringLengthValidatorThrowsAnExceptionIfMinLengthIsGreaterThanMaxLength() {
-               $this->validator = $this->getMock('TYPO3\Flow\Validation\Validator\StringLengthValidator', array('addError'), array(), '', FALSE);
-               $this->validatorOptions(array('minimum' => 101, 'maximum' => 100));
-               $this->validator->validate('1234567890');
+               $options = array('minimum' => 101, 'maximum' => 100);
+               $validator = $this->getMock($this->validatorClassName, array('addError', 'translateErrorMessage'), array($options));
+               $validator->validate('1234567890');
        }
 
        /**
         * @test
         */
        public function stringLengthValidatorInsertsAnErrorObjectIfValidationFails() {
-               $this->validatorOptions(array('minimum' => 50, 'maximum' => 100));
-
-               $this->assertEquals(1, count($this->validator->validate('this is a very short string')->getErrors()));
+               $options = array('minimum' => 50, 'maximum' => 100);
+               $validator = $this->getMock($this->validatorClassName, array('translateErrorMessage'), array($options));
+               $this->assertEquals(1, count($validator->validate('this is a very short string')->getErrors()));
        }
 
        /**
         * @test
         */
        public function stringLengthValidatorCanHandleAnObjectWithAToStringMethod() {
-               $this->validator = $this->getMock('TYPO3\Flow\Validation\Validator\StringLengthValidator', array('addError'), array(), '', FALSE);
-               $this->validatorOptions(array('minimum' => 5, 'maximum' => 100));
+               $options = array('minimum' => 5, 'maximum' => 100);
+               $validator = $this->getMock($this->validatorClassName, array('addError', 'translateErrorMessage'), array($options));
 
                $className = 'TestClass' . md5(uniqid(mt_rand(), TRUE));
 
@@ -168,15 +182,15 @@ class StringLengthValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation
                ');
 
                $object = new $className();
-               $this->assertFalse($this->validator->validate($object)->hasErrors());
+               $this->assertFalse($validator->validate($object)->hasErrors());
        }
 
        /**
         * @test
         */
        public function validateReturnsErrorsIfTheGivenObjectCanNotBeConvertedToAString() {
-               $this->validator = $this->getMock('TYPO3\Flow\Validation\Validator\StringLengthValidator', array('addError'), array(), '', FALSE);
-               $this->validatorOptions(array('minimum' => 5, 'maximum' => 100));
+               $options = array('minimum' => 5, 'maximum' => 100);
+               $validator = $this->getMock($this->validatorClassName, array('translateErrorMessage'), array($options));
 
                $className = 'TestClass' . md5(uniqid(mt_rand(), TRUE));
 
@@ -187,7 +201,7 @@ class StringLengthValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation
                ');
 
                $object = new $className();
-               $this->assertTrue($this->validator->validate($object)->hasErrors());
+               $this->assertTrue($validator->validate($object)->hasErrors());
        }
 
        /**
index 4cfbeb8..dcba3fe 100644 (file)
@@ -30,6 +30,10 @@ class StringValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation\Valid
 
        protected $validatorClassName = 'TYPO3\\CMS\\Extbase\\Validation\\Validator\\StringValidator';
 
+       public function setup() {
+               $this->validator = $this->getMock($this->validatorClassName, array('translateErrorMessage'));
+       }
+
        /**
         * @test
         * @author Sebastian Kurfürst <sebastian@typo3.org>
index 898ad89..93d5d8f 100644 (file)
@@ -30,6 +30,10 @@ class TextValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation\Validat
 
        protected $validatorClassName = 'TYPO3\\CMS\\Extbase\\Validation\\Validator\\TextValidator';
 
+       public function setup() {
+               $this->validator = $this->getMock($this->validatorClassName, array('translateErrorMessage'));
+       }
+
        /**
         * @test
         * @author Andreas Förthner <andreas.foerthner@netlogix.de>
@@ -69,7 +73,8 @@ class TextValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation\Validat
         * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
        public function textValidatorCreatesTheCorrectErrorIfTheSubjectContainsHtmlEntities() {
-               $expected = array(new \TYPO3\CMS\Extbase\Validation\Error('The given subject was not a valid text (e.g. contained XML tags).', 1221565786));
+               // we only test for the error code, after the translation Method for message is mocked anyway
+               $expected = array(new \TYPO3\CMS\Extbase\Validation\Error(NULL, 1221565786));
                $this->assertEquals($expected, $this->validator->validate('<span style="color: #BBBBBB;">a nice text</span>')->getErrors());
        }
 }