From 879b46be5bf75c1e80b3056351587c148c2fd638 Mon Sep 17 00:00:00 2001
From: Elmar Hinz <t3elmar@gmail.com>
Date: Thu, 23 Jun 2016 11:10:55 +0200
Subject: [PATCH] [TASK] Refactor unit test to cover stdWrap_ifEmpty

Releases: master
Resolves: #76752
Change-Id: Ice13eba7944f4fca04d167986a0c83c3a99d87f0
Reviewed-on: https://review.typo3.org/48649
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             | 81 ++++++++++---------
 1 file changed, 41 insertions(+), 40 deletions(-)

diff --git a/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php b/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php
index 10d7d9545ca3..40739b8052d2 100644
--- a/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php
+++ b/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php
@@ -2578,55 +2578,56 @@ class ContentObjectRendererTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
     }
 
     /**
-     * Data provider for stdWrap_ifEmptyDeterminesEmptyValues test
+     * Data provider for stdWrap_ifEmpty.
      *
-     * @return array
+     * @return array [$expect, $content, $conf]
      */
-    public function stdWrap_ifEmptyDeterminesEmptyValuesDataProvider()
+    public function stdWrap_ifEmptyDataProvider()
     {
-        return array(
-            'null value' => array(
-                null,
-                array(
-                    'ifEmpty' => '1',
-                ),
-                '1',
-            ),
-            'empty value' => array(
-                '',
-                array(
-                    'ifEmpty' => '1',
-                ),
-                '1',
-            ),
-            'string value' => array(
-                'string',
-                array(
-                    'ifEmpty' => '1',
-                ),
-                'string',
-            ),
-            'empty string value' => array(
-                '        ',
-                array(
-                    'ifEmpty' => '1',
-                ),
-                '1',
-            ),
-        );
+        $alt = $this->getUniqueId('alternative content');
+        $conf = ['ifEmpty' => $alt];
+        return [
+            // empty cases
+            'null is empty' => [ $alt, null, $conf ],
+            'false is empty' => [ $alt, false, $conf ],
+            'zero is empty' => [ $alt, 0, $conf ],
+            'float zero is empty' => [ $alt, 0.0, $conf ],
+            'whitespace is empty' => [ $alt, TAB . ' ', $conf ],
+            'empty string is empty' => [ $alt, '', $conf ],
+            'zero string is empty' => [ $alt, '0', $conf ],
+            'zero string is empty with whitespace' => [
+                $alt, TAB . ' 0 ' . TAB, $conf
+            ],
+            // non-empty cases
+            'string is not empty' => [ 'string', 'string', $conf ],
+            '1 is not empty' => [ 1, 1, $conf ],
+            '-1 is not empty' => [ -1, -1, $conf ],
+            '0.1 is not empty' => [ 0.1, 0.1, $conf ],
+            '-0.1 is not empty' => [ -0.1, -0.1, $conf ],
+            'true is not empty' => [ true, true, $conf ],
+        ];
     }
 
     /**
-     * @param string|NULL $content
-     * @param array $configuration
-     * @param string $expected
-     * @dataProvider stdWrap_ifEmptyDeterminesEmptyValuesDataProvider
+     * Check that stdWrap_ifEmpty works properly.
+     *
+     * Show:
+     *
+     * - Returns the content, if not empty.
+     * - Otherwise returns $conf['ifEmpty'].
+     * - Empty is checked by cast to boolean after trimming.
+     *
      * @test
+     * @dataProvider stdWrap_ifEmptyDataProvider
+     * @param mixed $expect The expected output.
+     * @param mixed $content The given content.
+     * @param array $conf The given configuration.
+     * @return void
      */
-    public function stdWrap_ifEmptyDeterminesEmptyValues($content, array $configuration, $expected)
+    public function stdWrap_ifEmpty($expect, $content, $conf)
     {
-        $result = $this->subject->stdWrap_ifEmpty($content, $configuration);
-        $this->assertEquals($expected, $result);
+        $result = $this->subject->stdWrap_ifEmpty($content, $conf);
+        $this->assertSame($expect, $result);
     }
 
     /**
-- 
GitLab