RelationTest::seederMustNotHaveEmptyValues()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.3888
c 0
b 0
f 0
cc 5
nc 5
nop 0
1
<?php
2
namespace TildBJ\Seeder\Tests\Functional\Seeder;
3
4
/***************************************************************
5
 *
6
 *  Copyright notice
7
 *
8
 *  (c) 2016 Dennis Römmich <[email protected]>
9
 *
10
 *  All rights reserved
11
 *
12
 *  This script is part of the TYPO3 project. The TYPO3 project is
13
 *  free software; you can redistribute it and/or modify
14
 *  it under the terms of the GNU General Public License as published by
15
 *  the Free Software Foundation; either version 3 of the License, or
16
 *  (at your option) any later version.
17
 *
18
 *  The GNU General Public License can be found at
19
 *  http://www.gnu.org/copyleft/gpl.html.
20
 *
21
 *  This script is distributed in the hope that it will be useful,
22
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
 *  GNU General Public License for more details.
25
 *
26
 *  This copyright notice MUST APPEAR in all copies of the script!
27
 ***************************************************************/
28
use TildBJ\Seeder\Collection\SeedCollection;
29
use TildBJ\Seeder\Factory\SeederFactory;
30
use TildBJ\Seeder\Faker;
31
use Nimut\TestingFramework\TestCase\UnitTestCase;
32
use TYPO3\CMS\Core\Utility\GeneralUtility;
33
34
/**
35
 * This Test checks if seeder is able to generate relations
36
 * with the given tca informations
37
 *
38
 * @author Dennis Römmich <[email protected]>
39
 */
40
class RelationTest extends UnitTestCase
41
{
42
    /**
43
     * factory
44
     *
45
     * @var SeederFactory $factory
46
     */
47
    protected $factory = null;
48
49
    protected $faker;
50
51
    public function setUp()
52
    {
53
        $GLOBALS['TCA']['fe_users']['columns'] = unserialize('a:27:{s:8:"username";a:2:{s:5:"label";s:79:"LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:fe_users.username";s:6:"config";a:5:{s:4:"type";s:5:"input";s:4:"size";s:2:"20";s:3:"max";s:3:"255";s:4:"eval";s:39:"nospace,trim,lower,uniqueInPid,required";s:12:"autocomplete";b:0;}}s:8:"password";a:2:{s:5:"label";s:79:"LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:fe_users.password";s:6:"config";a:6:{s:4:"type";s:5:"input";s:4:"size";s:2:"10";s:3:"max";i:100;s:4:"eval";s:77:"trim,required,TYPO3\CMS\Saltedpasswords\Evaluation\FrontendEvaluator,password";s:12:"autocomplete";b:0;s:10:"renderType";s:8:"rsaInput";}}s:9:"usergroup";a:2:{s:5:"label";s:80:"LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:fe_users.usergroup";s:6:"config";a:8:{s:4:"type";s:6:"select";s:10:"renderType";s:24:"selectMultipleSideBySide";s:13:"foreign_table";s:9:"fe_groups";s:19:"foreign_table_where";s:24:"ORDER BY fe_groups.title";s:32:"enableMultiSelectFilterTextfield";b:1;s:4:"size";s:1:"6";s:8:"minitems";s:1:"1";s:8:"maxitems";s:2:"50";}}s:12:"lockToDomain";a:3:{s:7:"exclude";i:1;s:5:"label";s:83:"LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:fe_users.lockToDomain";s:6:"config";a:5:{s:4:"type";s:5:"input";s:4:"size";s:2:"20";s:4:"eval";s:4:"trim";s:3:"max";s:2:"50";s:7:"softref";s:10:"substitute";}}s:4:"name";a:3:{s:7:"exclude";i:1;s:5:"label";s:43:"LLL:EXT:lang/locallang_general.xlf:LGL.name";s:6:"config";a:4:{s:4:"type";s:5:"input";s:4:"size";s:2:"40";s:4:"eval";s:4:"trim";s:3:"max";s:2:"80";}}s:10:"first_name";a:3:{s:7:"exclude";i:1;s:5:"label";s:49:"LLL:EXT:lang/locallang_general.xlf:LGL.first_name";s:6:"config";a:4:{s:4:"type";s:5:"input";s:4:"size";s:2:"25";s:4:"eval";s:4:"trim";s:3:"max";s:2:"50";}}s:11:"middle_name";a:3:{s:7:"exclude";i:1;s:5:"label";s:50:"LLL:EXT:lang/locallang_general.xlf:LGL.middle_name";s:6:"config";a:4:{s:4:"type";s:5:"input";s:4:"size";s:2:"25";s:4:"eval";s:4:"trim";s:3:"max";s:2:"50";}}s:9:"last_name";a:3:{s:7:"exclude";i:1;s:5:"label";s:48:"LLL:EXT:lang/locallang_general.xlf:LGL.last_name";s:6:"config";a:4:{s:4:"type";s:5:"input";s:4:"size";s:2:"25";s:4:"eval";s:4:"trim";s:3:"max";s:2:"50";}}s:7:"address";a:3:{s:7:"exclude";i:1;s:5:"label";s:46:"LLL:EXT:lang/locallang_general.xlf:LGL.address";s:6:"config";a:3:{s:4:"type";s:4:"text";s:4:"cols";s:2:"20";s:4:"rows";s:1:"3";}}s:9:"telephone";a:3:{s:7:"exclude";i:1;s:5:"label";s:44:"LLL:EXT:lang/locallang_general.xlf:LGL.phone";s:6:"config";a:4:{s:4:"type";s:5:"input";s:4:"eval";s:4:"trim";s:4:"size";s:2:"20";s:3:"max";s:2:"20";}}s:3:"fax";a:3:{s:7:"exclude";i:1;s:5:"label";s:42:"LLL:EXT:lang/locallang_general.xlf:LGL.fax";s:6:"config";a:4:{s:4:"type";s:5:"input";s:4:"size";s:2:"20";s:4:"eval";s:4:"trim";s:3:"max";s:2:"20";}}s:5:"email";a:3:{s:7:"exclude";i:1;s:5:"label";s:44:"LLL:EXT:lang/locallang_general.xlf:LGL.email";s:6:"config";a:4:{s:4:"type";s:5:"input";s:4:"size";s:2:"20";s:4:"eval";s:4:"trim";s:3:"max";s:3:"255";}}s:5:"title";a:3:{s:7:"exclude";i:1;s:5:"label";s:51:"LLL:EXT:lang/locallang_general.xlf:LGL.title_person";s:6:"config";a:4:{s:4:"type";s:5:"input";s:4:"size";s:2:"20";s:4:"eval";s:4:"trim";s:3:"max";s:2:"40";}}s:3:"zip";a:3:{s:7:"exclude";i:1;s:5:"label";s:42:"LLL:EXT:lang/locallang_general.xlf:LGL.zip";s:6:"config";a:4:{s:4:"type";s:5:"input";s:4:"eval";s:4:"trim";s:4:"size";s:2:"10";s:3:"max";s:2:"10";}}s:4:"city";a:3:{s:7:"exclude";i:1;s:5:"label";s:43:"LLL:EXT:lang/locallang_general.xlf:LGL.city";s:6:"config";a:4:{s:4:"type";s:5:"input";s:4:"size";s:2:"20";s:4:"eval";s:4:"trim";s:3:"max";s:2:"50";}}s:7:"country";a:3:{s:7:"exclude";i:1;s:5:"label";s:46:"LLL:EXT:lang/locallang_general.xlf:LGL.country";s:6:"config";a:4:{s:4:"type";s:5:"input";s:4:"size";s:2:"20";s:4:"eval";s:4:"trim";s:3:"max";s:2:"40";}}s:3:"www";a:3:{s:7:"exclude";i:1;s:5:"label";s:42:"LLL:EXT:lang/locallang_general.xlf:LGL.www";s:6:"config";a:4:{s:4:"type";s:5:"input";s:4:"eval";s:4:"trim";s:4:"size";s:2:"20";s:3:"max";s:2:"80";}}s:7:"company";a:3:{s:7:"exclude";i:1;s:5:"label";s:46:"LLL:EXT:lang/locallang_general.xlf:LGL.company";s:6:"config";a:4:{s:4:"type";s:5:"input";s:4:"eval";s:4:"trim";s:4:"size";s:2:"20";s:3:"max";s:2:"80";}}s:5:"image";a:3:{s:7:"exclude";i:1;s:5:"label";s:44:"LLL:EXT:lang/locallang_general.xlf:LGL.image";s:6:"config";a:8:{s:4:"type";s:5:"group";s:13:"internal_type";s:4:"file";s:7:"allowed";s:48:"gif,jpg,jpeg,tif,tiff,bmp,pcx,tga,png,pdf,ai,svg";s:12:"uploadfolder";s:12:"uploads/pics";s:11:"show_thumbs";s:1:"1";s:4:"size";s:1:"3";s:8:"maxitems";s:1:"6";s:8:"minitems";s:1:"0";}}s:7:"disable";a:3:{s:7:"exclude";i:1;s:5:"label";s:46:"LLL:EXT:lang/locallang_general.xlf:LGL.disable";s:6:"config";a:1:{s:4:"type";s:5:"check";}}s:9:"starttime";a:3:{s:7:"exclude";i:1;s:5:"label";s:48:"LLL:EXT:lang/locallang_general.xlf:LGL.starttime";s:6:"config";a:4:{s:4:"type";s:5:"input";s:4:"size";s:2:"13";s:4:"eval";s:8:"datetime";s:7:"default";s:1:"0";}}s:7:"endtime";a:3:{s:7:"exclude";i:1;s:5:"label";s:46:"LLL:EXT:lang/locallang_general.xlf:LGL.endtime";s:6:"config";a:5:{s:4:"type";s:5:"input";s:4:"size";s:2:"13";s:4:"eval";s:8:"datetime";s:7:"default";s:1:"0";s:5:"range";a:1:{s:5:"upper";i:1609369200;}}}s:8:"TSconfig";a:4:{s:7:"exclude";i:1;s:5:"label";s:9:"TSconfig:";s:6:"config";a:4:{s:4:"type";s:4:"text";s:4:"cols";s:2:"40";s:4:"rows";s:2:"10";s:7:"softref";s:8:"TSconfig";}s:13:"defaultExtras";s:23:"fixed-font : enable-tab";}s:9:"lastlogin";a:3:{s:7:"exclude";i:1;s:5:"label";s:48:"LLL:EXT:lang/locallang_general.xlf:LGL.lastlogin";s:6:"config";a:5:{s:4:"type";s:5:"input";s:8:"readOnly";s:1:"1";s:4:"size";s:2:"12";s:4:"eval";s:8:"datetime";s:7:"default";i:0;}}s:15:"tx_extbase_type";a:3:{s:7:"exclude";i:1;s:5:"label";s:84:"LLL:EXT:extbase/Resources/Private/Language/locallang_db.xlf:fe_users.tx_extbase_type";s:6:"config";a:6:{s:4:"type";s:6:"select";s:10:"renderType";s:12:"selectSingle";s:5:"items";a:2:{i:0;a:2:{i:0;s:86:"LLL:EXT:extbase/Resources/Private/Language/locallang_db.xlf:fe_users.tx_extbase_type.0";i:1;s:1:"0";}i:1;a:2:{i:0;s:121:"LLL:EXT:extbase/Resources/Private/Language/locallang_db.xlf:fe_users.tx_extbase_type.Tx_Extbase_Domain_Model_FrontendUser";i:1;s:36:"Tx_Extbase_Domain_Model_FrontendUser";}}s:4:"size";i:1;s:8:"maxitems";i:1;s:7:"default";s:1:"0";}}s:19:"felogin_redirectPid";a:3:{s:7:"exclude";i:1;s:5:"label";s:75:"LLL:EXT:felogin/Resources/Private/Language/Database.xlf:felogin_redirectPid";s:6:"config";a:7:{s:4:"type";s:5:"group";s:13:"internal_type";s:2:"db";s:7:"allowed";s:5:"pages";s:4:"size";i:1;s:8:"minitems";i:0;s:8:"maxitems";i:1;s:7:"wizards";a:1:{s:7:"suggest";a:1:{s:4:"type";s:7:"suggest";}}}}s:18:"felogin_forgotHash";a:3:{s:7:"exclude";i:1;s:5:"label";s:74:"LLL:EXT:felogin/Resources/Private/Language/Database.xlf:felogin_forgotHash";s:6:"config";a:1:{s:4:"type";s:11:"passthrough";}}}');
54
        $GLOBALS['TCA']['fe_groups']['columns'] = unserialize('a:8:{s:6:"hidden";a:3:{s:5:"label";s:46:"LLL:EXT:lang/locallang_general.xlf:LGL.disable";s:7:"exclude";i:1;s:6:"config";a:2:{s:4:"type";s:5:"check";s:7:"default";s:1:"0";}}s:5:"title";a:2:{s:5:"label";s:77:"LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:fe_groups.title";s:6:"config";a:4:{s:4:"type";s:5:"input";s:4:"size";s:2:"20";s:3:"max";s:2:"50";s:4:"eval";s:13:"trim,required";}}s:8:"subgroup";a:3:{s:7:"exclude";i:1;s:5:"label";s:80:"LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:fe_groups.subgroup";s:6:"config";a:9:{s:4:"type";s:6:"select";s:10:"renderType";s:24:"selectMultipleSideBySide";s:13:"foreign_table";s:9:"fe_groups";s:19:"foreign_table_where";s:87:"AND NOT(fe_groups.uid = ###THIS_UID###) AND fe_groups.hidden=0 ORDER BY fe_groups.title";s:32:"enableMultiSelectFilterTextfield";b:1;s:4:"size";i:6;s:11:"autoSizeMax";i:10;s:8:"minitems";i:0;s:8:"maxitems";i:20;}}s:12:"lockToDomain";a:3:{s:7:"exclude";i:1;s:5:"label";s:84:"LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:fe_groups.lockToDomain";s:6:"config";a:4:{s:4:"type";s:5:"input";s:4:"size";s:2:"20";s:4:"eval";s:4:"trim";s:3:"max";s:2:"50";}}s:11:"description";a:2:{s:5:"label";s:50:"LLL:EXT:lang/locallang_general.xlf:LGL.description";s:6:"config";a:3:{s:4:"type";s:4:"text";s:4:"rows";i:5;s:4:"cols";i:48;}}s:8:"TSconfig";a:4:{s:7:"exclude";i:1;s:5:"label";s:9:"TSconfig:";s:6:"config";a:4:{s:4:"type";s:4:"text";s:4:"cols";s:2:"40";s:4:"rows";s:2:"10";s:7:"softref";s:8:"TSconfig";}s:13:"defaultExtras";s:23:"fixed-font : enable-tab";}s:15:"tx_extbase_type";a:3:{s:7:"exclude";i:1;s:5:"label";s:85:"LLL:EXT:extbase/Resources/Private/Language/locallang_db.xlf:fe_groups.tx_extbase_type";s:6:"config";a:6:{s:4:"type";s:6:"select";s:10:"renderType";s:12:"selectSingle";s:5:"items";a:2:{i:0;a:2:{i:0;s:87:"LLL:EXT:extbase/Resources/Private/Language/locallang_db.xlf:fe_groups.tx_extbase_type.0";i:1;s:1:"0";}i:1;a:2:{i:0;s:127:"LLL:EXT:extbase/Resources/Private/Language/locallang_db.xlf:fe_groups.tx_extbase_type.Tx_Extbase_Domain_Model_FrontendUserGroup";i:1;s:41:"Tx_Extbase_Domain_Model_FrontendUserGroup";}}s:4:"size";i:1;s:8:"maxitems";i:1;s:7:"default";s:1:"0";}}s:19:"felogin_redirectPid";a:3:{s:7:"exclude";i:1;s:5:"label";s:75:"LLL:EXT:felogin/Resources/Private/Language/Database.xlf:felogin_redirectPid";s:6:"config";a:7:{s:4:"type";s:5:"group";s:13:"internal_type";s:2:"db";s:7:"allowed";s:5:"pages";s:4:"size";i:1;s:8:"minitems";i:0;s:8:"maxitems";i:1;s:7:"wizards";a:1:{s:7:"suggest";a:1:{s:4:"type";s:7:"suggest";}}}}}');
55
56
        $faker = $this->createMock(Faker::class);
57
        $faker->expects($this->any())->method('get')->willReturn('testData');
58
59
        $this->factory = GeneralUtility::makeInstance(SeederFactory::class, $faker);
60
    }
61
62
    /**
63
     * @test
64
     */
65
    public function seedCollectionContainsTwoUsers()
66
    {
67
        /** @var User $userSeed */
68
        $userSeed = GeneralUtility::makeInstance(User::class);
69
        $userSeed->run();
70
        $seedCollection = GeneralUtility::makeInstance(SeedCollection::class);
71
72
        $feUsers = $seedCollection->toArray()['fe_users'];
73
        $this->assertSame([
74
            0 => 'NEW1',
75
            1 => 'NEW2',
76
        ], array_keys($feUsers));
77
    }
78
79
    /**
80
     * @test
81
     */
82 View Code Duplication
    public function seedCollectionContainsTwoGroups()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
83
    {
84
        /** @var User $userSeed */
85
        $userSeed = GeneralUtility::makeInstance(User::class);
86
        $userSeed->run();
87
        $seedCollection = GeneralUtility::makeInstance(SeedCollection::class);
88
89
        $groups = [];
90
        foreach ($seedCollection->toArray()['fe_groups'] as $key => $group) {
91
            if ($group['title'] === 'Group') {
92
                $groups[$key] = $group;
93
            }
94
        }
95
        $this->assertSame([
96
            0 => 'NEW3',
97
            1 => 'NEW4',
98
        ], array_keys($groups));
99
    }
100
101
    /**
102
     * @test
103
     */
104 View Code Duplication
    public function seedCollectionContainsTwoSubGroups()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
105
    {
106
        /** @var User $userSeed */
107
        $userSeed = GeneralUtility::makeInstance(User::class);
108
        $userSeed->run();
109
        $seedCollection = GeneralUtility::makeInstance(SeedCollection::class);
110
111
        $groups = [];
112
        foreach ($seedCollection->toArray()['fe_groups'] as $key => $group) {
113
            if ($group['title'] === 'SubGroup') {
114
                $groups[$key] = $group;
115
            }
116
        }
117
        $this->assertSame([
118
            0 => 'NEW5',
119
            1 => 'NEW6',
120
            2 => 'NEW7',
121
            3 => 'NEW8',
122
        ], array_keys($groups));
123
    }
124
125
    /**
126
     * @test
127
     */
128
    public function userHasRelationToTwoGroups()
129
    {
130
        /** @var User $userSeed */
131
        $userSeed = GeneralUtility::makeInstance(User::class);
132
        $userSeed->run();
133
        $seedCollection = GeneralUtility::makeInstance(SeedCollection::class);
134
135
        $users = [];
136
        foreach ($seedCollection->toArray()['fe_users'] as $key => $user) {
137
            $users[$key] = $user['usergroup'];
138
        }
139
        $this->assertSame([
140
            0 => 'NEW3,NEW4',
141
            1 => 'NEW3,NEW4',
142
        ], array_values($users));
143
    }
144
145
    /**
146
     * @test
147
     */
148 View Code Duplication
    public function seedCollectionContainsFourSubGroups()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
149
    {
150
        /** @var User $userSeed */
151
        $userSeed = GeneralUtility::makeInstance(User::class);
152
        $userSeed->run();
153
        $seedCollection = GeneralUtility::makeInstance(SeedCollection::class);
154
155
        $groups = [];
156
        foreach ($seedCollection->toArray()['fe_groups'] as $key => $group) {
157
            if ($group['title'] === 'SubGroup') {
158
                $groups[$key] = $group;
159
            }
160
        }
161
        $this->assertSame([
162
            0 => 'NEW5',
163
            1 => 'NEW6',
164
            2 => 'NEW7',
165
            3 => 'NEW8',
166
        ], array_keys($groups));
167
    }
168
169
    /**
170
     * @test
171
     */
172 View Code Duplication
    public function eachGroupHasTwoDifferentSubGroups()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
173
    {
174
        /** @var User $userSeed */
175
        $userSeed = GeneralUtility::makeInstance(User::class);
176
        $userSeed->run();
177
        $seedCollection = GeneralUtility::makeInstance(SeedCollection::class);
178
179
        $groups = [];
180
        foreach ($seedCollection->toArray()['fe_groups'] as $key => $group) {
181
            if ($group['title'] === 'Group') {
182
                $groups[$key] = $group['subgroup'];
183
            }
184
        }
185
        $this->assertSame([
186
            'NEW3' => 'NEW5,NEW6',
187
            'NEW4' => 'NEW7,NEW8',
188
        ], $groups);
189
    }
190
191
    /**
192
     * When the seeder has empty values it can cause errors when inserting data
193
     *
194
     * @test
195
     */
196
    public function seederMustNotHaveEmptyValues()
197
    {
198
        /** @var User $userSeed */
199
        $userSeed = GeneralUtility::makeInstance(User::class);
200
        $userSeed->run();
201
        $seedCollection = GeneralUtility::makeInstance(SeedCollection::class);
202
203
        foreach ($seedCollection->toArray() as $dataArray) {
204
            foreach ($dataArray as $data) {
205
                foreach ($data as $key => $value) {
206
                    if (!$value) {
207
                        $this->assertNotNull($value, 'Value for ' . $key . ' is null!!!');
208
                    }
209
                }
210
            }
211
        }
212
    }
213
214
    public function tearDown()
215
    {
216
        unset($GLOBALS['TCA']);
217
        $seedCollection = GeneralUtility::makeInstance(SeedCollection::class);
218
        $seedCollection->clear();
219
    }
220
}
221