-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MAINTENANCE] Add ViewHelper functional tests instead of unit tests. (#…
…902) Co-authored-by: Oliver Stöhr <[email protected]>
- Loading branch information
1 parent
5310a15
commit 2bcf180
Showing
3 changed files
with
199 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
/** | ||
* (c) Kitodo. Key to digital objects e.V. <[email protected]> | ||
* | ||
* 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( | ||
'<html xmlns:kitodo="http://typo3.org/ns/Kitodo/Dlf/ViewHelpers"> | ||
<kitodo:jsFooter inlineCode="$(document).ready(function() {});" /> | ||
</html>' | ||
); | ||
|
||
$view->render(); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
Tests/Functional/ViewHelpers/MetadataWrapVariableViewHelperTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
/** | ||
* (c) Kitodo. Key to digital objects e.V. <[email protected]> | ||
* | ||
* 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 = <article class="shlb-metadata-text-item metadata-title">|</article> | ||
key.wrap = <label>|</label> | ||
value.required = 1 | ||
value.wrap = <li>|</li>' | ||
] | ||
); | ||
$view->setTemplateSource( | ||
'<html xmlns:kitodo="http://typo3.org/ns/Kitodo/Dlf/ViewHelpers"> | ||
{configObject.wrap -> kitodo:metadataWrapVariable(name: \'metadataWrap\')} | ||
</html>' | ||
); | ||
$view->render(); | ||
|
||
$this->assertEquals( | ||
[ | ||
'key' => ['wrap' => '<label>|</label>'], | ||
'value' => ['required' => 1, 'wrap' => '<li>|</li>'], | ||
'all' => ['wrap' => '<article class="shlb-metadata-text-item metadata-title">|</article>'] | ||
], | ||
$view->getRenderingContext()->getVariableProvider()->get('metadataWrap') | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
/** | ||
* (c) Kitodo. Key to digital objects e.V. <[email protected]> | ||
* | ||
* 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' => '<label>|</label>'], | ||
'value' => ['required' => 1, 'wrap' => '<li>|</li>'], | ||
'all' => ['wrap' => '<article class="shlb-metadata-text-item metadata-title">|</article>'] | ||
] | ||
); | ||
|
||
// 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( | ||
'<html xmlns:kitodo="http://typo3.org/ns/Kitodo/Dlf/ViewHelpers"> | ||
<kitodo:stdWrap wrap="{metadataWrap.all}" data="{metaCObjData.0}"> | ||
<kitodo:stdWrap wrap="{metadataWrap.key}" data="{metaCObjData.0}">Label</kitodo:stdWrap> | ||
<h2>Title</h2><p>Text</p> | ||
</kitodo:stdWrap> | ||
</html>' | ||
); | ||
|
||
$this->assertXmlStringEqualsXmlString( | ||
'<html xmlns:kitodo="http://typo3.org/ns/Kitodo/Dlf/ViewHelpers"> | ||
<article class="shlb-metadata-text-item metadata-title"> | ||
<label>Label</label> | ||
<h2>Title</h2><p>Text</p> | ||
</article> | ||
</html>', | ||
$view->render() | ||
); | ||
|
||
// Without using the data parameter the rendering result is the same as above. | ||
$view->setTemplateSource( | ||
'<html xmlns:kitodo="http://typo3.org/ns/Kitodo/Dlf/ViewHelpers"> | ||
<kitodo:stdWrap wrap="{metadataWrap.all}"> | ||
<kitodo:stdWrap wrap="{metadataWrap.key}">Label</kitodo:stdWrap> | ||
<h2>Title</h2><p>Text</p> | ||
</kitodo:stdWrap> | ||
</html>' | ||
); | ||
|
||
$this->assertXmlStringEqualsXmlString( | ||
'<html xmlns:kitodo="http://typo3.org/ns/Kitodo/Dlf/ViewHelpers"> | ||
<article class="shlb-metadata-text-item metadata-title"> | ||
<label>Label</label> | ||
<h2>Title</h2><p>Text</p> | ||
</article> | ||
</html>', | ||
$view->render() | ||
); | ||
} | ||
} |