From 52819c95fe23338c6e4e4efa221f209c1edf1097 Mon Sep 17 00:00:00 2001 From: Michael Oehlhof <typo3@oehlhof.de> Date: Fri, 2 Oct 2015 22:59:50 +0200 Subject: [PATCH] [TASK] Add unit tests for stdWrap_age() and calcAge() Resolves: #70321 Releases: master Change-Id: I7eba3a6da86c07e1e0c7421671cfabdc25c493c9 Reviewed-on: http://review.typo3.org/43752 Reviewed-by: Daniel Goerz <ervaude@gmail.com> Tested-by: Daniel Goerz <ervaude@gmail.com> Reviewed-by: Morton Jonuschat <m.jonuschat@mojocode.de> Tested-by: Morton Jonuschat <m.jonuschat@mojocode.de> --- .../ContentObjectRendererTest.php | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php b/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php index 24b9cd20223d..854d1211904c 100644 --- a/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php +++ b/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php @@ -1839,6 +1839,88 @@ class ContentObjectRendererTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { $this->assertEquals($expected, $result); } + /** + * @test + */ + public function stdWrap_ageCallsCalcAgeWithSubtractedTimestampAndSubPartOfArray() { + $subject = $this->getMock( + \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class, + array('calcAge') + ); + // 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')); + } + + /** + * Data provider for calcAgeCalculatesAgeOfTimestamp + * + * @return array + * @see calcAge + */ + public function calcAgeCalculatesAgeOfTimestampDataProvider() { + 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', + ) + ); + } + + /** + * @param int $timestamp + * @param string $labels + * @param int $expectation + * @dataProvider calcAgeCalculatesAgeOfTimestampDataProvider + * @test + */ + public function calcAgeCalculatesAgeOfTimestamp($timestamp, $labels, $expectation) { + $result = $this->subject->calcAge($timestamp, $labels); + $this->assertEquals($result, $expectation); + } + /** * Data provider for stdWrap_stdWrapValue test * -- GitLab