Completed
Push — master ( 576a4c...bc864b )
by Dennis
01:49
created

SeedTest::seedCollectionContainsTwoGroups()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 12

Duplication

Lines 18
Ratio 100 %

Importance

Changes 0
Metric Value
dl 18
loc 18
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 12
nc 3
nop 0
1
<?php
2
namespace Dennis\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 Dennis\Seeder\Collection\SeedCollection;
29
use Dennis\Seeder\Factory\SeederFactory;
30
use Dennis\Seeder\Faker;
31
use TYPO3\CMS\Core\Tests\UnitTestCase;
32
use TYPO3\CMS\Core\Utility\GeneralUtility;
33
34
/**
35
 * Test case
36
 *
37
 * @author Dennis Römmich <[email protected]>
38
 */
39
class SeedTest extends UnitTestCase
0 ignored issues
show
Deprecated Code introduced by
The class TYPO3\CMS\Core\Tests\UnitTestCase has been deprecated with message: will be removed once TYPO3 9 LTS is released

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
40
{
41
    /**
42
     * factory
43
     *
44
     * @var SeederFactory $factory
45
     */
46
    protected $factory = null;
47
48
    protected $faker;
49
50
    public function setUp()
0 ignored issues
show
Coding Style introduced by
setUp uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
51
    {
52
        $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";}}}');
53
        $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";}}}}}');
54
55
        $faker = $this->getMock(Faker::class);
56
        $faker->expects($this->any())->method('get')->willReturn('testData');
57
58
        $this->factory = GeneralUtility::makeInstance(SeederFactory::class, $faker);
59
    }
60
61
    /**
62
     * @test
63
     */
64
    public function seedCollectionContainTwoUsers()
65
    {
66
        /** @var User $userSeed */
67
        $userSeed = GeneralUtility::makeInstance(User::class);
68
        $userSeed->run();
69
        $seedCollection = GeneralUtility::makeInstance(SeedCollection::class);
70
71
        $feUsers = $seedCollection->toArray()['fe_users'];
72
        $this->assertSame([
73
            0 => 'NEW1',
74
            1 => 'NEW2',
75
        ], array_keys($feUsers));
76
    }
77
78
    /**
79
     * @test
80
     */
81 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...
82
    {
83
        /** @var User $userSeed */
84
        $userSeed = GeneralUtility::makeInstance(User::class);
85
        $userSeed->run();
86
        $seedCollection = GeneralUtility::makeInstance(SeedCollection::class);
87
88
        $groups = [];
89
        foreach ($seedCollection->toArray()['fe_groups'] as $key => $group) {
90
            if ($group['title'] === 'Group') {
91
                $groups[$key] = $group;
92
            }
93
        }
94
        $this->assertSame([
95
            0 => 'NEW3',
96
            1 => 'NEW4',
97
        ], array_keys($groups));
98
    }
99
100
    /**
101
     * @test
102
     */
103 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...
104
    {
105
        /** @var User $userSeed */
106
        $userSeed = GeneralUtility::makeInstance(User::class);
107
        $userSeed->run();
108
        $seedCollection = GeneralUtility::makeInstance(SeedCollection::class);
109
110
        $groups = [];
111
        foreach ($seedCollection->toArray()['fe_groups'] as $key => $group) {
112
            if ($group['title'] === 'SubGroup') {
113
                $groups[$key] = $group;
114
            }
115
        }
116
        $this->assertSame([
117
            0 => 'NEW5',
118
            1 => 'NEW6',
119
        ], array_keys($groups));
120
    }
121
122
    /**
123
     * @test
124
     */
125 View Code Duplication
    public function userHasRelationToTwoGroups()
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...
126
    {
127
        /** @var User $userSeed */
128
        $userSeed = GeneralUtility::makeInstance(User::class);
129
        $userSeed->run();
130
        $seedCollection = GeneralUtility::makeInstance(SeedCollection::class);
131
132
        $users = [];
133
        foreach ($seedCollection->toArray()['fe_users'] as $key => $user) {
134
            $users[$key] = $user['usergroup'];
135
        }
136
        $this->assertSame([
137
            0 => 'NEW3,NEW4',
138
            1 => 'NEW3,NEW4',
139
        ], array_values($users));
140
    }
141
142
    /**
143
     * When the seeder has empty values it can cause errors when inserting data
144
     *
145
     * @test
146
     */
147
    public function seederMustNotHaveEmptyValues()
148
    {
149
        /** @var User $userSeed */
150
        $userSeed = GeneralUtility::makeInstance(User::class);
151
        $userSeed->run();
152
        $seedCollection = GeneralUtility::makeInstance(SeedCollection::class);
153
154
        foreach($seedCollection->toArray() as $dataArray) {
155
            foreach ($dataArray as $data) {
156
                foreach ($data as $key => $value) {
157
                    if (!$value) {
158
                        $this->assertNotNull($value, 'Value for ' . $key . ' is null!!!');
159
                    }
160
                }
161
            }
162
        }
163
    }
164
165
    public function tearDown()
166
    {
167
        $seedCollection = GeneralUtility::makeInstance(SeedCollection::class);
168
        $seedCollection->clear();
169
    }
170
}
171