Passed
Pull Request — master (#123)
by
unknown
04:10
created

StdWrapViewHelperTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 39
c 2
b 0
f 0
dl 0
loc 63
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A renderWithStdWrap() 0 53 1
1
<?php
2
3
/**
4
 * (c) Kitodo. Key to digital objects e.V. <[email protected]>
5
 *
6
 * This file is part of the Kitodo and TYPO3 projects.
7
 *
8
 * @license GNU General Public License version 3 or later.
9
 * For the full copyright and license information, please read the
10
 * LICENSE.txt file that was distributed with this source code.
11
 */
12
13
namespace Kitodo\Dlf\Tests\Unit\ViewHelpers;
14
15
use Kitodo\Dlf\Tests\Functional\FunctionalTestCase;
16
use TYPO3\CMS\Fluid\View\StandaloneView;
17
18
/**
19
 * @covers StdWrapViewHelper
20
 */
21
class StdWrapViewHelperTest extends FunctionalTestCase
22
{
23
    /**
24
     * @var bool Speed up this test case, it needs no database
25
     */
26
    protected $initializeDatabase = false;
27
28
    /**
29
     * @test
30
     */
31
    public function renderWithStdWrap(): void
32
    {
33
        $view = new StandaloneView();
34
        $view->assign(
35
            'metadataWrap',
36
            [
37
                'key' => ['wrap' => '<label>|</label>'],
38
                'value' => ['required' => 1, 'wrap' => '<li>|</li>'],
39
                'all' => ['wrap' => '<article class="shlb-metadata-text-item metadata-title">|</article>']
40
            ]
41
        );
42
43
        // A fully filled array with correct values does not make any difference. The rendering result
44
        // is not been influenced by the viewhelpers data parameter.
45
        $view->assign('metaSectionCObj', [0 => ['tilte' => 'A test title']]);
46
47
        $view->setTemplateSource(
48
            '<html xmlns:kitodo="http://typo3.org/ns/Kitodo/Dlf/ViewHelpers">
49
              <kitodo:stdWrap wrap="{metadataWrap.all}" data="{metaConfigObjectData.0}">
50
                <kitodo:stdWrap wrap="{metadataWrap.key}" data="{metaConfigObjectData.0}">Label</kitodo:stdWrap>
51
                    <h2>Title</h2><p>Text</p>
52
                </kitodo:stdWrap>
53
            </html>'
54
        );
55
56
        self::assertXmlStringEqualsXmlString(
57
            '<html xmlns:kitodo="http://typo3.org/ns/Kitodo/Dlf/ViewHelpers">
58
              <article class="shlb-metadata-text-item metadata-title">
59
                <label>Label</label>
60
                    <h2>Title</h2><p>Text</p>
61
                </article>
62
            </html>',
63
            $view->render()
64
        );
65
66
        // Without using the data parameter the rendering result is the same as above.
67
        $view->setTemplateSource(
68
            '<html xmlns:kitodo="http://typo3.org/ns/Kitodo/Dlf/ViewHelpers">
69
              <kitodo:stdWrap wrap="{metadataWrap.all}">
70
                <kitodo:stdWrap wrap="{metadataWrap.key}">Label</kitodo:stdWrap>
71
                    <h2>Title</h2><p>Text</p>
72
                </kitodo:stdWrap>
73
            </html>'
74
        );
75
76
        self::assertXmlStringEqualsXmlString(
77
            '<html xmlns:kitodo="http://typo3.org/ns/Kitodo/Dlf/ViewHelpers">
78
              <article class="shlb-metadata-text-item metadata-title">
79
                <label>Label</label>
80
                    <h2>Title</h2><p>Text</p>
81
                </article>
82
            </html>',
83
            $view->render()
84
        );
85
    }
86
}
87