[FEATURE] Fallback/default case for SwitchViewhelper
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Tests / Unit / ViewHelpers / CaseViewHelperTest.php
index 18427e6..4c2276e 100644 (file)
@@ -87,4 +87,64 @@ class CaseViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\ViewHel
                $this->assertSame('', $this->viewHelper->render('someOtherValue'));
        }
 
+       /**
+        * @test
+        */
+       public function renderReturnsChildNodesIfDefaultIsTrue() {
+               $this->viewHelperVariableContainer->expects(
+                       $this->atLeastOnce())
+                       ->method('exists')
+                       ->with('TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper', 'switchExpression')
+                       ->will($this->returnValue(TRUE)
+                       );
+               $this->viewHelperVariableContainer->expects(
+                       $this->atLeastOnce())->method('get')
+                       ->with('TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper', 'switchExpression')
+                       ->will($this->returnValue(NULL)
+                       );
+
+               $renderedChildNodes = 'ChildNodes';
+               $this->viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue($renderedChildNodes));
+
+               $this->assertSame($renderedChildNodes, $this->viewHelper->render(NULL, TRUE));
+       }
+
+       /**
+        * @test
+        * @expectedException \TYPO3\CMS\Fluid\Core\ViewHelper\Exception
+        */
+       public function renderThrowsExceptionIfNeighterValueNorDefaultAreGiven() {
+               $this->viewHelperVariableContainer->expects(
+                       $this->atLeastOnce())
+                       ->method('exists')
+                       ->with('TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper', 'switchExpression')
+                       ->will($this->returnValue(TRUE)
+                       );
+               $this->viewHelperVariableContainer->expects($this->never())->method('get');
+
+               $this->viewHelper->render(NULL, FALSE);
+       }
+
+       /**
+        * @test
+        */
+       public function renderReturnsChildNodesEvenIfValueIsFalseButDefaultIsTrue() {
+               $this->viewHelperVariableContainer->expects(
+                       $this->atLeastOnce())
+                       ->method('exists')
+                       ->with('TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper', 'switchExpression')
+                       ->will($this->returnValue(TRUE)
+                       );
+               $this->viewHelperVariableContainer->expects(
+                       $this->atLeastOnce())->method('get')
+                       ->with('TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper', 'switchExpression')
+                       ->will($this->returnValue('someValue')
+                       );
+
+               $renderedChildNodes = 'ChildNodes';
+               $this->viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue($renderedChildNodes));
+
+               $this->assertSame($renderedChildNodes, $this->viewHelper->render('someOtherValue', TRUE));
+       }
+
 }