Skip to content

Commit

Permalink
BUGFIX: Fix support for typo3fluid/fluid 2.15
Browse files Browse the repository at this point in the history
Adjusts tests that mocked `AbstractViewHelper::renderChildren()` that is no longer invoked with version 2.15
  • Loading branch information
bwaidelich committed Sep 3, 2024
1 parent a82234e commit 415cbac
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
require_once(__DIR__ . '/../ViewHelperBaseTestcase.php');

use Neos\FluidAdaptor\Tests\Unit\ViewHelpers\ViewHelperBaseTestcase;
use TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\ViewHelperNode;

/**
* Test for \Neos\FluidAdaptor\ViewHelpers\Format\CropViewHelper
Expand All @@ -37,7 +38,7 @@ protected function setUp(): void
*/
public function viewHelperDoesNotCropTextIfMaxCharactersIsLargerThanNumberOfCharacters()
{
$this->viewHelper->expects(self::once())->method('renderChildren')->will(self::returnValue('some text'));
$this->simulateViewHelperChildNodeContent($this->viewHelper, 'some text');
$this->viewHelper = $this->prepareArguments($this->viewHelper, ['maxCharacters' => 50]);
$actualResult = $this->viewHelper->render();
self::assertEquals('some text', $actualResult);
Expand All @@ -48,7 +49,7 @@ public function viewHelperDoesNotCropTextIfMaxCharactersIsLargerThanNumberOfChar
*/
public function viewHelperAppendsEllipsisToTruncatedText()
{
$this->viewHelper->expects(self::once())->method('renderChildren')->will(self::returnValue('some text'));
$this->simulateViewHelperChildNodeContent($this->viewHelper, 'some text');
$this->viewHelper = $this->prepareArguments($this->viewHelper, ['maxCharacters' => 5]);
$actualResult = $this->viewHelper->render();
self::assertEquals('some ...', $actualResult);
Expand All @@ -59,7 +60,7 @@ public function viewHelperAppendsEllipsisToTruncatedText()
*/
public function viewHelperAppendsCustomSuffix()
{
$this->viewHelper->expects(self::once())->method('renderChildren')->will(self::returnValue('some text'));
$this->simulateViewHelperChildNodeContent($this->viewHelper, 'some text');
$this->viewHelper = $this->prepareArguments($this->viewHelper, ['maxCharacters' => 3, 'append' => '[custom suffix]']);
$actualResult = $this->viewHelper->render();
self::assertEquals('som[custom suffix]', $actualResult);
Expand All @@ -70,7 +71,7 @@ public function viewHelperAppendsCustomSuffix()
*/
public function viewHelperAppendsSuffixEvenIfResultingTextIsLongerThanMaxCharacters()
{
$this->viewHelper->expects(self::once())->method('renderChildren')->will(self::returnValue('some text'));
$this->simulateViewHelperChildNodeContent($this->viewHelper, 'some text');
$this->viewHelper = $this->prepareArguments($this->viewHelper, ['maxCharacters' => 8]);
$actualResult = $this->viewHelper->render();
self::assertEquals('some tex...', $actualResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function renderUsesValueAsSourceIfSpecified()
*/
public function renderUsesChildnodesAsSourceIfSpecified()
{
$this->viewHelper->expects(self::atLeastOnce())->method('renderChildren')->will(self::returnValue('Some string'));
$this->simulateViewHelperChildNodeContent($this->viewHelper, 'Some string');
$this->viewHelper = $this->prepareArguments($this->viewHelper, []);
$actualResult = $this->viewHelper->render();
self::assertEquals('Some string', $actualResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function renderUsesValueAsSourceIfSpecified()
*/
public function renderUsesChildnodesAsSourceIfSpecified()
{
$this->viewHelper->expects(self::atLeastOnce())->method('renderChildren')->will(self::returnValue('Some string'));
$this->simulateViewHelperChildNodeContent($this->viewHelper, 'Some string');
$this->viewHelper = $this->prepareArguments($this->viewHelper, []);
$actualResult = $this->viewHelper->render();
self::assertEquals('Some string', $actualResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected function setUp(): void
*/
public function stringsArePaddedWithBlanksByDefault()
{
$this->viewHelper->expects(self::once())->method('renderChildren')->will(self::returnValue('foo'));
$this->simulateViewHelperChildNodeContent($this->viewHelper, 'foo');
$this->viewHelper = $this->prepareArguments($this->viewHelper, ['padLength' => 10]);
$actualResult = $this->viewHelper->render();
self::assertEquals('foo ', $actualResult);
Expand All @@ -48,7 +48,7 @@ public function stringsArePaddedWithBlanksByDefault()
*/
public function paddingStringCanBeSpecified()
{
$this->viewHelper->expects(self::once())->method('renderChildren')->will(self::returnValue('foo'));
$this->simulateViewHelperChildNodeContent($this->viewHelper, 'foo');
$this->viewHelper = $this->prepareArguments($this->viewHelper, ['padLength' => 10, 'padString' => '-=']);
$actualResult = $this->viewHelper->render();
self::assertEquals('foo-=-=-=-', $actualResult);
Expand All @@ -59,7 +59,7 @@ public function paddingStringCanBeSpecified()
*/
public function stringIsNotTruncatedIfPadLengthIsBelowStringLength()
{
$this->viewHelper->expects(self::once())->method('renderChildren')->will(self::returnValue('some long string'));
$this->simulateViewHelperChildNodeContent($this->viewHelper, 'some long string');
$this->viewHelper = $this->prepareArguments($this->viewHelper, ['padLength' => 5]);
$actualResult = $this->viewHelper->render();
self::assertEquals('some long string', $actualResult);
Expand All @@ -70,7 +70,7 @@ public function stringIsNotTruncatedIfPadLengthIsBelowStringLength()
*/
public function integersArePaddedCorrectly()
{
$this->viewHelper->expects(self::once())->method('renderChildren')->will(self::returnValue(123));
$this->simulateViewHelperChildNodeContent($this->viewHelper, 123);
$this->viewHelper = $this->prepareArguments($this->viewHelper, ['padLength' => 5, 'padString' => '0']);
$actualResult = $this->viewHelper->render(5, '0');
self::assertEquals('12300', $actualResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function renderUsesValueAsSourceIfSpecified()
*/
public function renderUsesChildnodesAsSourceIfSpecified()
{
$this->viewHelper->expects(self::atLeastOnce())->method('renderChildren')->will(self::returnValue('Source'));
$this->simulateViewHelperChildNodeContent($this->viewHelper, 'Source');
$this->viewHelper = $this->prepareArguments($this->viewHelper, []);
$actualResult = $this->viewHelper->render();
self::assertEquals('Source', $actualResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
use Neos\FluidAdaptor\Core\ViewHelper\AbstractViewHelper;
use Neos\Http\Factories\ServerRequestFactory;
use Neos\Http\Factories\UriFactory;
use PHPUnit\Framework\MockObject\MockObject;
use TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\ViewHelperNode;
use TYPO3Fluid\Fluid\Core\ViewHelper\TagBuilder;

/**
Expand Down Expand Up @@ -175,4 +177,12 @@ protected function prepareArguments(\TYPO3Fluid\Fluid\Core\ViewHelper\AbstractVi
$viewHelper->initialize();
return $viewHelper;
}

protected function simulateViewHelperChildNodeContent(AbstractViewHelper&MockObject $viewHelper, string|int $content): void
{
$viewHelper->method('renderChildren')->willReturn($content);
$mockThenViewHelperNode = $this->createMock(ViewHelperNode::class);
$mockThenViewHelperNode->method('evaluateChildNodes')->willReturn($content);
$viewHelper->setViewHelperNode($mockThenViewHelperNode);
}
}

0 comments on commit 415cbac

Please sign in to comment.