[TASK] Add unit test to cover stdwrap_prefixComment 23/48823/3
authorElmar Hinz <t3elmar@gmail.com>
Wed, 6 Jul 2016 11:00:37 +0000 (13:00 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Wed, 6 Jul 2016 21:40:13 +0000 (23:40 +0200)
Releases: master
Resolves: #76851
Change-Id: Ic249f25354385e4b89208a9a54d3e7e2f80f4885
Reviewed-on: https://review.typo3.org/48823
Tested-by: Bamboo TYPO3com <info@typo3.com>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php

index e8326ac..cf749c7 100644 (file)
@@ -2391,6 +2391,61 @@ class ContentObjectRendererTest extends UnitTestCase
     }
 
     /**
+     * Data provider for stdWrap_prefixComment.
+     *
+     * @retunr array [$expect, $content, $conf, $disable, $times, $will]
+     */
+    public function stdWrap_prefixCommentDataProvider()
+    {
+        $content = $this->getUniqueId('content');
+        $will = $this->getUniqueId('will');
+        $conf['prefixComment'] = $this->getUniqueId('prefixComment');
+        $emptyConf1 = [];
+        $emptyConf2['prefixComment'] = '';
+        return [
+            'standard case' => [$will, $content, $conf, false, 1, $will],
+            'emptyConf1' => [$content, $content, $emptyConf1, false, 0, $will],
+            'emptyConf2' => [$content, $content, $emptyConf2, false, 0, $will],
+            'disabled by bool' => [$content, $content, $conf, true, 0, $will],
+            'disabled by int' => [$content, $content, $conf, 1, 0, $will],
+        ];
+    }
+
+    /**
+     * Check that stdWrap_prefixComment works properly.
+     *
+     * Show:
+     *
+     *  - Delegates to method prefixComment.
+     *  - Parameter 1 is $conf['prefixComment'].
+     *  - Parameter 2 is [].
+     *  - Parameter 3 is $content.
+     *  - Returns the return value.
+     *  - Returns $content as is,
+     *    - if $conf['prefixComment'] is empty.
+     *    - if 'config.disablePrefixComment' is configured by the frontend.
+     *
+     *  @test
+     *  @dataProvider stdWrap_prefixCommentDataProvider
+     *  @return void
+     */
+    public function stdWrap_prefixComment(
+        $expect, $content, $conf, $disable, $times, $will)
+    {
+        $this->frontendControllerMock
+            ->config['config']['disablePrefixComment'] = $disable;
+        $subject = $this->getMockBuilder(ContentObjectRenderer::class)
+            ->setMethods(['prefixComment'])->getMock();
+        $subject
+            ->expects($this->exactly($times))
+            ->method('prefixComment')
+            ->with($conf['prefixComment'], [], $content)
+            ->willReturn($will);
+        $this->assertSame($expect,
+            $subject->stdWrap_prefixComment($content, $conf));
+    }
+
+    /**
      * Data provider for the hash test
      *
      * @return array [$expect, $content, $conf]