[BUGFIX] Adapt tests concerning fluid viewhelpers 74/59474/6
authorAnja Leichsenring <aleichsenring@ab-softlab.de>
Fri, 18 Jan 2019 10:13:34 +0000 (11:13 +0100)
committerBenni Mack <benni@typo3.org>
Fri, 18 Jan 2019 15:15:42 +0000 (16:15 +0100)
Since the release of fluid 2.6.0 unit tests fail due to
changed calling sequence. The unit tests use mocked calls
to keep track of internal sequence.
Using the prophecy mock framework gives better control and fixes
the issue for now.

Resolves: #87474
Releases: master, 9.5
Change-Id: I371ae8c7793ae74ecc827696cbbb97c30b3862f8
Reviewed-on: https://review.typo3.org/59474
Tested-by: TYPO3com <noreply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Form/HiddenViewHelperTest.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Form/PasswordViewHelperTest.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Form/Select/OptionViewHelperTest.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Form/SelectViewHelperTest.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Form/SubmitViewHelperTest.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Form/TextareaViewHelperTest.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Form/UploadViewHelperTest.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Link/EmailViewHelperTest.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Link/ExternalViewHelperTest.php

index 2ff5d22..55fd474 100644 (file)
@@ -13,6 +13,7 @@ namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form;
  *
  * The TYPO3 project - inspiring people to share!
  */
+
 use TYPO3\CMS\Fluid\ViewHelpers\Form\HiddenViewHelper;
 use TYPO3Fluid\Fluid\Core\ViewHelper\TagBuilder;
 
@@ -38,18 +39,21 @@ class HiddenViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\
      */
     public function renderCorrectlySetsTagNameAndDefaultAttributes()
     {
-        $mockTagBuilder = $this->getMockBuilder(TagBuilder::class)
-            ->setMethods(['setTagName', 'addAttribute'])
-            ->getMock();
-        $mockTagBuilder->expects($this->once())->method('setTagName')->with('input');
-        $mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('type', 'hidden');
-        $mockTagBuilder->expects($this->at(2))->method('addAttribute')->with('name', 'foo');
+        $tagBuilder = $this->prophesize(TagBuilder::class);
+        $tagBuilder->render()->shouldBeCalled();
+        // @todo remove condition once typo3fluid/fluid version 2.6.0 will be the minimum version
+        if (class_exists(\TYPO3Fluid\Fluid\ViewHelpers\InlineViewHelper::class)) {
+            $tagBuilder->reset()->shouldBeCalled();
+        }
+        $tagBuilder->addAttribute('type', 'hidden')->shouldBeCalled();
+        $tagBuilder->addAttribute('name', 'foo')->shouldBeCalled();
+        $tagBuilder->addAttribute('value', 'bar')->shouldBeCalled();
+        $tagBuilder->setTagName('input')->shouldBeCalled();
         $this->viewHelper->expects($this->once())->method('registerFieldNameForFormTokenGeneration')->with('foo');
-        $mockTagBuilder->expects($this->at(3))->method('addAttribute')->with('value', 'bar');
 
         $this->viewHelper->expects($this->once())->method('getName')->will($this->returnValue('foo'));
         $this->viewHelper->expects($this->once())->method('getValueAttribute')->will($this->returnValue('bar'));
-        $this->viewHelper->setTagBuilder($mockTagBuilder);
+        $this->viewHelper->setTagBuilder($tagBuilder->reveal());
 
         $this->viewHelper->initializeArgumentsAndRender();
     }
index 8ded544..e82df86 100644 (file)
@@ -42,7 +42,7 @@ class PasswordViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\For
             ->setMethods(['setTagName'])
             ->disableOriginalConstructor()
             ->getMock();
-        $mockTagBuilder->expects($this->once())->method('setTagName')->with('input');
+        $mockTagBuilder->expects($this->atLeastOnce())->method('setTagName')->with('input');
         $this->viewHelper->setTagBuilder($mockTagBuilder);
         $this->viewHelper->initializeArgumentsAndRender();
     }
index dd38b79..50cde8f 100644 (file)
@@ -49,7 +49,7 @@ class OptionViewHelperTest extends ViewHelperBaseTestcase
     public function optionTagNameIsSet(): void
     {
         $tagBuilder = $this->createMock(TagBuilder::class);
-        $tagBuilder->expects($this->once())->method('setTagName')->with('option');
+        $tagBuilder->expects($this->atLeastOnce())->method('setTagName')->with('option');
         $this->viewHelper->setTagBuilder($tagBuilder);
         $this->viewHelper->initializeArgumentsAndRender();
     }
index 7b17b29..8d32d56 100644 (file)
@@ -46,7 +46,7 @@ class SelectViewHelperTest extends ViewHelperBaseTestcase
      */
     public function selectCorrectlySetsTagName()
     {
-        $this->tagBuilder->expects($this->once())->method('setTagName')->with('select');
+        $this->tagBuilder->expects($this->atLeastOnce())->method('setTagName')->with('select');
 
         $this->arguments['options'] = [];
         $this->injectDependenciesIntoViewHelper($this->viewHelper);
index fd38b2e..475322e 100644 (file)
@@ -13,6 +13,7 @@ namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form;
  *
  * The TYPO3 project - inspiring people to share!
  */
+
 use TYPO3Fluid\Fluid\Core\ViewHelper\TagBuilder;
 
 /**
@@ -38,13 +39,17 @@ class SubmitViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\
      */
     public function renderCorrectlySetsTagNameAndDefaultAttributes()
     {
-        $mockTagBuilder = $this->getMockBuilder(TagBuilder::class)
-            ->setMethods(['setTagName', 'addAttribute'])
-            ->getMock();
-        $mockTagBuilder->expects($this->once())->method('setTagName')->with('input');
-        $mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('type', 'submit');
+        $tagBuilder = $this->prophesize(TagBuilder::class);
+        $tagBuilder->render()->shouldBeCalled();
+        // @todo remove condition once typo3fluid/fluid version 2.6.0 will be the minimum version
+        if (class_exists(\TYPO3Fluid\Fluid\ViewHelpers\InlineViewHelper::class)) {
+            $tagBuilder->reset()->shouldBeCalled();
+        }
+        $tagBuilder->addAttribute('type', 'submit')->shouldBeCalled();
+        $tagBuilder->addAttribute('value', null)->shouldBeCalled();
+        $tagBuilder->setTagName('input')->shouldBeCalled();
 
-        $this->viewHelper->setTagBuilder($mockTagBuilder);
+        $this->viewHelper->setTagBuilder($tagBuilder->reveal());
 
         $this->viewHelper->initializeArgumentsAndRender();
     }
index a651f9d..495e597 100644 (file)
@@ -43,7 +43,7 @@ class TextareaViewHelperTest extends FormFieldViewHelperBaseTestcase
             ->setMethods(['setTagName'])
             ->disableOriginalConstructor()
             ->getMock();
-        $mockTagBuilder->expects($this->once())->method('setTagName')->with('textarea');
+        $mockTagBuilder->expects($this->atLeastOnce())->method('setTagName')->with('textarea');
         $this->viewHelper->setTagBuilder($mockTagBuilder);
 
         $this->viewHelper->initializeArgumentsAndRender();
index 481e05f..d3fb1cf 100644 (file)
@@ -41,7 +41,7 @@ class UploadViewHelperTest extends ViewHelperBaseTestcase
     public function renderCorrectlySetsTagName()
     {
         $this->tagBuilder = $this->createMock(\TYPO3Fluid\Fluid\Core\ViewHelper\TagBuilder::class);
-        $this->tagBuilder->expects($this->once())->method('setTagName')->with('input');
+        $this->tagBuilder->expects($this->atLeastOnce())->method('setTagName')->with('input');
         $this->viewHelper->setTagBuilder($this->tagBuilder);
         $this->viewHelper->initializeArgumentsAndRender();
     }
index c84a9a4..a21a061 100644 (file)
@@ -54,7 +54,7 @@ class EmailViewHelperTest extends ViewHelperBaseTestcase
         $mockTagBuilder = $this->getMockBuilder(TagBuilder::class)
             ->setMethods(['setTagName', 'addAttribute', 'setContent'])
             ->getMock();
-        $mockTagBuilder->expects($this->once())->method('setTagName')->with('a');
+        $mockTagBuilder->expects($this->atLeastOnce())->method('setTagName')->with('a');
         $mockTagBuilder->expects($this->once())->method('addAttribute')->with('href', 'mailto:some@email.tld');
         $mockTagBuilder->expects($this->once())->method('setContent')->with('some content');
         $this->viewHelper->setTagBuilder($mockTagBuilder);
index 37130ea..3ea2b31 100644 (file)
@@ -42,7 +42,7 @@ class ExternalViewHelperTest extends ViewHelperBaseTestcase
         $mockTagBuilder = $this->getMockBuilder(TagBuilder::class)
             ->setMethods(['setTagName', 'addAttribute', 'setContent'])
             ->getMock();
-        $mockTagBuilder->expects($this->once())->method('setTagName')->with('a');
+        $mockTagBuilder->expects($this->atLeastOnce())->method('setTagName')->with('a');
         $mockTagBuilder->expects($this->once())->method('addAttribute')->with('href', 'http://www.some-domain.tld');
         $mockTagBuilder->expects($this->once())->method('setContent')->with('some content');
         $this->viewHelper->setTagBuilder($mockTagBuilder);
@@ -66,7 +66,7 @@ class ExternalViewHelperTest extends ViewHelperBaseTestcase
         $mockTagBuilder = $this->getMockBuilder(TagBuilder::class)
             ->setMethods(['setTagName', 'addAttribute', 'setContent'])
             ->getMock();
-        $mockTagBuilder->expects($this->once())->method('setTagName')->with('a');
+        $mockTagBuilder->expects($this->atLeastOnce())->method('setTagName')->with('a');
         $mockTagBuilder->expects($this->once())->method('addAttribute')->with('href', 'http://www.some-domain.tld');
         $mockTagBuilder->expects($this->once())->method('setContent')->with('some content');
         $this->viewHelper->setTagBuilder($mockTagBuilder);
@@ -90,7 +90,7 @@ class ExternalViewHelperTest extends ViewHelperBaseTestcase
         $mockTagBuilder = $this->getMockBuilder(TagBuilder::class)
             ->setMethods(['setTagName', 'addAttribute', 'setContent'])
             ->getMock();
-        $mockTagBuilder->expects($this->once())->method('setTagName')->with('a');
+        $mockTagBuilder->expects($this->atLeastOnce())->method('setTagName')->with('a');
         $mockTagBuilder->expects($this->once())->method('addAttribute')->with('href', 'ftp://some-domain.tld');
         $mockTagBuilder->expects($this->once())->method('setContent')->with('some content');
         $this->viewHelper->setTagBuilder($mockTagBuilder);
@@ -115,7 +115,7 @@ class ExternalViewHelperTest extends ViewHelperBaseTestcase
         $mockTagBuilder = $this->getMockBuilder(TagBuilder::class)
             ->setMethods(['setTagName', 'addAttribute', 'setContent'])
             ->getMock();
-        $mockTagBuilder->expects($this->once())->method('setTagName')->with('a');
+        $mockTagBuilder->expects($this->atLeastOnce())->method('setTagName')->with('a');
         $mockTagBuilder->expects($this->once())->method('addAttribute')->with('href', 'some-domain.tld');
         $mockTagBuilder->expects($this->once())->method('setContent')->with('some content');
         $this->viewHelper->setTagBuilder($mockTagBuilder);