tca-group-test.patch

Robert Vock, 2019-04-14 13:40

Download (5.7 KB)

View differences:

typo3/sysext/backend/Tests/Functional/Form/FormDataProvider/Fixtures/DataSet/TestTcaGroup.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<dataset>
3
    <pages>
4
        <uid>1</uid>
5
        <pid>1</pid>
6
        <title>visible</title>
7
        <deleted>0</deleted>
8
    </pages>
9
    <pages>
10
        <uid>2</uid>
11
        <pid>1</pid>
12
        <title>deleted</title>
13
        <deleted>1</deleted>
14
    </pages>
15
    <pages>
16
        <uid>3</uid>
17
        <pid>1</pid>
18
        <title>hidden</title>
19
        <hidden>1</hidden>
20
    </pages>
21
    <pages>
22
        <uid>4</uid>
23
        <pid>1</pid>
24
        <title>expired</title>
25
        <endtime>1262300400</endtime>
26
    </pages>
27
    <pages>
28
        <uid>5</uid>
29
        <pid>-1</pid>
30
        <title>deletedInWorkspace</title>
31
        <t3_origuid>1</t3_origuid>
32
        <t3ver_oid>1</t3ver_oid>
33
        <t3ver_wsid>1</t3ver_wsid>
34
        <t3ver_state>2</t3ver_state>
35
    </pages>
36
</dataset>
typo3/sysext/backend/Tests/Functional/Form/FormDataProvider/TcaGroupTest.php
1
<?php
2
declare(strict_types = 1);
3

  
4
namespace TYPO3\CMS\Core\Tests\Functional\Database;
5

  
6
/*
7
 * This file is part of the TYPO3 CMS project.
8
 *
9
 * It is free software; you can redistribute it and/or modify it under
10
 * the terms of the GNU General Public License, either version 2
11
 * of the License, or any later version.
12
 *
13
 * For the full copyright and license information, please read the
14
 * LICENSE.txt file that was distributed with this source code.
15
 *
16
 * The TYPO3 project - inspiring people to share!
17
 */
18

  
19
use TYPO3\CMS\Backend\Clipboard\Clipboard;
20
use TYPO3\CMS\Backend\Form\FormDataProvider\TcaGroup;
21
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
22
use TYPO3\CMS\Core\Utility\GeneralUtility;
23
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
24

  
25
/**
26
 * Test case
27
 */
28
class TcaGroupTest extends FunctionalTestCase
29
{
30
    protected $coreExtensionsToLoad = ['workspaces'];
31

  
32
    /**
33
     * This test checks if TcaGroup respects deleted elements
34
     *
35
     * @test
36
     */
37
    public function respectsDeletedElements()
38
    {
39
        $this->importDataSet(__DIR__ . '/Fixtures/DataSet/TestTcaGroup.xml');
40

  
41
        $aFieldConfig = [
42
            'type' => 'group',
43
            'internal_type' => 'db',
44
            'allowed' => 'pages',
45
            'maxitems' => 99999,
46
        ];
47
        $input = [
48
            'tableName' => 'aTable',
49
            'databaseRow' => [
50
                'uid' => 42,
51
                'aField' => '1,2,3,4',
52
            ],
53
            'processedTca' => [
54
                'columns' => [
55
                    'aField' => [
56
                        'config' => $aFieldConfig,
57
                    ],
58
                ],
59
            ],
60
        ];
61

  
62
        $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
63
        $GLOBALS['BE_USER'] = $backendUserProphecy->reveal();
64

  
65
        $clipboardProphecy = $this->prophesize(Clipboard::class);
66
        GeneralUtility::addInstance(Clipboard::class, $clipboardProphecy->reveal());
67
        $clipboardProphecy->initializeClipboard()->shouldBeCalled();
68
        $clipboardProphecy->elFromTable('pages')->shouldBeCalled()->willReturn([]);
69

  
70
        $result = (new TcaGroup)->addData($input);
71
        static::assertIsArray($result['databaseRow']['aField'], 'TcaGroup did not load items');
72

  
73
        $loadedUids = array_column($result['databaseRow']['aField'], 'uid');
74
        static::assertEquals($loadedUids, [1, 3, 4], 'TcaGroup did not load the correct items');
75
    }
76

  
77
    /**
78
     * This test checks if TcaGroup respects deleted elements in a workspace
79
     *
80
     * @test
81
     */
82
    public function respectsDeletedElementsInWorkspace()
83
    {
84
        $this->importDataSet(__DIR__ . '/Fixtures/DataSet/TestTcaGroup.xml');
85

  
86
        $aFieldConfig = [
87
            'type' => 'group',
88
            'internal_type' => 'db',
89
            'allowed' => 'pages',
90
            'maxitems' => 99999,
91
        ];
92
        $input = [
93
            'tableName' => 'aTable',
94
            'databaseRow' => [
95
                'uid' => 42,
96
                'aField' => '1,2,3,4',
97
            ],
98
            'processedTca' => [
99
                'columns' => [
100
                    'aField' => [
101
                        'config' => $aFieldConfig,
102
                    ],
103
                ],
104
            ],
105
        ];
106

  
107
        $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
108
        $backendUserProphecy->workspace = 1;
109
        $GLOBALS['BE_USER'] = $backendUserProphecy->reveal();
110

  
111
        $clipboardProphecy = $this->prophesize(Clipboard::class);
112
        GeneralUtility::addInstance(Clipboard::class, $clipboardProphecy->reveal());
113
        $clipboardProphecy->initializeClipboard()->shouldBeCalled();
114
        $clipboardProphecy->elFromTable('pages')->shouldBeCalled()->willReturn([]);
115

  
116
        $result = (new TcaGroup)->addData($input);
117
        static::assertIsArray($result['databaseRow']['aField'], 'TcaGroup did not load items in a workspace');
118

  
119
        $loadedUids = array_column($result['databaseRow']['aField'], 'uid');
120
        static::assertEquals($loadedUids, [3, 4], 'TcaGroup did not load the correct items in a workspace');
121
    }
122
}