Completed
Push — master ( b74cd0...088e4f )
by Dennis
11:47
created

tableConfigurationContainsArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 5
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
namespace Dennis\Seeder\Tests\Unit\Provider;
3
4
/***************************************************************
5
 *  Copyright notice
6
 *
7
 *  (c) 2016 Dennis Römmich <[email protected]>
8
 *
9
 *  All rights reserved
10
 *
11
 *  This script is part of the TYPO3 project. The TYPO3 project is
12
 *  free software; you can redistribute it and/or modify
13
 *  it under the terms of the GNU General Public License as published by
14
 *  the Free Software Foundation; either version 2 of the License, or
15
 *  (at your option) any later version.
16
 *
17
 *  The GNU General Public License can be found at
18
 *  http://www.gnu.org/copyleft/gpl.html.
19
 *
20
 *  This script is distributed in the hope that it will be useful,
21
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 *  GNU General Public License for more details.
24
 *
25
 *  This copyright notice MUST APPEAR in all copies of the script!
26
 ***************************************************************/
27
use Dennis\Seeder\Tests\Unit\AccessibleTraitForTest;
28
use Dennis\Seeder\Traits\Language;
29
use Dennis\Seeder\Provider\TableConfiguration;
30
use TYPO3\CMS\Core\Tests\UnitTestCase;
31
32
/**
33
 * Test case for class \Dennis\Seeder\Tests\Provider\TableConfigurationTest
34
 *
35
 * @author Dennis Römmich <[email protected]>
36
 */
37
class TableConfigurationTest 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...
38
{
39
    use Language, AccessibleTraitForTest;
40
41
    /**
42
     * subject
43
     *
44
     * @var TableConfiguration $subject
45
     */
46
    protected $subject;
47
48
    /**
49
     * TABLE
50
     */
51
    const TABLE = 'pages';
52
53
    /**
54
     * setUp
55
     *
56
     * @return void
57
     */
58
    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...
59
    {
60
        $GLOBALS['LANG'] = new \TYPO3\CMS\Lang\LanguageService();
61
        $GLOBALS['LANG']->init('de');
62
63
        $GLOBALS['TCA'] = [
64
            'pages' => [
65
                'ctrl' => [
66
                    'title' => 'LLL:EXT:lang/locallang_tca.xlf:pages'
67
                ],
68
                'columns' => [
69
                    'title' => [
70
                        'config' => [
71
                            'type' => 'array',
72
                            'size' => '50',
73
                            'max' => '255',
74
                            'eval' => 'trim,required',
75
                        ],
76
                    ],
77
                    'doctype' => [
78
                        'exclude' => 1,
79
                        'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.type',
80
                        'config' => [
81
                           'type' => 'select',
82
                           'renderType' => 'selectSingle',
83
                           'default' => '1'
84
                        ],
85
                    ],
86
                ],
87
            ],
88
            'fe_users' => [],
89
        ];
90
91
        $this->subject = new TableConfiguration('pages');
92
    }
93
94
    /**
95
     * tableConfigurationContainsArray
96
     *
97
     * @test
98
     */
99
    public function tableConfigurationContainsArray()
100
    {
101
        $tableConfiguration = $this->accessProtectedProperty($this->subject, 'tableConfiguration');
102
        $this->assertTrue(is_array($tableConfiguration));
103
    }
104
105
    /**
106
     * tablePropertyContainsString
107
     *
108
     * @test
109
     */
110
    public function tablePropertyContainsString()
111
    {
112
        $table = $this->accessProtectedProperty($this->subject, 'name');
113
        $this->assertSame(self::TABLE, $table);
114
    }
115
116
    /**
117
     * getNameReturnsTableName
118
     *
119
     * @test
120
     */
121
    public function getNameReturnsTableName()
122
    {
123
        $this->assertSame(self::TABLE, $this->subject->getName());
124
    }
125
126
    /**
127
     * getTitleReturnsTitleOfTable
128
     *
129
     * @test
130
     */
131
    public function getTitleReturnsTitleOfTable()
132
    {
133
        $this->assertSame('Page', $this->subject->getTitle());
134
    }
135
136
    /**
137
     * getColumnsReturnsArray
138
     *
139
     * @test
140
     */
141
    public function getColumnsReturnsArray()
142
    {
143
        $this->assertSame(['title', 'doctype'], $this->subject->getColumns());
144
    }
145
146
    /**
147
     * getColumnConfigurationThrowsExceptionWhenTableNotExist
148
     *
149
     * @test
150
     */
151
    public function getColumnConfigurationThrowsExceptionWhenTableNotExist()
152
    {
153
        $column = 'FooBar';
154
        $this->setExpectedException(
155
            'InvalidArgumentException',
156
            'Column ' . $column . ' does not exist for table ' . self::TABLE
157
        );
158
        $this->assertSame($this->getExpectedException(), $this->subject->getColumnConfiguration($column));
159
    }
160
161
    /**
162
     * getColumnConfigurationReturnsArray
163
     *
164
     * @test
165
     */
166
    public function getColumnConfigurationReturnsArray()
167
    {
168
        $expected = [
169
            'title' => [
170
                'type' => 'array',
171
                'size' => '50',
172
                'max' => '255',
173
                'eval' => 'trim,required',
174
            ],
175
        ];
176
        $this->assertSame($expected, $this->subject->getColumnConfiguration('title'));
177
    }
178
179
    /**
180
     * getAllTablesReturnsArray
181
     *
182
     * @test
183
     */
184
    public function getAllTablesReturnsArray()
185
    {
186
        $this->assertSame(['pages' => 'pages', 'fe_users' => 'fe_users'], $this->subject->getAllTables());
187
    }
188
}
189