[TASK] Use language labels in BooleanValidator 20/39620/3
authorFrederic Gaus <frederic.gaus@flagbit.de>
Tue, 19 May 2015 11:19:21 +0000 (13:19 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Tue, 23 Jun 2015 20:29:20 +0000 (22:29 +0200)
Use language labels instead of simple strings in BooleanValidator

Change-Id: Icc25bd1a08d9a162ca23c018a791e07ac04533f7
Resolves: #66973
Releases: master
Reviewed-on: http://review.typo3.org/39620
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/extbase/Classes/Validation/Validator/BooleanValidator.php
typo3/sysext/extbase/Resources/Private/Language/locallang.xlf
typo3/sysext/extbase/Tests/Unit/Validation/Validator/BooleanValidatorTest.php

index abbf233..6114708 100644 (file)
@@ -64,12 +64,21 @@ class BooleanValidator extends AbstractValidator {
 
                if ($value !== $expectation) {
                        if (!is_bool($value)) {
-                               $this->addError('The given subject is not true.', 1361959230);
+                               $this->addError($this->translateErrorMessage(
+                                       'validator.boolean.nottrue',
+                                       'extbase'
+                               ), 1361959230);
                        } else {
                                if ($expectation) {
-                                       $this->addError('The given subject is not true.', 1361959228);
+                                       $this->addError($this->translateErrorMessage(
+                                               'validator.boolean.nottrue',
+                                               'extbase'
+                                       ), 1361959228);
                                } else {
-                                       $this->addError('The given subject is not false.', 1361959229);
+                                       $this->addError($this->translateErrorMessage(
+                                               'validator.boolean.notfalse',
+                                               'extbase'
+                                       ), 1361959229);
                                }
                        }
                }
index fb2ab65..731f206 100644 (file)
                        <trans-unit id="validator.integer.notvalid">
                                <source>The given subject was not a valid integer.</source>
                        </trans-unit>
+                       <trans-unit id="validator.boolean.nottrue">
+                               <source>The given subject was not true.</source>
+                       </trans-unit>
+                       <trans-unit id="validator.boolean.notfalse">
+                               <source>The given subject was not false.</source>
+                       </trans-unit>
                </body>
        </file>
 </xliff>
index cf6a171..eaeb43b 100644 (file)
@@ -35,8 +35,9 @@ class BooleanValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation\Vali
         * @author Pascal Dürsteler <pascal.duersteler@gmail.com>
         */
        public function booleanValidatorReturnsNoErrorForAFalseStringExpectation() {
-               $this->validatorOptions(array('is' => 'false'));
-               $this->assertFalse($this->validator->validate(FALSE)->hasErrors());
+               $options = array('is' => 'false');
+               $validator = $this->getMock($this->validatorClassName, array('translateErrorMessage'), array($options));
+               $this->assertFalse($validator->validate(FALSE)->hasErrors());
        }
 
        /**
@@ -44,8 +45,9 @@ class BooleanValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation\Vali
         * @author Pascal Dürsteler <pascal.duersteler@gmail.com>
         */
        public function booleanValidatorReturnsNoErrorForATrueStringExpectation() {
-               $this->validatorOptions(array('is' => 'true'));
-               $this->assertFalse($this->validator->validate(TRUE)->hasErrors());
+               $options = array('is' => 'true');
+               $validator = $this->getMock($this->validatorClassName, array('translateErrorMessage'), array($options));
+               $this->assertFalse($validator->validate(TRUE)->hasErrors());
        }
 
        /**
@@ -53,8 +55,9 @@ class BooleanValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation\Vali
         * @author Pascal Dürsteler <pascal.duersteler@gmail.com>
         */
        public function booleanValidatorReturnsNoErrorForATrueExpectation() {
-               $this->validatorOptions(array('is' => TRUE));
-               $this->assertFalse($this->validator->validate(TRUE)->hasErrors());
+               $options = array('is' => TRUE);
+               $validator = $this->getMock($this->validatorClassName, array('translateErrorMessage'), array($options));
+               $this->assertFalse($validator->validate(TRUE)->hasErrors());
        }
 
        /**
@@ -62,8 +65,9 @@ class BooleanValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation\Vali
         * @author Pascal Dürsteler <pascal.duersteler@gmail.com>
         */
        public function booleanValidatorReturnsNoErrorForAFalseExpectation() {
-               $this->validatorOptions(array('is' => FALSE));
-               $this->assertFalse($this->validator->validate(FALSE)->hasErrors());
+               $options = array('is' => FALSE);
+               $validator = $this->getMock($this->validatorClassName, array('translateErrorMessage'), array($options));
+               $this->assertFalse($validator->validate(FALSE)->hasErrors());
        }
 
        /**
@@ -71,8 +75,9 @@ class BooleanValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation\Vali
         * @author Pascal Dürsteler <pascal.duersteler@gmail.com>
         */
        public function booleanValidatorReturnsErrorForTrueWhenFalseExpected() {
-               $this->validatorOptions(array('is' => FALSE));
-               $this->assertTrue($this->validator->validate(TRUE)->hasErrors());
+               $options = array('is' => FALSE);
+               $validator = $this->getMock($this->validatorClassName, array('translateErrorMessage'), array($options));
+               $this->assertTrue($validator->validate(TRUE)->hasErrors());
        }
 
        /**
@@ -80,8 +85,9 @@ class BooleanValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation\Vali
         * @author Pascal Dürsteler <pascal.duersteler@gmail.com>
         */
        public function booleanValidatorReturnsErrorForFalseWhenTrueExpected() {
-               $this->validatorOptions(array('is' => TRUE));
-               $this->assertTrue($this->validator->validate(FALSE)->hasErrors());
+               $options = array('is' => TRUE);
+               $validator = $this->getMock($this->validatorClassName, array('translateErrorMessage'), array($options));
+               $this->assertTrue($validator->validate(FALSE)->hasErrors());
        }
 
        /**
@@ -89,16 +95,18 @@ class BooleanValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation\Vali
         * @author Pascal Dürsteler <pascal.duersteler@gmail.com>
         */
        public function booleanValidatorReturnsErrorForAString() {
-               $this->validatorOptions(array('is' => TRUE));
-               $this->assertTrue($this->validator->validate('a string')->hasErrors());
+               $options = array('is' => TRUE);
+               $validator = $this->getMock($this->validatorClassName, array('translateErrorMessage'), array($options));
+               $this->assertTrue($validator->validate('a string')->hasErrors());
        }
 
        /**
         * @test
         */
        public function booleanValidatorReturnsTrueIfNoParameterIsGiven() {
-               $this->validatorOptions(array());
-               $this->assertFalse($this->validator->validate(TRUE)->hasErrors());
+               $options = array();
+               $validator = $this->getMock($this->validatorClassName, array('translateErrorMessage'), array($options));
+               $this->assertFalse($validator->validate(TRUE)->hasErrors());
        }
 
 }