[TASK] Refactor unit test to cover stdWrap_age 01/48701/6
authorElmar Hinz <t3elmar@gmail.com>
Tue, 28 Jun 2016 09:52:11 +0000 (11:52 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Wed, 29 Jun 2016 11:00:32 +0000 (13:00 +0200)
Resolves: #76780
Releases: master
Change-Id: Ie41897d4ac2ab62577dd059e5a43844577691f62
Reviewed-on: https://review.typo3.org/48701
Tested-by: Bamboo TYPO3com <info@typo3.com>
Reviewed-by: Michael Oehlhof <typo3@oehlhof.de>
Tested-by: Michael Oehlhof <typo3@oehlhof.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php

index 9def097..ac8e313 100644 (file)
@@ -2934,87 +2934,88 @@ class ContentObjectRendererTest extends UnitTestCase
     }
 
     /**
+     * Check if stdWrap_age works properly.
+     *
+     * Show:
+     *
+     * - Delegates to calcAge.
+     * - Parameter 1 is the difference between $content and EXEC_TIME.
+     * - Parameter 2 is $conf['age'].
+     * - Returns the return value.
+     *
      * @test
+     * @return void
      */
-    public function stdWrap_ageCallsCalcAgeWithSubtractedTimestampAndSubPartOfArray()
+    public function stdWrap_age()
     {
+        $now = 10;
+        $content = '9';
+        $conf = ['age' => $this->getUniqueId('age')];
+        $return = $this->getUniqueId('return');
+        $difference = $now - (int)$content;
+        $GLOBALS['EXEC_TIME'] = $now;
         $subject = $this->getMockBuilder(ContentObjectRenderer::class)
-            ->setMethods(array('calcAge'))
-            ->getMock();
-        // Set exec_time to a hard timestamp
-        $GLOBALS['EXEC_TIME'] = 10;
-        $subject->expects($this->once())->method('calcAge')->with(1, 'Min| Hrs| Days| Yrs');
-        $subject->stdWrap_age(9, array('age' => 'Min| Hrs| Days| Yrs'));
+            ->setMethods(['calcAge'])->getMock();
+        $subject
+            ->expects($this->once())
+            ->method('calcAge')
+            ->with($difference, $conf['age'])
+            ->willReturn($return);
+        $this->assertSame($return, $subject->stdWrap_age($content, $conf));
     }
 
     /**
-     * Data provider for calcAgeCalculatesAgeOfTimestamp
+     * Data provider for calcAge.
      *
-     * @return array
-     * @see calcAge
+     * @return array [$expect, $timestamp, $labels]
      */
-    public function calcAgeCalculatesAgeOfTimestampDataProvider()
+    public function calcAgeDataProvider()
     {
-        return array(
-            'minutes' => array(
-                120,
-                ' min| hrs| days| yrs',
-                '2 min',
-            ),
-            'hours' => array(
-                7200,
-                ' min| hrs| days| yrs',
-                '2 hrs',
-            ),
-            'days' => array(
-                604800,
-                ' min| hrs| days| yrs',
-                '7 days',
-            ),
-            'day with provided singular labels' => array(
-                86400,
-                ' min| hrs| days| yrs| min| hour| day| year',
-                '1 day',
-            ),
-            'years' => array(
-                1417997800,
-                ' min| hrs| days| yrs',
-                '45 yrs',
-            ),
-            'different labels' => array(
-                120,
-                ' Minutes| Hrs| Days| Yrs',
-                '2 Minutes',
-            ),
-            'negative values' => array(
-                -604800,
-                ' min| hrs| days| yrs',
-                '-7 days',
-            ),
-            'default label values for wrong label input' => array(
-                121,
-                10,
-                '2 min',
-            ),
-            'default singular label values for wrong label input' => array(
-                31536000,
-                10,
-                '1 year',
-            )
-        );
+        return [
+            'minutes' => [
+                '2 min', 120, ' min| hrs| days| yrs',
+            ],
+            'hours' => [
+                '2 hrs', 7200, ' min| hrs| days| yrs',
+            ],
+            'days' => [
+                '7 days', 604800, ' min| hrs| days| yrs',
+            ],
+            'day with provided singular labels' => [
+                '1 day', 86400, ' min| hrs| days| yrs| min| hour| day| year',
+            ],
+            'years' => [
+                '45 yrs', 1417997800, ' min| hrs| days| yrs',
+            ],
+            'different labels' => [
+                '2 Minutes', 120, ' Minutes| Hrs| Days| Yrs',
+            ],
+            'negative values' => [
+                '-7 days', -604800, ' min| hrs| days| yrs',
+            ],
+            'default label values for wrong label input' => [
+                '2 min', 121, 10,
+            ],
+            'default singular label values for wrong label input' => [
+                '1 year', 31536000, 10,
+            ]
+        ];
     }
 
     /**
+     * Check if calcAge works properly.
+     *
+     * @test
+     * @dataProvider calcAgeDataProvider
+     * @param int $expect
      * @param int $timestamp
      * @param string $labels
-     * @param int $expectation
-     * @dataProvider calcAgeCalculatesAgeOfTimestampDataProvider
-     * @test
+     * @return void
      */
-    public function calcAgeCalculatesAgeOfTimestamp($timestamp, $labels, $expectation)
+    public function calcAge($expect, $timestamp, $labels)
     {
-        $result = $this->subject->calcAge($timestamp, $labels);
-        $this->assertEquals($result, $expectation);
+        $this->assertSame($expect,
+            $this->subject->calcAge($timestamp, $labels));
     }
 
     /**