[BUGFIX] Follow-Up: Fix major bug in Enumeration::equals + Tests 34/24634/11
authorSascha Egerer <sascha.egerer@dkd.de>
Sat, 12 Oct 2013 15:29:10 +0000 (17:29 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Sun, 13 Oct 2013 09:58:28 +0000 (11:58 +0200)
* Fixed major bug in Enumeration->equals method by
  changing object comparison to loose comparison
* Optimized Enumeration at some places
* Do not throw generic exceptions but specific exceptions
* Add Unit tests
* Move "cast" function from VersionState to Enumeration

Resolves: #52551
Releases: 6.2
Change-Id: Ief64bc08e474c38036d34ed3791c13e39661e9b3
Reviewed-on: https://review.typo3.org/24634
Reviewed-by: Sebastian Fischer
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
typo3/sysext/core/Classes/Type/Enumeration.php
typo3/sysext/core/Classes/Type/Exception.php [new file with mode: 0644]
typo3/sysext/core/Classes/Type/Exception/InvalidEnumerationDefinitionException.php [new file with mode: 0644]
typo3/sysext/core/Classes/Type/Exception/InvalidEnumerationValueException.php [new file with mode: 0644]
typo3/sysext/core/Classes/Versioning/VersionState.php
typo3/sysext/core/Tests/Unit/Type/EnumerationTest.php [new file with mode: 0644]
typo3/sysext/core/Tests/Unit/Type/Fixture/Enumeration/CompleteEnumeration.php [new file with mode: 0644]
typo3/sysext/core/Tests/Unit/Type/Fixture/Enumeration/DuplicateConstantValueEnumeration.php [new file with mode: 0644]
typo3/sysext/core/Tests/Unit/Type/Fixture/Enumeration/InvalidConstantEnumeration.php [new file with mode: 0644]
typo3/sysext/core/Tests/Unit/Type/Fixture/Enumeration/MissingConstantsEnumeration.php [new file with mode: 0644]
typo3/sysext/core/Tests/Unit/Type/Fixture/Enumeration/MissingDefaultEnumeration.php [new file with mode: 0644]

index 1fd7fb1..8ff67f8 100644 (file)
@@ -27,6 +27,8 @@ namespace TYPO3\CMS\Core\Type;
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
 
+use TYPO3\CMS\Core\Type\Exception;
+
 /**
  * Abstract class for Enumeration.
  * Inspired by SplEnum.
@@ -37,7 +39,7 @@ namespace TYPO3\CMS\Core\Type;
 abstract class Enumeration {
 
        /**
-        * @var string
+        * @var mixed
         */
        protected $value;
 
@@ -48,19 +50,24 @@ abstract class Enumeration {
 
        /**
         * @param mixed $value
-        * @throws \DomainException
-        * @throws \UnexpectedValueException
+        * @throws Exception\InvalidEnumerationValueException
         */
        public function __construct($value = NULL) {
-               if (!defined('static::__default')) {
-                       throw new \DomainException(sprintf("Required constant __default for Enum %s is not defined", __CLASS__), 1381512753);
+               if ($value === NULL && !defined('static::__default')) {
+                       throw new Exception\InvalidEnumerationValueException(
+                               sprintf('A value for %s is required if no __default is defined.', __CLASS__),
+                               1381512753
+                       );
                }
                if ($value === NULL) {
                        $value = static::__default;
                }
                $this->loadValues();
                if (!$this->isValid($value)) {
-                       throw new \UnexpectedValueException(sprintf("Invalid enumeration %s for Enum %s", $value, __CLASS__), 1381512761);
+                       throw new Exception\InvalidEnumerationValueException(
+                               sprintf('Invalid value %s for %s', $value, __CLASS__),
+                               1381512761
+                       );
                }
                $this->setValue($value);
        }
@@ -77,12 +84,14 @@ abstract class Enumeration {
                }
 
                $reflection = new \ReflectionClass($class);
-               $constants  = $reflection->getConstants();
+               $constants = $reflection->getConstants();
+               $defaultValue = NULL;
                if (isset($constants['__default'])) {
+                       $defaultValue = $constants['__default'];
                        unset($constants['__default']);
                }
                if (empty($constants)) {
-                       throw new \Exception(
+                       throw new Exception\InvalidEnumerationValueException(
                                sprintf(
                                        'No enumeration constants defined for "%s"', $class
                                ),
@@ -91,7 +100,7 @@ abstract class Enumeration {
                }
                foreach ($constants as $constant => $value) {
                        if (!is_int($value) && !is_string($value)) {
-                               throw new \Exception(
+                               throw new Exception\InvalidEnumerationDefinitionException(
                                        sprintf(
                                                'Constant value must be of type integer or string; constant=%s; type=%s',
                                                $constant,
@@ -106,7 +115,7 @@ abstract class Enumeration {
                $constantValueCount = current($constantValueCounts);
                $constant = key($constantValueCounts);
                if ($constantValueCount > 1) {
-                       throw new \Exception(
+                       throw new Exception\InvalidEnumerationDefinitionException(
                                sprintf(
                                        'Constant value is not unique; constant=%s; value=%s; enum=%s',
                                        $constant, $constantValueCount, $class
@@ -114,14 +123,28 @@ abstract class Enumeration {
                                1381512859
                        );
                }
+               if ($defaultValue !== NULL) {
+                       $constants['__default'] = $defaultValue;
+               }
                static::$enumConstants[$class] = $constants;
        }
 
        /**
+        * Set the Enumeration value to the associated enumeration value by a loose comparison.
+        * The value, that is used as the enumeration value, will be of the same type like defined in the enumeration
+        *
         * @param mixed $value
+        * @throws Exception\InvalidEnumerationValueException
         */
        protected function setValue($value) {
-               $this->value = $value;
+               $enumKey = array_search($value, static::$enumConstants[get_called_class()]);
+               if ($enumKey === FALSE) {
+                       throw new Exception\InvalidEnumerationValueException(
+                               sprintf('Invalid value %s for %s', $value, __CLASS__),
+                               1381615295
+                       );
+               }
+               $this->value = static::$enumConstants[get_called_class()][$enumKey];
        }
 
        /**
@@ -151,17 +174,28 @@ abstract class Enumeration {
        }
 
        /**
+        * Cast value to enumeration type
+        *
+        * @param mixed $value Value that has to be casted
+        * @return Enumeration
+        */
+       public static function cast($value) {
+               $currentClass = get_called_class();
+               if (!is_object($value) || get_class($value) !== $currentClass) {
+                       $value = new $currentClass($value);
+               }
+               return $value;
+       }
+
+       /**
         * Compare if the value of the current object value equals the given value
         *
         * @param mixed $value default
         * @return boolean
         */
        public function equals($value) {
-               $currentClass = get_class($this);
-               if (!is_object($value) || get_class($value) !== $currentClass) {
-                       $value = new $currentClass($value);
-               }
-               return $this === $value;
+               $value = static::cast($value);
+               return $this == $value;
        }
 
        /**
diff --git a/typo3/sysext/core/Classes/Type/Exception.php b/typo3/sysext/core/Classes/Type/Exception.php
new file mode 100644 (file)
index 0000000..350d67c
--- /dev/null
@@ -0,0 +1,34 @@
+<?php
+namespace TYPO3\CMS\Core\Type;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2013 Sascha Egerer <sascha.egerer@dkd.de>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *  A copy is found in the textfile GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
+ *
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+/**
+ * A generic Type exception
+ */
+class Exception extends \TYPO3\CMS\Core\Exception {
+
+}
diff --git a/typo3/sysext/core/Classes/Type/Exception/InvalidEnumerationDefinitionException.php b/typo3/sysext/core/Classes/Type/Exception/InvalidEnumerationDefinitionException.php
new file mode 100644 (file)
index 0000000..d38b6a6
--- /dev/null
@@ -0,0 +1,34 @@
+<?php
+namespace TYPO3\CMS\Core\Type\Exception;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2013 Sascha Egerer <sascha.egerer@dkd.de>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *  A copy is found in the textfile GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
+ *
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+/**
+ * Exception for an invalid enumeration definition
+ */
+class InvalidEnumerationDefinitionException extends \TYPO3\CMS\Core\Type\Exception {
+
+}
diff --git a/typo3/sysext/core/Classes/Type/Exception/InvalidEnumerationValueException.php b/typo3/sysext/core/Classes/Type/Exception/InvalidEnumerationValueException.php
new file mode 100644 (file)
index 0000000..7ba52bf
--- /dev/null
@@ -0,0 +1,34 @@
+<?php
+namespace TYPO3\CMS\Core\Type\Exception;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2013 Sascha Egerer <sascha.egerer@dkd.de>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *  A copy is found in the textfile GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
+ *
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+/**
+ * Exception for an invalid enumeration value
+ */
+class InvalidEnumerationValueException extends \TYPO3\CMS\Core\Type\Exception {
+
+}
index e5e7807..3dcf78b 100644 (file)
@@ -85,29 +85,6 @@ class VersionState extends \TYPO3\CMS\Core\Type\Enumeration {
        const MOVE_POINTER = 4;
 
        /**
-        * @param mixed $value
-        */
-       public function __construct($value = NULL) {
-               if($value !== NULL) {
-                       $value = (int)$value;
-               }
-               parent::__construct($value);
-       }
-
-       /**
-        * Cast value to VersionState Object
-        *
-        * @param mixed $versionState A value that is casted to a VersionState or a VersionState object that is returned
-        * @return VersionState
-        */
-       public static function cast($versionState) {
-               if (!$versionState instanceof VersionState) {
-                       $versionState = new VersionState($versionState);
-               }
-               return $versionState;
-       }
-
-       /**
         * @return boolean
         */
        public function indicatesPlaceholder() {
diff --git a/typo3/sysext/core/Tests/Unit/Type/EnumerationTest.php b/typo3/sysext/core/Tests/Unit/Type/EnumerationTest.php
new file mode 100644 (file)
index 0000000..5cc70a0
--- /dev/null
@@ -0,0 +1,283 @@
+<?php
+namespace TYPO3\CMS\Core\Tests\Unit\Type;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2013 Sascha Egerer <sascha.egerer@dkd.de>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+use TYPO3\CMS\Core\Tests\Unit\Type\Fixture\Enumeration;
+use TYPO3\CMS\Core\Type;
+
+/**
+ * Testcase for class \TYPO3\CMS\Core\Type\Enumeration
+ */
+class EnumerationTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
+
+       /**
+        * @test
+        * @expectedException \TYPO3\CMS\Core\Type\Exception\InvalidEnumerationValueException
+        */
+       public function constructThrowsExceptionIfNoConstantsAreDefined() {
+               new Enumeration\MissingConstantsEnumeration();
+       }
+
+       /**
+        * @test
+        * @expectedException \TYPO3\CMS\Core\Type\Exception\InvalidEnumerationValueException
+        */
+       public function loadValuesThrowsExceptionIfGivenValueIsNotAvailableInEnumeration() {
+               new Enumeration\MissingConstantsEnumeration(2);
+       }
+
+       /**
+        * @test
+        * @expectedException \TYPO3\CMS\Core\Type\Exception\InvalidEnumerationDefinitionException
+        */
+       public function loadValuesThrowsExceptionIfDisallowedTypeIsDefinedAsConstant() {
+               new Enumeration\InvalidConstantEnumeration(1);
+       }
+
+       /**
+        * @test
+        * @expectedException \TYPO3\CMS\Core\Type\Exception\InvalidEnumerationValueException
+        */
+       public function loadValuesThrowsExceptionIfNoDefaultConstantIsDefinedAndNoValueIsGiven() {
+               new Enumeration\MissingDefaultEnumeration();
+       }
+
+       /**
+        * @test
+        * @expectedException \TYPO3\CMS\Core\Type\Exception\InvalidEnumerationDefinitionException
+        */
+       public function loadValuesThrowsExceptionIfValueIsDefinedMultipleTimes() {
+               new Enumeration\DuplicateConstantValueEnumeration(1);
+       }
+
+       /**
+        * @test
+        */
+       public function loadValuesSetsStaticEnumConstants() {
+               $enumeration = $this->getAccessibleMock(
+                       'TYPO3\\CMS\\Core\\Tests\\Unit\\Type\Fixture\\Enumeration\\CompleteEnumeration',
+                       array('dummy')
+               );
+
+               $expectedValue = array(
+                       get_class($enumeration) => array(
+                               'INTEGER_VALUE' => 1,
+                               'STRING_VALUE' => 'foo',
+                                '__default' => 1
+                       )
+               );
+
+               $this->assertEquals($expectedValue, $enumeration->_getStatic('enumConstants'));
+       }
+
+       /**
+        * @test
+        */
+       public function constructerSetsValue() {
+               $enumeration = $this->getAccessibleMock(
+                       'TYPO3\\CMS\\Core\\Tests\\Unit\\Type\Fixture\\Enumeration\\CompleteEnumeration',
+                       array('dummy'),
+                       array(1)
+               );
+               $this->assertEquals(1, $enumeration->_get('value'));
+       }
+
+       /**
+        * @test
+        */
+       public function setValueSetsValue() {
+               $enumeration = $this->getAccessibleMock(
+                       'TYPO3\\CMS\\Core\\Tests\\Unit\\Type\Fixture\\Enumeration\\CompleteEnumeration',
+                       array('dummy'),
+                       array(1)
+               );
+               $enumeration->_call('setValue', 'foo');
+               $this->assertEquals('foo', $enumeration->_get('value'));
+       }
+
+       /**
+        * @test
+        * @expectedException \TYPO3\CMS\Core\Type\Exception\InvalidEnumerationValueException
+        */
+       public function setValueToAnInvalidValueThrowsException() {
+               $enumeration = $this->getAccessibleMock(
+                       'TYPO3\\CMS\\Core\\Tests\\Unit\\Type\Fixture\\Enumeration\\CompleteEnumeration',
+                       array('dummy'),
+                       array(1)
+               );
+               $enumeration->_call('setValue', 2);
+               $this->assertEquals(2, $enumeration->_get('value'));
+       }
+
+       /**
+        * @test
+        */
+       public function isValueReturnsTrueIfValueIsValid() {
+               $enumeration = $this->getAccessibleMock(
+                       'TYPO3\\CMS\\Core\\Tests\\Unit\\Type\Fixture\\Enumeration\\CompleteEnumeration',
+                       array('dummy')
+               );
+               $this->assertTrue($enumeration->_call('isValid', 1));
+       }
+
+       /**
+        * @test
+        */
+       public function isValueReturnsFalseIfValueIsValid() {
+               $enumeration = $this->getAccessibleMock(
+                       'TYPO3\\CMS\\Core\\Tests\\Unit\\Type\Fixture\\Enumeration\\CompleteEnumeration',
+                       array('dummy')
+               );
+               $this->assertFalse($enumeration->_call('isValid', 2));
+       }
+
+       /**
+        * @test
+        */
+       public function getConstantsReturnsArrayOfPossibleValuesWithoutDefault() {
+               $enumeration = new Enumeration\CompleteEnumeration();
+
+               $this->assertEquals(array('INTEGER_VALUE' => 1, 'STRING_VALUE' => 'foo'), $enumeration->getConstants());
+       }
+
+       /**
+        * @test
+        */
+       public function getConstantsReturnsArrayOfPossibleValuesWithDefaultIfRequested() {
+               $enumeration = new Enumeration\CompleteEnumeration();
+               $this->assertEquals(array('INTEGER_VALUE' => 1, 'STRING_VALUE' => 'foo', '__default' => 1), $enumeration->getConstants(TRUE));
+       }
+
+       /**
+        * @test
+        */
+       public function toStringReturnsValueAsString() {
+               $enumeration = new Enumeration\CompleteEnumeration();
+               $this->assertSame('1', $enumeration->__toString());
+       }
+
+       /**
+        * @test
+        */
+       public function castReturnsObjectOfEnumerationTypeIfSimpleValueIsGiven() {
+               $enumeration = Enumeration\CompleteEnumeration::cast(1);
+               $this->assertInstanceOf('TYPO3\\CMS\\Core\\Tests\\Unit\\Type\Fixture\\Enumeration\\CompleteEnumeration', $enumeration);
+       }
+
+       /**
+        * @test
+        */
+       public function castReturnsObjectOfCalledEnumerationTypeIfCalledWithValueOfDifferentType() {
+               $initialEnumeration = new Enumeration\MissingDefaultEnumeration(1);
+               $enumeration = Enumeration\CompleteEnumeration::cast($initialEnumeration);
+               $this->assertInstanceOf('TYPO3\\CMS\\Core\\Tests\\Unit\\Type\Fixture\\Enumeration\\CompleteEnumeration', $enumeration);
+       }
+
+       /**
+        * @test
+        */
+       public function castReturnsGivenObjectIfCalledWithValueOfSameType() {
+               $initialEnumeration = new Enumeration\CompleteEnumeration(1);
+               $enumeration = Enumeration\CompleteEnumeration::cast($initialEnumeration);
+               $this->assertSame($initialEnumeration, $enumeration);
+       }
+
+       /**
+        * @test
+        */
+       public function castCastsStringToEnumerationWithCorrespondingValue() {
+               $enumeration = $this->getAccessibleMock(
+                       'TYPO3\\CMS\\Core\\Tests\\Unit\\Type\Fixture\\Enumeration\\CompleteEnumeration',
+                       array('dummy'),
+                       array('1')
+               );
+               $this->assertSame(1, $enumeration->_get('value'));
+       }
+
+       /**
+        * @test
+        */
+       public function castCastsIntegerToEnumerationWithCorrespondingValue() {
+               $enumeration = $this->getAccessibleMock(
+                       'TYPO3\\CMS\\Core\\Tests\\Unit\\Type\Fixture\\Enumeration\\CompleteEnumeration',
+                       array('dummy'),
+                       array(1)
+               );
+               $this->assertSame(1, $enumeration->_get('value'));
+       }
+
+       /**
+        * @test
+        */
+       public function equalsReturnsTrueIfIntegerIsGivenThatEqualsEnumerationsIntegerValue() {
+               $enumeration = new Enumeration\CompleteEnumeration(1);
+               $this->assertTrue($enumeration->equals(1));
+       }
+
+       /**
+        * @test
+        */
+       public function equalsReturnsTrueIfStringIsGivenThatEqualsEnumerationsIntegerValue() {
+               $enumeration = new Enumeration\CompleteEnumeration(1);
+               $this->assertTrue($enumeration->equals('1'));
+       }
+
+       /**
+        * @test
+        */
+       public function equalsReturnsTrueIfEqualEnumerationIsGiven() {
+               $enumerationFoo = new Enumeration\CompleteEnumeration(1);
+               $enumerationBar = new Enumeration\CompleteEnumeration(1);
+               $this->assertTrue($enumerationFoo->equals($enumerationBar));
+       }
+
+       /**
+        * @test
+        */
+       public function equalsReturnsTrueIfDifferentEnumerationWithSameValueIsGiven() {
+               $enumerationFoo = new Enumeration\CompleteEnumeration(1);
+               $enumerationBar = new Enumeration\MissingDefaultEnumeration(1);
+               $this->assertTrue($enumerationFoo->equals($enumerationBar));
+       }
+
+       /**
+        * @test
+        */
+       public function equalsReturnsFalseIfDifferentEnumerationWithDifferentValueIsGiven() {
+               $enumerationFoo = new Enumeration\CompleteEnumeration('foo');
+               $enumerationBar = new Enumeration\MissingDefaultEnumeration(1);
+               $this->assertFalse($enumerationFoo->equals($enumerationBar));
+       }
+
+       /**
+        * @test
+        */
+       public function equalsReturnsFalseIfEnumerationOfSameTypeWithDifferentValueIsGiven() {
+               $enumerationFoo = new Enumeration\CompleteEnumeration(1);
+               $enumerationBar = new Enumeration\CompleteEnumeration('foo');
+               $this->assertFalse($enumerationFoo->equals($enumerationBar));
+       }
+
+}
\ No newline at end of file
diff --git a/typo3/sysext/core/Tests/Unit/Type/Fixture/Enumeration/CompleteEnumeration.php b/typo3/sysext/core/Tests/Unit/Type/Fixture/Enumeration/CompleteEnumeration.php
new file mode 100644 (file)
index 0000000..2c9632f
--- /dev/null
@@ -0,0 +1,34 @@
+<?php
+namespace TYPO3\CMS\Core\Tests\Unit\Type\Fixture\Enumeration;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2013 Sascha Egerer <sascha.egerer@dkd.de>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * This is an complete enumeration with all possible constant values
+ */
+class CompleteEnumeration extends \TYPO3\CMS\Core\Type\Enumeration {
+       const __default = self::INTEGER_VALUE;
+       const INTEGER_VALUE = 1;
+       const STRING_VALUE = 'foo';
+}
\ No newline at end of file
diff --git a/typo3/sysext/core/Tests/Unit/Type/Fixture/Enumeration/DuplicateConstantValueEnumeration.php b/typo3/sysext/core/Tests/Unit/Type/Fixture/Enumeration/DuplicateConstantValueEnumeration.php
new file mode 100644 (file)
index 0000000..0851b25
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+namespace TYPO3\CMS\Core\Tests\Unit\Type\Fixture\Enumeration;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2013 Sascha Egerer <sascha.egerer@dkd.de>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * This is an invalid enumeration because the constant values are not unique
+ */
+class DuplicateConstantValueEnumeration extends \TYPO3\CMS\Core\Type\Enumeration {
+       const FOO = 1;
+       const BAR = 1;
+}
\ No newline at end of file
diff --git a/typo3/sysext/core/Tests/Unit/Type/Fixture/Enumeration/InvalidConstantEnumeration.php b/typo3/sysext/core/Tests/Unit/Type/Fixture/Enumeration/InvalidConstantEnumeration.php
new file mode 100644 (file)
index 0000000..5c3bc27
--- /dev/null
@@ -0,0 +1,32 @@
+<?php
+namespace TYPO3\CMS\Core\Tests\Unit\Type\Fixture\Enumeration;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2013 Sascha Egerer <sascha.egerer@dkd.de>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * This is an invalid enumeration because an unsupported constant value is used
+ */
+class InvalidConstantEnumeration extends \TYPO3\CMS\Core\Type\Enumeration {
+       const FOO = 1.11;
+}
\ No newline at end of file
diff --git a/typo3/sysext/core/Tests/Unit/Type/Fixture/Enumeration/MissingConstantsEnumeration.php b/typo3/sysext/core/Tests/Unit/Type/Fixture/Enumeration/MissingConstantsEnumeration.php
new file mode 100644 (file)
index 0000000..abec2fe
--- /dev/null
@@ -0,0 +1,32 @@
+<?php
+namespace TYPO3\CMS\Core\Tests\Unit\Type\Fixture\Enumeration;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2013 Sascha Egerer <sascha.egerer@dkd.de>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * This is an invalid enumeration because no constants are defined
+ */
+class MissingConstantsEnumeration extends \TYPO3\CMS\Core\Type\Enumeration {
+
+}
\ No newline at end of file
diff --git a/typo3/sysext/core/Tests/Unit/Type/Fixture/Enumeration/MissingDefaultEnumeration.php b/typo3/sysext/core/Tests/Unit/Type/Fixture/Enumeration/MissingDefaultEnumeration.php
new file mode 100644 (file)
index 0000000..963e22f
--- /dev/null
@@ -0,0 +1,32 @@
+<?php
+namespace TYPO3\CMS\Core\Tests\Unit\Type\Fixture\Enumeration;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2013 Sascha Egerer <sascha.egerer@dkd.de>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * This is an enumeration without a default value so it must be called with a value
+ */
+class MissingDefaultEnumeration extends \TYPO3\CMS\Core\Type\Enumeration {
+       const FOO = 1;
+}
\ No newline at end of file