[BUGFIX] LogLevelTest dataProvider not used
authorChristian Kuhn <lolli@schwarzbu.ch>
Sun, 2 Sep 2012 21:12:02 +0000 (23:12 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sun, 2 Sep 2012 21:30:21 +0000 (23:30 +0200)
isValidLevelThrowsExceptionOnInvalidLevelIfAskedToDoSo() test throwed a
warning that required input parameter $inputValue was not used. This was
because of a typo @dataprovider -> @dataProvider, so the data provider
was not used at all. Fixing this, one of the tests with the
object \stdClass failed.
This turned out to be an error in the thrown exception in validateLevel
 because the exception is not thrown, if the exception message is
compiled from a string and an object. Therefore, the parameter $level
is now left out in method validateLevel().
As additional cleanup, the MathUtilityTest is moved from t3lib to core
extension, and the rootline test and fixture names are adapted.

Change-Id: If5ec0505abc224ad59cd5dc6cb4b679fc4bc46ba
Fixes: #40540
Releases: 6.0
Reviewed-on: http://review.typo3.org/14295
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
tests/Unit/t3lib/utility/class.t3lib_utility_mathTest.php [deleted file]
tests/Unit/t3lib/utility/fixture/t3lib_utility_math_fixture_classWithStringRepresentation.php [deleted file]
typo3/sysext/core/Classes/Log/LogLevel.php
typo3/sysext/core/Tests/Unit/Log/LogLevelTest.php
typo3/sysext/core/Tests/Unit/Utility/Fixtures/AccessibleRootline.php [deleted file]
typo3/sysext/core/Tests/Unit/Utility/Fixtures/MathUtilityTestClassWithStringRepresentationFixture.php [new file with mode: 0644]
typo3/sysext/core/Tests/Unit/Utility/Fixtures/RootlineUtilityTestAccessibleFixture.php [new file with mode: 0644]
typo3/sysext/core/Tests/Unit/Utility/MathUtilityTest.php [new file with mode: 0644]
typo3/sysext/core/Tests/Unit/Utility/RootlineUtilityTest.php

diff --git a/tests/Unit/t3lib/utility/class.t3lib_utility_mathTest.php b/tests/Unit/t3lib/utility/class.t3lib_utility_mathTest.php
deleted file mode 100644 (file)
index acbbed1..0000000
+++ /dev/null
@@ -1,275 +0,0 @@
-<?php
-/***************************************************************
- *  Copyright notice
- *
- *  (c) 2011 Susanne Moog <typo3@susanne-moog.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!
- ***************************************************************/
-require_once 'fixture/t3lib_utility_math_fixture_classWithStringRepresentation.php';
-/**
- * Testcase for class t3lib_utility_Math
- *
- * @author Susanne Moog <typo3@susanne-moog.de>
- * @package TYPO3
- * @subpackage t3lib
- */
-class t3lib_utility_MathTest extends tx_phpunit_testcase {
-
-       //////////////////////////////////
-       // Tests concerning forceIntegerInRange
-       //////////////////////////////////
-       /**
-        * Data provider for forceIntegerInRangeForcesIntegerIntoBoundaries
-        *
-        * @return array expected values, arithmetic expression
-        */
-       public function forceIntegerInRangeForcesIntegerIntoDefaultBoundariesDataProvider() {
-               return array(
-                       'negativeValue' => array(0, -10),
-                       'normalValue' => array(30, 30),
-                       'veryHighValue' => array(2000000000, PHP_INT_MAX),
-                       'zeroValue' => array(0, 0),
-                       'anotherNormalValue' => array(12309, 12309)
-               );
-       }
-
-       /**
-        * @test
-        * @dataProvider forceIntegerInRangeForcesIntegerIntoDefaultBoundariesDataProvider
-        */
-       public function forceIntegerInRangeForcesIntegerIntoDefaultBoundaries($expected, $value) {
-               $this->assertEquals($expected, \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($value, 0));
-       }
-
-       /**
-        * @test
-        */
-       public function forceIntegerInRangeSetsDefaultValueIfZeroValueIsGiven() {
-               $this->assertEquals(42, \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange('', 0, 2000000000, 42));
-       }
-
-       //////////////////////////////////
-       // Tests concerning convertToPositiveInteger
-       //////////////////////////////////
-       /**
-        * @test
-        */
-       public function convertToPositiveIntegerReturnsZeroForNegativeValues() {
-               $this->assertEquals(0, \TYPO3\CMS\Core\Utility\MathUtility::convertToPositiveInteger(-123));
-       }
-
-       /**
-        * @test
-        */
-       public function convertToPositiveIntegerReturnsTheInputValueForPositiveValues() {
-               $this->assertEquals(123, \TYPO3\CMS\Core\Utility\MathUtility::convertToPositiveInteger(123));
-       }
-
-       ///////////////////////////////
-       // Tests concerning testInt
-       ///////////////////////////////
-       /**
-        * Data provider for canBeInterpretedAsIntegerReturnsTrue
-        *
-        * @return array Data sets
-        */
-       public function functionCanBeInterpretedAsIntegerValidDataProvider() {
-               return array(
-                       'int' => array(32425),
-                       'negative int' => array(-32425),
-                       'largest int' => array(PHP_INT_MAX),
-                       'int as string' => array('32425'),
-                       'negative int as string' => array('-32425'),
-                       'zero' => array(0),
-                       'zero as string' => array('0')
-               );
-       }
-
-       /**
-        * @test
-        * @dataProvider functionCanBeInterpretedAsIntegerValidDataProvider
-        */
-       public function testIntReturnsTrue($int) {
-               $this->assertTrue(\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($int));
-       }
-
-       /**
-        * Data provider for testIntReturnsFalse
-        *
-        * @return array Data sets
-        */
-       public function functionCanBeInterpretedAsIntegerInvalidDataProvider() {
-               $objectWithNumericalStringRepresentation = new t3lib_utility_math_fixture_classWithStringRepresentation();
-               $objectWithNumericalStringRepresentation->setString('1234');
-               $objectWithNonNumericalStringRepresentation = new t3lib_utility_math_fixture_classWithStringRepresentation();
-               $objectWithNonNumericalStringRepresentation->setString('foo');
-               $objectWithEmptyStringRepresentation = new t3lib_utility_math_fixture_classWithStringRepresentation();
-               $objectWithEmptyStringRepresentation->setString('');
-               return array(
-                       'int as string with leading zero' => array('01234'),
-                       'positive int as string with plus modifier' => array('+1234'),
-                       'negative int as string with leading zero' => array('-01234'),
-                       'largest int plus one' => array(PHP_INT_MAX + 1),
-                       'string' => array('testInt'),
-                       'empty string' => array(''),
-                       'int in string' => array('5 times of testInt'),
-                       'int as string with space after' => array('5 '),
-                       'int as string with space before' => array(' 5'),
-                       'int as string with many spaces before' => array('     5'),
-                       'float' => array(3.14159),
-                       'float as string' => array('3.14159'),
-                       'float as string only a dot' => array('10.'),
-                       'float as string trailing zero would evaluate to int 10' => array('10.0'),
-                       'float as string trailing zeros  would evaluate to int 10' => array('10.00'),
-                       'null' => array(NULL),
-                       'empty array' => array(array()),
-                       'int in array' => array(array(32425)),
-                       'int as string in array' => array(array('32425')),
-                       'object without string representation' => array(new stdClass()),
-                       'object with numerical string representation' => array($objectWithNumericalStringRepresentation),
-                       'object without numerical string representation' => array($objectWithNonNumericalStringRepresentation),
-                       'object with empty string representation' => array($objectWithEmptyStringRepresentation)
-               );
-       }
-
-       /**
-        * @test
-        * @dataProvider functionCanBeInterpretedAsIntegerInvalidDataProvider
-        */
-       public function canBeInterpretedAsIntegerReturnsFalse($int) {
-               $this->assertFalse(\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($int));
-       }
-
-       //////////////////////////////////
-       // Tests concerning calculateWithPriorityToAdditionAndSubtraction
-       //////////////////////////////////
-       /**
-        * Data provider for calculateWithPriorityToAdditionAndSubtraction
-        *
-        * @return array expected values, arithmetic expression
-        */
-       public function calculateWithPriorityToAdditionAndSubtractionDataProvider() {
-               return array(
-                       'add' => array(9, '6 + 3'),
-                       'substract with positive result' => array(3, '6 - 3'),
-                       'substract with negative result' => array(-3, '3 - 6'),
-                       'multiply' => array(6, '2 * 3'),
-                       'divide' => array(2.5, '5 / 2'),
-                       'modulus' => array(1, '5 % 2'),
-                       'power' => array(8, '2 ^ 3'),
-                       'three operands with non integer result' => array(6.5, '5 + 3 / 2'),
-                       'three operands with power' => array(14, '5 + 3 ^ 2'),
-                       'three operads with modulus' => array(4, '5 % 2 + 3'),
-                       'four operands' => array(3, '2 + 6 / 2 - 2'),
-                       'division by zero when dividing' => array('ERROR: dividing by zero', '2 / 0'),
-                       'division by zero with modulus' => array('ERROR: dividing by zero', '2 % 0')
-               );
-       }
-
-       /**
-        * @test
-        * @dataProvider calculateWithPriorityToAdditionAndSubtractionDataProvider
-        */
-       public function calculateWithPriorityToAdditionAndSubtractionCorrectlyCalculatesExpression($expected, $expression) {
-               $this->assertEquals($expected, \TYPO3\CMS\Core\Utility\MathUtility::calculateWithPriorityToAdditionAndSubtraction($expression));
-       }
-
-       //////////////////////////////////
-       // Tests concerning calcParenthesis
-       //////////////////////////////////
-       /**
-        * Data provider for calcParenthesis
-        *
-        * @return array expected values, arithmetic expression
-        */
-       public function calculateWithParenthesesDataProvider() {
-               return array(
-                       'starts with parenthesis' => array(18, '(6 + 3) * 2'),
-                       'ends with parenthesis' => array(6, '2 * (6 - 3)'),
-                       'multiple parentheses' => array(-6, '(3 - 6) * (4 - 2)'),
-                       'nested parentheses' => array(22, '2 * (3 + 2 + (3 * 2))'),
-                       'parenthesis with division' => array(15, '5 / 2 * (3 * 2)')
-               );
-       }
-
-       /**
-        * @test
-        * @dataProvider calculateWithParenthesesDataProvider
-        */
-       public function calculateWithParenthesesCorrectlyCalculatesExpression($expected, $expression) {
-               $this->assertEquals($expected, \TYPO3\CMS\Core\Utility\MathUtility::calculateWithParentheses($expression));
-       }
-
-       //////////////////////////////////
-       // Tests concerning isIntegerInRange
-       //////////////////////////////////
-       /**
-        * @test
-        */
-       public function isIntegerInRangeIncludesLowerBoundary() {
-               $this->assertTrue(\TYPO3\CMS\Core\Utility\MathUtility::isIntegerInRange(1, 1, 2));
-       }
-
-       /**
-        * @test
-        */
-       public function isIntegerInRangeIncludesUpperBoundary() {
-               $this->assertTrue(\TYPO3\CMS\Core\Utility\MathUtility::isIntegerInRange(2, 1, 2));
-       }
-
-       /**
-        * @test
-        */
-       public function isIntegerInRangeAcceptsValueInRange() {
-               $this->assertTrue(\TYPO3\CMS\Core\Utility\MathUtility::isIntegerInRange(10, 1, 100));
-       }
-
-       /**
-        * @test
-        */
-       public function isIntegerInRangeRejectsValueOutsideOfRange() {
-               $this->assertFalse(\TYPO3\CMS\Core\Utility\MathUtility::isIntegerInRange(10, 1, 2));
-       }
-
-       /**
-        * Data provider or isIntegerInRangeRejectsOtherDataTypes
-        */
-       public function isIntegerInRangeRejectsOtherDataTypesDataProvider() {
-               return array(
-                       'negative integer' => array(-1),
-                       'float' => array(1.5),
-                       'string' => array('string'),
-                       'array' => array(array()),
-                       'object' => array(new stdClass()),
-                       'boolean FALSE' => array(FALSE),
-                       'NULL' => array(NULL)
-               );
-       }
-
-       /**
-        * @test
-        * @dataProvider isIntegerInRangeRejectsOtherDataTypesDataProvider
-        */
-       public function isIntegerInRangeRejectsOtherDataTypes($inputValue) {
-               $this->assertFalse(\TYPO3\CMS\Core\Utility\MathUtility::isIntegerInRange($invalidValue, 0, 10));
-       }
-
-}
-
-?>
\ No newline at end of file
diff --git a/tests/Unit/t3lib/utility/fixture/t3lib_utility_math_fixture_classWithStringRepresentation.php b/tests/Unit/t3lib/utility/fixture/t3lib_utility_math_fixture_classWithStringRepresentation.php
deleted file mode 100644 (file)
index e1feccb..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-<?php
-/***************************************************************
- *  Copyright notice
- *
- *  (c) 2012 Philipp Gampe (forge.typo3.org@philippgampe.info)
- *  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!
- ***************************************************************/
-/**
- * Class t3lib_utility_math_fixture_classWithStringRepresentation.
- *
- * This is a fixture subclass for t3lib_utility_math
- *
- * @package TYPO3
- * @subpackage t3lib
- */
-class t3lib_utility_math_fixture_classWithStringRepresentation {
-
-       protected $string = '';
-
-       public function __toString() {
-               return $this->getString();
-       }
-
-       public function setString($string) {
-               $this->string = $string;
-       }
-
-       public function getString() {
-               return $this->string;
-       }
-
-}
-
-?>
\ No newline at end of file
index d947533..7d26c88 100644 (file)
@@ -141,11 +141,11 @@ class LogLevel {
         *
         * @param integer $level log level to validate
         * @return void
-        * @throws RangeException if the given log level is invalid
+        * @throws \RangeException if the given log level is invalid
         */
        static public function validateLevel($level) {
                if (!self::isValidLevel($level)) {
-                       throw new \RangeException(('Invalid Log Level "' . $level) . '".', 1321637121);
+                       throw new \RangeException('Invalid Log Level.', 1321637121);
                }
        }
 
index 8ec5a85..da31246 100644 (file)
@@ -63,7 +63,7 @@ class LevelTest extends \tx_phpunit_testcase {
                        'float' => array(1.5),
                        'string' => array('string'),
                        'array' => array(array()),
-                       'object' => array(new stdClass()),
+                       'object' => array(new \stdClass()),
                        'boolean FALSE' => array(FALSE),
                        'NULL' => array(NULL)
                );
@@ -71,10 +71,10 @@ class LevelTest extends \tx_phpunit_testcase {
 
        /**
         * @test
-        * @dataprovider isValidLevelThrowsExceptionOnInvalidLevelIfAskedToDoSoDataProvider
+        * @dataProvider isValidLevelThrowsExceptionOnInvalidLevelIfAskedToDoSoDataProvider
+        * @expectedException \RangeException
         */
        public function isValidLevelThrowsExceptionOnInvalidLevelIfAskedToDoSo($inputValue) {
-               $this->setExpectedException('RangeException');
                \TYPO3\CMS\Core\Log\LogLevel::validateLevel($inputValue);
        }
 
diff --git a/typo3/sysext/core/Tests/Unit/Utility/Fixtures/AccessibleRootline.php b/typo3/sysext/core/Tests/Unit/Utility/Fixtures/AccessibleRootline.php
deleted file mode 100644 (file)
index c2cf0f4..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-<?php
-namespace TYPO3\CMS\Core\Tests\Unit\Utility\Fixtures;
-
-/***************************************************************
- *  Copyright notice
- *
- *  (c) 2012 Steffen Ritter <steffen.ritter@typo3.org>
- *  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!
- ***************************************************************/
-
-/**
- * Make method public
- *
- * @author Steffen Ritter <steffen.ritter@typo3.org>
- * @package TYPO3
- * @subpackage test
- */
-class AccessibleRootlineUtility extends \TYPO3\CMS\Core\Utility\RootlineUtility {
-
-       public function processMountedPage($mountedPageData, $mountPointPageData) {
-               return parent::processMountedPage($mountedPageData, $mountPointPageData);
-       }
-
-       public function columnHasRelationToResolve($configuration) {
-               return parent::columnHasRelationToResolve($configuration);
-       }
-
-}
-
-?>
\ No newline at end of file
diff --git a/typo3/sysext/core/Tests/Unit/Utility/Fixtures/MathUtilityTestClassWithStringRepresentationFixture.php b/typo3/sysext/core/Tests/Unit/Utility/Fixtures/MathUtilityTestClassWithStringRepresentationFixture.php
new file mode 100644 (file)
index 0000000..2e70dc8
--- /dev/null
@@ -0,0 +1,56 @@
+<?php
+namespace TYPO3\CMS\Core\Tests\Unit\Utility\Fixtures;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2012 Philipp Gampe (forge.typo3.org@philippgampe.info)
+ *  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!
+ ***************************************************************/
+
+/**
+ * Class t3lib_utility_math_fixture_classWithStringRepresentation.
+ *
+ * This is a fixture subclass for t3lib_utility_math
+ *
+ * @package TYPO3
+ * @subpackage t3lib
+ */
+class MathUtilityTestClassWithStringRepresentationFixture {
+
+       protected $string = '';
+
+       public function __toString() {
+               return $this->getString();
+       }
+
+       public function setString($string) {
+               $this->string = $string;
+       }
+
+       public function getString() {
+               return $this->string;
+       }
+
+}
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/core/Tests/Unit/Utility/Fixtures/RootlineUtilityTestAccessibleFixture.php b/typo3/sysext/core/Tests/Unit/Utility/Fixtures/RootlineUtilityTestAccessibleFixture.php
new file mode 100644 (file)
index 0000000..cfc7cf2
--- /dev/null
@@ -0,0 +1,46 @@
+<?php
+namespace TYPO3\CMS\Core\Tests\Unit\Utility\Fixtures;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2012 Steffen Ritter <steffen.ritter@typo3.org>
+ *  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!
+ ***************************************************************/
+
+/**
+ * Make method public
+ *
+ * @author Steffen Ritter <steffen.ritter@typo3.org>
+ * @package TYPO3
+ * @subpackage test
+ */
+class RootlineUtilityTestAccessibleFixture extends \TYPO3\CMS\Core\Utility\RootlineUtility {
+
+       public function processMountedPage($mountedPageData, $mountPointPageData) {
+               return parent::processMountedPage($mountedPageData, $mountPointPageData);
+       }
+
+       public function columnHasRelationToResolve($configuration) {
+               return parent::columnHasRelationToResolve($configuration);
+       }
+
+}
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/core/Tests/Unit/Utility/MathUtilityTest.php b/typo3/sysext/core/Tests/Unit/Utility/MathUtilityTest.php
new file mode 100644 (file)
index 0000000..9ed25bb
--- /dev/null
@@ -0,0 +1,279 @@
+<?php
+namespace TYPO3\CMS\Core\Tests\Unit\Utility;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2011 Susanne Moog <typo3@susanne-moog.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!
+ ***************************************************************/
+
+require_once 'Fixtures/MathUtilityTestClassWithStringRepresentationFixture.php';
+
+/**
+ * Testcase for class t3lib_utility_Math
+ *
+ * @author Susanne Moog <typo3@susanne-moog.de>
+ * @package TYPO3
+ * @subpackage t3lib
+ */
+class t3lib_utility_MathTest extends \tx_phpunit_testcase {
+
+       //////////////////////////////////
+       // Tests concerning forceIntegerInRange
+       //////////////////////////////////
+       /**
+        * Data provider for forceIntegerInRangeForcesIntegerIntoBoundaries
+        *
+        * @return array expected values, arithmetic expression
+        */
+       public function forceIntegerInRangeForcesIntegerIntoDefaultBoundariesDataProvider() {
+               return array(
+                       'negativeValue' => array(0, -10),
+                       'normalValue' => array(30, 30),
+                       'veryHighValue' => array(2000000000, PHP_INT_MAX),
+                       'zeroValue' => array(0, 0),
+                       'anotherNormalValue' => array(12309, 12309)
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider forceIntegerInRangeForcesIntegerIntoDefaultBoundariesDataProvider
+        */
+       public function forceIntegerInRangeForcesIntegerIntoDefaultBoundaries($expected, $value) {
+               $this->assertEquals($expected, \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($value, 0));
+       }
+
+       /**
+        * @test
+        */
+       public function forceIntegerInRangeSetsDefaultValueIfZeroValueIsGiven() {
+               $this->assertEquals(42, \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange('', 0, 2000000000, 42));
+       }
+
+       //////////////////////////////////
+       // Tests concerning convertToPositiveInteger
+       //////////////////////////////////
+       /**
+        * @test
+        */
+       public function convertToPositiveIntegerReturnsZeroForNegativeValues() {
+               $this->assertEquals(0, \TYPO3\CMS\Core\Utility\MathUtility::convertToPositiveInteger(-123));
+       }
+
+       /**
+        * @test
+        */
+       public function convertToPositiveIntegerReturnsTheInputValueForPositiveValues() {
+               $this->assertEquals(123, \TYPO3\CMS\Core\Utility\MathUtility::convertToPositiveInteger(123));
+       }
+
+       ///////////////////////////////
+       // Tests concerning testInt
+       ///////////////////////////////
+       /**
+        * Data provider for canBeInterpretedAsIntegerReturnsTrue
+        *
+        * @return array Data sets
+        */
+       public function functionCanBeInterpretedAsIntegerValidDataProvider() {
+               return array(
+                       'int' => array(32425),
+                       'negative int' => array(-32425),
+                       'largest int' => array(PHP_INT_MAX),
+                       'int as string' => array('32425'),
+                       'negative int as string' => array('-32425'),
+                       'zero' => array(0),
+                       'zero as string' => array('0')
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider functionCanBeInterpretedAsIntegerValidDataProvider
+        */
+       public function testIntReturnsTrue($int) {
+               $this->assertTrue(\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($int));
+       }
+
+       /**
+        * Data provider for testIntReturnsFalse
+        *
+        * @return array Data sets
+        */
+       public function functionCanBeInterpretedAsIntegerInvalidDataProvider() {
+               $objectWithNumericalStringRepresentation = new \TYPO3\CMS\Core\Tests\Unit\Utility\Fixtures\MathUtilityTestClassWithStringRepresentationFixture();
+               $objectWithNumericalStringRepresentation->setString('1234');
+               $objectWithNonNumericalStringRepresentation = new \TYPO3\CMS\Core\Tests\Unit\Utility\Fixtures\MathUtilityTestClassWithStringRepresentationFixture();
+               $objectWithNonNumericalStringRepresentation->setString('foo');
+               $objectWithEmptyStringRepresentation = new \TYPO3\CMS\Core\Tests\Unit\Utility\Fixtures\MathUtilityTestClassWithStringRepresentationFixture();
+               $objectWithEmptyStringRepresentation->setString('');
+               return array(
+                       'int as string with leading zero' => array('01234'),
+                       'positive int as string with plus modifier' => array('+1234'),
+                       'negative int as string with leading zero' => array('-01234'),
+                       'largest int plus one' => array(PHP_INT_MAX + 1),
+                       'string' => array('testInt'),
+                       'empty string' => array(''),
+                       'int in string' => array('5 times of testInt'),
+                       'int as string with space after' => array('5 '),
+                       'int as string with space before' => array(' 5'),
+                       'int as string with many spaces before' => array('     5'),
+                       'float' => array(3.14159),
+                       'float as string' => array('3.14159'),
+                       'float as string only a dot' => array('10.'),
+                       'float as string trailing zero would evaluate to int 10' => array('10.0'),
+                       'float as string trailing zeros  would evaluate to int 10' => array('10.00'),
+                       'null' => array(NULL),
+                       'empty array' => array(array()),
+                       'int in array' => array(array(32425)),
+                       'int as string in array' => array(array('32425')),
+                       'object without string representation' => array(new \stdClass()),
+                       'object with numerical string representation' => array($objectWithNumericalStringRepresentation),
+                       'object without numerical string representation' => array($objectWithNonNumericalStringRepresentation),
+                       'object with empty string representation' => array($objectWithEmptyStringRepresentation)
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider functionCanBeInterpretedAsIntegerInvalidDataProvider
+        */
+       public function canBeInterpretedAsIntegerReturnsFalse($int) {
+               $this->assertFalse(\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($int));
+       }
+
+       //////////////////////////////////
+       // Tests concerning calculateWithPriorityToAdditionAndSubtraction
+       //////////////////////////////////
+       /**
+        * Data provider for calculateWithPriorityToAdditionAndSubtraction
+        *
+        * @return array expected values, arithmetic expression
+        */
+       public function calculateWithPriorityToAdditionAndSubtractionDataProvider() {
+               return array(
+                       'add' => array(9, '6 + 3'),
+                       'substract with positive result' => array(3, '6 - 3'),
+                       'substract with negative result' => array(-3, '3 - 6'),
+                       'multiply' => array(6, '2 * 3'),
+                       'divide' => array(2.5, '5 / 2'),
+                       'modulus' => array(1, '5 % 2'),
+                       'power' => array(8, '2 ^ 3'),
+                       'three operands with non integer result' => array(6.5, '5 + 3 / 2'),
+                       'three operands with power' => array(14, '5 + 3 ^ 2'),
+                       'three operads with modulus' => array(4, '5 % 2 + 3'),
+                       'four operands' => array(3, '2 + 6 / 2 - 2'),
+                       'division by zero when dividing' => array('ERROR: dividing by zero', '2 / 0'),
+                       'division by zero with modulus' => array('ERROR: dividing by zero', '2 % 0')
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider calculateWithPriorityToAdditionAndSubtractionDataProvider
+        */
+       public function calculateWithPriorityToAdditionAndSubtractionCorrectlyCalculatesExpression($expected, $expression) {
+               $this->assertEquals($expected, \TYPO3\CMS\Core\Utility\MathUtility::calculateWithPriorityToAdditionAndSubtraction($expression));
+       }
+
+       //////////////////////////////////
+       // Tests concerning calcParenthesis
+       //////////////////////////////////
+       /**
+        * Data provider for calcParenthesis
+        *
+        * @return array expected values, arithmetic expression
+        */
+       public function calculateWithParenthesesDataProvider() {
+               return array(
+                       'starts with parenthesis' => array(18, '(6 + 3) * 2'),
+                       'ends with parenthesis' => array(6, '2 * (6 - 3)'),
+                       'multiple parentheses' => array(-6, '(3 - 6) * (4 - 2)'),
+                       'nested parentheses' => array(22, '2 * (3 + 2 + (3 * 2))'),
+                       'parenthesis with division' => array(15, '5 / 2 * (3 * 2)')
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider calculateWithParenthesesDataProvider
+        */
+       public function calculateWithParenthesesCorrectlyCalculatesExpression($expected, $expression) {
+               $this->assertEquals($expected, \TYPO3\CMS\Core\Utility\MathUtility::calculateWithParentheses($expression));
+       }
+
+       //////////////////////////////////
+       // Tests concerning isIntegerInRange
+       //////////////////////////////////
+       /**
+        * @test
+        */
+       public function isIntegerInRangeIncludesLowerBoundary() {
+               $this->assertTrue(\TYPO3\CMS\Core\Utility\MathUtility::isIntegerInRange(1, 1, 2));
+       }
+
+       /**
+        * @test
+        */
+       public function isIntegerInRangeIncludesUpperBoundary() {
+               $this->assertTrue(\TYPO3\CMS\Core\Utility\MathUtility::isIntegerInRange(2, 1, 2));
+       }
+
+       /**
+        * @test
+        */
+       public function isIntegerInRangeAcceptsValueInRange() {
+               $this->assertTrue(\TYPO3\CMS\Core\Utility\MathUtility::isIntegerInRange(10, 1, 100));
+       }
+
+       /**
+        * @test
+        */
+       public function isIntegerInRangeRejectsValueOutsideOfRange() {
+               $this->assertFalse(\TYPO3\CMS\Core\Utility\MathUtility::isIntegerInRange(10, 1, 2));
+       }
+
+       /**
+        * Data provider or isIntegerInRangeRejectsOtherDataTypes
+        */
+       public function isIntegerInRangeRejectsOtherDataTypesDataProvider() {
+               return array(
+                       'negative integer' => array(-1),
+                       'float' => array(1.5),
+                       'string' => array('string'),
+                       'array' => array(array()),
+                       'object' => array(new \stdClass()),
+                       'boolean FALSE' => array(FALSE),
+                       'NULL' => array(NULL)
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider isIntegerInRangeRejectsOtherDataTypesDataProvider
+        */
+       public function isIntegerInRangeRejectsOtherDataTypes($inputValue) {
+               $this->assertFalse(\TYPO3\CMS\Core\Utility\MathUtility::isIntegerInRange($inputValue, 0, 10));
+       }
+
+}
+
+?>
\ No newline at end of file
index 0a0f45e..11483ba 100644 (file)
@@ -24,7 +24,7 @@ namespace TYPO3\CMS\Core\Tests\Unit\Utility;
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
 
-require_once __DIR__ . '/Fixtures/AccessibleRootline.php';
+require_once __DIR__ . '/Fixtures/RootlineUtilityTestAccessibleFixture.php';
 
 /**
  * Testcase for class \TYPO3\CMS\Core\Utility\RootlineUtility
@@ -61,7 +61,7 @@ class RootlineUtilityTest extends \tx_phpunit_testcase {
         * @test
         */
        public function isMountedPageWithoutMountPointsReturnsFalse() {
-               $fixture = new Fixtures\AccessibleRootlineUtility(1);
+               $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1);
                $this->assertFalse($fixture->isMountedPage());
        }
 
@@ -69,7 +69,7 @@ class RootlineUtilityTest extends \tx_phpunit_testcase {
         * @test
         */
        public function isMountedPageWithMatchingMountPointParameterReturnsTrue() {
-               $fixture = new Fixtures\AccessibleRootlineUtility(1, '1-99');
+               $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1, '1-99');
                $this->assertTrue($fixture->isMountedPage());
        }
 
@@ -77,7 +77,7 @@ class RootlineUtilityTest extends \tx_phpunit_testcase {
         * @test
         */
        public function isMountedPageWithNonMatchingMountPointParameterReturnsFalse() {
-               $fixture = new Fixtures\AccessibleRootlineUtility(1, '99-99');
+               $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1, '99-99');
                $this->assertFalse($fixture->isMountedPage());
        }
 
@@ -86,7 +86,7 @@ class RootlineUtilityTest extends \tx_phpunit_testcase {
         * @expectedException RuntimeException
         */
        public function processMountedPageWithNonMountedPageThrowsException() {
-               $fixture = new Fixtures\AccessibleRootlineUtility(1, '1-99');
+               $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1, '1-99');
                $fixture->processMountedPage(array('uid' => 1), array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_DEFAULT));
        }
 
@@ -94,7 +94,7 @@ class RootlineUtilityTest extends \tx_phpunit_testcase {
         * @test
         */
        public function processMountedPageWithMountedPageNotThrowsException() {
-               $fixture = new Fixtures\AccessibleRootlineUtility(1, '1-99');
+               $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1, '1-99');
                $fixture->processMountedPage(array('uid' => 1), array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1));
        }
 
@@ -102,7 +102,7 @@ class RootlineUtilityTest extends \tx_phpunit_testcase {
         * @test
         */
        public function processMountedPageWithMountedPageAddsMountedFromParameter() {
-               $fixture = new Fixtures\AccessibleRootlineUtility(1, '1-99');
+               $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1, '1-99');
                $result = $fixture->processMountedPage(array('uid' => 1), array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1));
                $this->assertTrue(isset($result['_MOUNTED_FROM']));
                $this->assertSame(1, $result['_MOUNTED_FROM']);
@@ -112,7 +112,7 @@ class RootlineUtilityTest extends \tx_phpunit_testcase {
         * @test
         */
        public function processMountedPageWithMountedPageAddsMountPointParameterToReturnValue() {
-               $fixture = new Fixtures\AccessibleRootlineUtility(1, '1-99');
+               $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1, '1-99');
                $result = $fixture->processMountedPage(array('uid' => 1), array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1));
                $this->assertTrue(isset($result['_MP_PARAM']));
                $this->assertSame('1-99', $result['_MP_PARAM']);
@@ -122,7 +122,7 @@ class RootlineUtilityTest extends \tx_phpunit_testcase {
         * @test
         */
        public function processMountedPageForMountPageIsOverlayAddsMountOLParameter() {
-               $fixture = new Fixtures\AccessibleRootlineUtility(1, '1-99');
+               $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1, '1-99');
                $result = $fixture->processMountedPage(array('uid' => 1), array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1, 'mount_pid_ol' => 1));
                $this->assertTrue(isset($result['_MOUNT_OL']));
                $this->assertSame(TRUE, $result['_MOUNT_OL']);
@@ -132,7 +132,7 @@ class RootlineUtilityTest extends \tx_phpunit_testcase {
         * @test
         */
        public function processMountedPageForMountPageIsOverlayAddsDataInformationAboutMountPage() {
-               $fixture = new Fixtures\AccessibleRootlineUtility(1, '1-99');
+               $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1, '1-99');
                $result = $fixture->processMountedPage(array('uid' => 1), array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1, 'mount_pid_ol' => 1, 'pid' => 5, 'title' => 'TestCase'));
                $this->assertTrue(isset($result['_MOUNT_PAGE']));
                $this->assertSame(array('uid' => 99, 'pid' => 5, 'title' => 'TestCase'), $result['_MOUNT_PAGE']);
@@ -143,7 +143,7 @@ class RootlineUtilityTest extends \tx_phpunit_testcase {
         */
        public function processMountedPageForMountPageWithoutOverlayReplacesMountedPageWithMountPage() {
                $a = array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1, 'mount_pid_ol' => 0);
-               $fixture = new Fixtures\AccessibleRootlineUtility(1, '1-99');
+               $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1, '1-99');
                $result = $fixture->processMountedPage(array('uid' => 1), $a);
                $this->assertIsSubset($a, $result);
        }
@@ -152,7 +152,7 @@ class RootlineUtilityTest extends \tx_phpunit_testcase {
         * @test
         */
        public function columnHasRelationToResolveDetectsGroupFieldAsLocal() {
-               $fixture = new Fixtures\AccessibleRootlineUtility(1);
+               $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1);
                $this->assertFalse($fixture->columnHasRelationToResolve(array(
                        'type' => 'group'
                )));
@@ -162,7 +162,7 @@ class RootlineUtilityTest extends \tx_phpunit_testcase {
         * @test
         */
        public function columnHasRelationToResolveDetectsGroupFieldWithMMAsRemote() {
-               $fixture = new Fixtures\AccessibleRootlineUtility(1);
+               $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1);
                $this->assertTrue($fixture->columnHasRelationToResolve(array(
                        'config' => array(
                                'type' => 'group',
@@ -175,7 +175,7 @@ class RootlineUtilityTest extends \tx_phpunit_testcase {
         * @test
         */
        public function columnHasRelationToResolveDetectsInlineFieldAsLocal() {
-               $fixture = new Fixtures\AccessibleRootlineUtility(1);
+               $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1);
                $this->assertFalse($fixture->columnHasRelationToResolve(array(
                        'config' => array(
                                'type' => 'inline'
@@ -187,7 +187,7 @@ class RootlineUtilityTest extends \tx_phpunit_testcase {
         * @test
         */
        public function columnHasRelationToResolveDetectsInlineFieldWithForeignKeyAsRemote() {
-               $fixture = new Fixtures\AccessibleRootlineUtility(1);
+               $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1);
                $this->assertTrue($fixture->columnHasRelationToResolve(array(
                        'config' => array(
                                'type' => 'inline',
@@ -200,7 +200,7 @@ class RootlineUtilityTest extends \tx_phpunit_testcase {
         * @test
         */
        public function columnHasRelationToResolveDetectsInlineFieldWithFMMAsRemote() {
-               $fixture = new Fixtures\AccessibleRootlineUtility(1);
+               $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1);
                $this->assertTrue($fixture->columnHasRelationToResolve(array(
                        'config' => array(
                                'type' => 'inline',
@@ -213,7 +213,7 @@ class RootlineUtilityTest extends \tx_phpunit_testcase {
         * @test
         */
        public function columnHasRelationToResolveDetectsSelectFieldAsLocal() {
-               $fixture = new Fixtures\AccessibleRootlineUtility(1);
+               $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1);
                $this->assertFalse($fixture->columnHasRelationToResolve(array(
                        'config' => array(
                                'type' => 'select'
@@ -225,7 +225,7 @@ class RootlineUtilityTest extends \tx_phpunit_testcase {
         * @test
         */
        public function columnHasRelationToResolveDetectsSelectFieldWithMMAsRemote() {
-               $fixture = new Fixtures\AccessibleRootlineUtility(1);
+               $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1);
                $this->assertTrue($fixture->columnHasRelationToResolve(array(
                        'config' => array(
                                'type' => 'select',
@@ -242,13 +242,13 @@ class RootlineUtilityTest extends \tx_phpunit_testcase {
                $pageContext->sys_language_uid = 8;
                $pageContext->versioningWorkspaceId = 15;
                $pageContext->versioningPreview = TRUE;
-               $fixture = new Fixtures\AccessibleRootlineUtility(42, '47-11', $pageContext);
+               $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(42, '47-11', $pageContext);
                $this->assertSame('42_47-11_8_15_1', $fixture->getCacheIdentifier());
                $pageContext->versioningPreview = FALSE;
-               $fixture = new Fixtures\AccessibleRootlineUtility(42, '47-11', $pageContext);
+               $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(42, '47-11', $pageContext);
                $this->assertSame('42_47-11_8_15_0', $fixture->getCacheIdentifier());
                $pageContext->versioningWorkspaceId = 0;
-               $fixture = new Fixtures\AccessibleRootlineUtility(42, '47-11', $pageContext);
+               $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(42, '47-11', $pageContext);
                $this->assertSame('42_47-11_8_0_0', $fixture->getCacheIdentifier());
        }