From 2bcf1809f526232f0d24f7bcc6c1c812e8783c3d Mon Sep 17 00:00:00 2001 From: haogatyp Date: Thu, 26 Oct 2023 14:42:08 +0200 Subject: [PATCH] [MAINTENANCE] Add ViewHelper functional tests instead of unit tests. (#902) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Oliver Stöhr --- .../ViewHelpers/JsFooterViewHelperTest.php | 52 +++++++++++ .../MetadataWrapVariableViewHelperTest.php | 60 +++++++++++++ .../ViewHelpers/StdWrapViewHelperTest.php | 87 +++++++++++++++++++ 3 files changed, 199 insertions(+) create mode 100644 Tests/Functional/ViewHelpers/JsFooterViewHelperTest.php create mode 100644 Tests/Functional/ViewHelpers/MetadataWrapVariableViewHelperTest.php create mode 100644 Tests/Functional/ViewHelpers/StdWrapViewHelperTest.php diff --git a/Tests/Functional/ViewHelpers/JsFooterViewHelperTest.php b/Tests/Functional/ViewHelpers/JsFooterViewHelperTest.php new file mode 100644 index 000000000..560dcac5e --- /dev/null +++ b/Tests/Functional/ViewHelpers/JsFooterViewHelperTest.php @@ -0,0 +1,52 @@ + + * + * This file is part of the Kitodo and TYPO3 projects. + * + * @license GNU General Public License version 3 or later. + * For the full copyright and license information, please read the + * LICENSE.txt file that was distributed with this source code. + */ + +namespace Kitodo\Dlf\Tests\Unit\ViewHelpers; + +use Kitodo\Dlf\Tests\Functional\FunctionalTestCase; +use Kitodo\Dlf\ViewHelpers\JsFooterViewHelper; +use TYPO3\CMS\Core\Page\PageRenderer; +use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Fluid\View\StandaloneView; + +/** + * @covers JsFooterViewHelper + */ +class JsFooterViewHelperTest extends FunctionalTestCase +{ + /** + * @var bool Speed up this test case, it needs no database + */ + protected $initializeDatabase = false; + + /** + * @test + */ + public function pageRendererCallsAddJsFooterInlineCode(): void + { + $pageRendererProphecy = $this->getMockBuilder(PageRenderer::class)->getMock(); + + $pageRendererProphecy->expects(self::once())->method('addJsFooterInlineCode')->with( + 'js-dlf-inline-footer', '$(document).ready(function() {});' + ); + + GeneralUtility::setSingletonInstance(PageRenderer::class, $pageRendererProphecy); + + $view = new StandaloneView(); + $view->setTemplateSource( + ' + + ' + ); + + $view->render(); + } +} diff --git a/Tests/Functional/ViewHelpers/MetadataWrapVariableViewHelperTest.php b/Tests/Functional/ViewHelpers/MetadataWrapVariableViewHelperTest.php new file mode 100644 index 000000000..e82a37000 --- /dev/null +++ b/Tests/Functional/ViewHelpers/MetadataWrapVariableViewHelperTest.php @@ -0,0 +1,60 @@ + + * + * This file is part of the Kitodo and TYPO3 projects. + * + * @license GNU General Public License version 3 or later. + * For the full copyright and license information, please read the + * LICENSE.txt file that was distributed with this source code. + */ + +namespace Kitodo\Dlf\Tests\Unit\ViewHelpers; + +use Kitodo\Dlf\Tests\Functional\FunctionalTestCase; +use Kitodo\Dlf\ViewHelpers\MetadataWrapVariableViewHelper; +use TYPO3\CMS\Fluid\View\StandaloneView; +use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextFactory; + +/** + * @covers MetadataWrapVariableViewHelper + */ +class MetadataWrapVariableViewHelperTest extends FunctionalTestCase +{ + /** + * @var bool Speed up this test case, it needs no database + */ + protected $initializeDatabase = false; + + /** + * @test + */ + public function renderingContextCallsGetVariableProviderAdd(): void + { + $view = new StandaloneView(); + + $view->assign( + 'configObject', + [ 'wrap' => 'all.wrap = + key.wrap = + value.required = 1 + value.wrap =
  • |
  • ' + ] + ); + $view->setTemplateSource( + ' + {configObject.wrap -> kitodo:metadataWrapVariable(name: \'metadataWrap\')} + ' + ); + $view->render(); + + $this->assertEquals( + [ + 'key' => ['wrap' => ''], + 'value' => ['required' => 1, 'wrap' => '
  • |
  • '], + 'all' => ['wrap' => ''] + ], + $view->getRenderingContext()->getVariableProvider()->get('metadataWrap') + ); + } +} diff --git a/Tests/Functional/ViewHelpers/StdWrapViewHelperTest.php b/Tests/Functional/ViewHelpers/StdWrapViewHelperTest.php new file mode 100644 index 000000000..30191559a --- /dev/null +++ b/Tests/Functional/ViewHelpers/StdWrapViewHelperTest.php @@ -0,0 +1,87 @@ + + * + * This file is part of the Kitodo and TYPO3 projects. + * + * @license GNU General Public License version 3 or later. + * For the full copyright and license information, please read the + * LICENSE.txt file that was distributed with this source code. + */ + +namespace Kitodo\Dlf\Tests\Unit\ViewHelpers; + +use Kitodo\Dlf\Tests\Functional\FunctionalTestCase; +use Kitodo\Dlf\ViewHelpers\StdWrapViewHelper; +use TYPO3\CMS\Fluid\View\StandaloneView; +use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextFactory; + +/** + * @covers StdWrapViewHelper + */ +class StdWrapViewHelperTest extends FunctionalTestCase +{ + /** + * @var bool Speed up this test case, it needs no database + */ + protected $initializeDatabase = false; + + /** + * @test + */ + public function renderWithStdWrap(): void + { + $view = new StandaloneView(); + $view->assign( + 'metadataWrap', + [ + 'key' => ['wrap' => ''], + 'value' => ['required' => 1, 'wrap' => '
  • |
  • '], + 'all' => ['wrap' => ''] + ] + ); + + // A fully filled array with correct values does not make any difference. The rendering result + // is not been influenced by the viewhelpers data parameter. + $view->assign('metaSectionCObj', [0 => ['tilte' => 'A test title']]); + + $view->setTemplateSource( + ' + + Label +

    Title

    Text

    +
    + ' + ); + + $this->assertXmlStringEqualsXmlString( + ' + + ', + $view->render() + ); + + // Without using the data parameter the rendering result is the same as above. + $view->setTemplateSource( + ' + + Label +

    Title

    Text

    +
    + ' + ); + + $this->assertXmlStringEqualsXmlString( + ' + + ', + $view->render() + ); + } +}