From 3176eb8e0ebc5b262960b62b48a353de67172712 Mon Sep 17 00:00:00 2001 From: Elmar Hinz <t3elmar@gmail.com> Date: Thu, 23 Jun 2016 10:44:18 +0200 Subject: [PATCH] [TASK] Refactor unit test to cover stdWrap_ifNull Resolves: #76753 Releases: master Change-Id: Ibbebfaee0cb2a11cecf40d981194e217e9309111 Reviewed-on: https://review.typo3.org/48650 Reviewed-by: Daniel Goerz <ervaude@gmail.com> Tested-by: Daniel Goerz <ervaude@gmail.com> Reviewed-by: Michael Oehlhof <typo3@oehlhof.de> Tested-by: Michael Oehlhof <typo3@oehlhof.de> Reviewed-by: Joerg Boesche <typo3@joergboesche.de> Tested-by: Joerg Boesche <typo3@joergboesche.de> Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl> Tested-by: Wouter Wolters <typo3@wouterwolters.nl> --- .../ContentObjectRendererTest.php | 59 ++++++++++--------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php b/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php index 1004bf9566b6..10d7d9545ca3 100644 --- a/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php +++ b/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php @@ -2535,41 +2535,46 @@ class ContentObjectRendererTest extends \TYPO3\CMS\Core\Tests\UnitTestCase } /** - * @param string|NULL $content - * @param array $configuration - * @param string $expected - * @dataProvider stdWrap_ifNullDeterminesNullValuesDataProvider - * @test + * Data provider for stdWrap_ifNull. + * + * @return array [$expect, $content, $conf] */ - public function stdWrap_ifNullDeterminesNullValues($content, array $configuration, $expected) + public function stdWrap_ifNullDataProvider() { - $result = $this->subject->stdWrap_ifNull($content, $configuration); - $this->assertEquals($expected, $result); + $alt = $this->getUniqueId('alternative content'); + $conf = ['ifNull' => $alt]; + return [ + 'only null is null' => [$alt, null, $conf], + 'zero is not null' => [0, 0, $conf], + 'float zero is not null' => [0.0, 0.0, $conf], + 'false is not null' => [false, false, $conf], + 'zero is not null' => [0, 0, $conf], + 'zero string is not null' => ['0', '0', $conf], + 'empty string is not null' => ['', '', $conf], + 'whitespace is not null' => [TAB . '', TAB . '', $conf], + ]; } /** - * Data provider for stdWrap_ifNullDeterminesNullValues test + * Check that stdWrap_ifNull works properly. * - * @return array + * Show: + * + * - Returns the content, if not null. + * - Otherwise returns $conf['ifNull']. + * - Null is strictly checked by identiy with null. + * + * @test + * @dataProvider stdWrap_ifNullDataProvider + * @param mixed $expected The expected output. + * @param mixed $content The given input. + * @param array $conf The given configuration. + * @return void */ - public function stdWrap_ifNullDeterminesNullValuesDataProvider() + public function stdWrap_ifNull($expect, $content, $conf) { - return array( - 'null value' => array( - null, - array( - 'ifNull' => '1', - ), - '1', - ), - 'zero value' => array( - '0', - array( - 'ifNull' => '1', - ), - '0', - ), - ); + $result = $this->subject->stdWrap_ifNull($content, $conf); + $this->assertSame($expect, $result); } /** -- GitLab