[TASK] Add unit tests for stdWrap_numberFormat() 19/43619/5
authorMichael Oehlhof <typo3@oehlhof.de>
Mon, 28 Sep 2015 17:31:57 +0000 (19:31 +0200)
committerGeorg Ringer <georg.ringer@gmail.com>
Tue, 29 Sep 2015 04:01:49 +0000 (06:01 +0200)
Resolves: #70165
Releases: master
Change-Id: Ib8bc39be416d7030ce33e8cc8bd65dc4a2abb211
Reviewed-on: http://review.typo3.org/43619
Reviewed-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
Tested-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php
typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php

index c0da47f..56928b3 100644 (file)
@@ -4874,7 +4874,7 @@ class ContentObjectRenderer {
         *
         * @param float $content Value to process
         * @param array $conf TypoScript Configuration for numberFormat
-        * @return string The formated number
+        * @return string The formatted number
         */
        public function numberFormat($content, $conf) {
                $decimals = isset($conf['decimals.']) ? $this->stdWrap($conf['decimals'], $conf['decimals.']) : $conf['decimals'];
index d899f18..9215e8f 100644 (file)
@@ -827,6 +827,18 @@ class ContentObjectRendererTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        }
 
        /**
+        * Checks if stdWrap.cropHTML handles linebreaks correctly (by ignoring them)
+        *
+        * @test
+        */
+       public function cropHtmlWorksWithLinebreaks() {
+               $subject = "Lorem ipsum dolor sit amet,\nconsetetur sadipscing elitr,\nsed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam";
+               $expected = "Lorem ipsum dolor sit amet,\nconsetetur sadipscing elitr,\nsed diam nonumy eirmod tempor invidunt ut labore et dolore magna";
+               $result = $this->subject->cropHTML($subject, '121');
+               $this->assertEquals($expected, $result);
+       }
+
+       /**
         * @return array
         */
        public function stdWrap_roundDataProvider() {
@@ -873,18 +885,6 @@ class ContentObjectRendererTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        }
 
        /**
-        * Checks if stdWrap.cropHTML handles linebreaks correctly (by ignoring them)
-        *
-        * @test
-        */
-       public function cropHtmlWorksWithLinebreaks() {
-               $subject = "Lorem ipsum dolor sit amet,\nconsetetur sadipscing elitr,\nsed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam";
-               $expected = "Lorem ipsum dolor sit amet,\nconsetetur sadipscing elitr,\nsed diam nonumy eirmod tempor invidunt ut labore et dolore magna";
-               $result = $this->subject->cropHTML($subject, '121');
-               $this->assertEquals($expected, $result);
-       }
-
-       /**
         * Test for the stdWrap function "round"
         *
         * @param float $float
@@ -905,6 +905,84 @@ class ContentObjectRendererTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        /**
         * @return array
         */
+       public function stdWrap_numberFormatDataProvider() {
+               return array(
+                       'testing decimals' => array(
+                               0.8,
+                               array(
+                                       'numberFormat.' => array(
+                                               'decimals' => 2
+                                       ),
+                               ),
+                               '0.80'
+                       ),
+                       'testing decimals with input as string' => array(
+                               '0.8',
+                               array(
+                                       'numberFormat.' => array(
+                                               'decimals' => 2
+                                       ),
+                               ),
+                               '0.80'
+                       ),
+                       'testing dec_point' => array(
+                               0.8,
+                               array(
+                                       'numberFormat.' => array(
+                                               'decimals' => 1,
+                                               'dec_point' => ','
+                                       ),
+                               ),
+                               '0,8'
+                       ),
+                       'testing thousands_sep' => array(
+                               999.99,
+                               array(
+                                       'numberFormat.' => array(
+                                               'decimals' => 0,
+                                               'thousands_sep.' => array(
+                                                       'char' => 46
+                                               ),
+                                       ),
+                               ),
+                               '1.000'
+                       ),
+                       'testing mixture' => array(
+                               1281731.45,
+                               array(
+                                       'numberFormat.' => array(
+                                               'decimals' => 1,
+                                               'dec_point.' => array(
+                                                       'char' => 44
+                                               ),
+                                               'thousands_sep.' => array(
+                                                       'char' => 46
+                                               ),
+                                       ),
+                               ),
+                               '1.281.731,5'
+                       )
+               );
+       }
+
+       /**
+        * Test for the stdWrap function "round"
+        *
+        * @param float $float
+        * @param array $conf
+        * @param string $expected
+        * @return void
+        * @dataProvider stdWrap_numberFormatDataProvider
+        * @test
+        */
+       public function stdWrap_numberFormat($float, $conf, $expected) {
+               $result = $this->subject->stdWrap_numberFormat($float, $conf);
+               $this->assertEquals($expected, $result);
+       }
+
+       /**
+        * @return array
+        */
        public function stdWrap_trimDataProvider() {
                return array(
                        'trimstring' => array(