Completed
Push — master ( 7f2d14...7fc8f2 )
by Fabien
02:11
created

additionalFieldBirthDayIsFormattedAsDate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
namespace Fab\Vidi\Tests\Unit\Tca;
3
4
/**
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
 * It is free software; you can redistribute it and/or modify it under
8
 * the terms of the GNU General Public License, either version 2
9
 * of the License, or any later version.
10
 *
11
 * For the full copyright and license information, please read the
12
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
 * The TYPO3 project - inspiring people to share!
15
 */
16
17
use Fab\Vidi\Formatter\Date;
18
use Fab\Vidi\Formatter\Datetime;
19
use Fab\Vidi\Tca\Tca;
20
21
/**
22
 * Test case for class \Fab\Vidi\Tca\GridService.
23
 */
24
class GridServiceTest extends AbstractServiceTest {
25
26
	/**
27
	 * @var \Fab\Vidi\Tca\GridService
28
	 */
29
	private $fixture;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
30
31
	public function setUp() {
32
		parent::setUp();
33
		$this->fixture = $this->getMock('Fab\Vidi\Tca\GridService', array('getModulePreferences'), array('tx_foo', Tca::TYPE_GRID));
34
35
		// Configure the ModulePreferences
36
		$mockModulePreferences = $this->getMock('Fab\Vidi\Module\ModulePreferences');
37
		$mockModulePreferences->expects($this->once())->method('get')->will($this->returnValue(array()));
38
		$this->fixture->expects($this->once())->method('getModulePreferences')->will($this->returnValue($mockModulePreferences));
39
40
		$GLOBALS['BE_USER'] = $this->getMock('TYPO3\CMS\Core\Authentication\BackendUserAuthentication', [], [], '', false);
41
		$GLOBALS['BE_USER']->expects($this->any())->method('isAdmin')->will($this->returnValue(true));
42
	}
43
44
	public function tearDown() {
45
		unset($this->fixture);
46
	}
47
48
	/**
49
	 * test
50
	 */
51
	#public function getLabelReturnNameAsValue() {
52
	#	$GLOBALS['LANG'] = $this->getMock('TYPO3\CMS\Lang\LanguageService', [], [], '', false);
53
	#	$GLOBALS['LANG']->expects($this->once())->method('sL')->will($this->returnValue('Name'));
54
    #
55
	#	$this->assertEquals('Name', $this->fixture->getLabel('name'));
56
	#}
57
58
	/**
59
	 * @test
60
	 */
61
	public function getFieldNamesReturnsNotEmpty() {
62
		$actual = $this->fixture->getFieldNames();
63
64
		$this->assertTrue(is_array($actual));
65
		$this->assertNotEmpty($actual);
66
		$this->assertTrue(in_array('username', $actual));
67
	}
68
69
	/**
70
	 * @test
71
	 */
72
	public function getColumnsReturnsAnNotEmptyArray() {
73
		$actual = $this->fixture->getFields();
74
		$this->assertTrue(is_array($actual));
75
		$this->assertNotEmpty($actual);
76
	}
77
78
	/**
79
	 * @test
80
	 */
81
	public function getFieldsReturnsGreaterThanNumberOfColumns() {
82
		$actual = $this->fixture->getFields();
83
		$this->assertGreaterThanOrEqual(count($actual), count($GLOBALS['TCA']['tx_foo']['columns']));
84
	}
85
86
	/**
87
	 * @test
88
	 */
89
	public function additionalFieldsAreHiddenByDefault() {
90
		$actual = $this->fixture->getFields();
91
		$this->assertFalse($actual['birthday']['visible']);
92
	}
93
94
	/**
95
	 * @test
96
	 */
97
	public function additionalFieldBirthDayIsFormattedAsDate() {
98
		$actual = $this->fixture->getFields();
99
		$this->assertEquals('Fab\Vidi\Formatter\Date', $actual['birthday']['format']);
100
	}
101
102
	/**
103
	 * @test
104
	 */
105
	public function additionalFieldStartTimeIsFormattedAsDateTime() {
106
		$actual = $this->fixture->getFields();
107
		$this->assertEquals('Fab\Vidi\Formatter\Datetime', $actual['starttime']['format']);
108
	}
109
110
	/**
111
	 * @test
112
	 */
113
	public function getConfigurationForColumnUsername() {
114
		$actual = $this->fixture->getField('username');
115
		$this->assertTrue(is_array($actual));
116
		$this->assertTrue(count($actual) > 0);
117
	}
118
119
	/**
120
	 * @test
121
	 */
122
	public function additionalColumnFirstNameShouldNotBeVisible() {
123
		$actual = $this->fixture->isVisible('first_name');
124
		$this->assertFalse($actual);
125
	}
126
127
	/**
128
	 * @test
129
	 */
130
	public function columnUsernameShouldBeSortableByDefault() {
131
		$this->assertTrue($this->fixture->isSortable('username'));
132
	}
133
134
	/**
135
	 * @test
136
	 */
137
	public function columnNumberShouldBeNotSortableByDefault() {
138
		$this->assertFalse($this->fixture->isSortable('usergroup'));
139
	}
140
141
	/**
142
	 * @test
143
	 */
144
	public function getExcludedFieldsReturnsArray() {
145
		$result = $this->fixture->getExcludedFields();
146
		$this->assertInternalType('array', $result);
147
	}
148
149
	/**
150
	 * @test
151
	 */
152
	public function getFieldsRemoveFieldMiddleNameFromResultSet() {
153
		$result = $this->fixture->getFields();
154
		$this->assertArrayNotHasKey('middle_name', $result);
155
	}
156
157
	/**
158
	 * @test
159
	 */
160
	public function columnUsernameShouldBeVisibleByDefault() {
161
		$this->assertTrue($this->fixture->isVisible('username'));
162
	}
163
164
	/**
165
	 * @test
166
	 */
167
	public function getConfigurationOfNotExistingColumnReturnsAnException() {
168
		$expected = [];
169
		$this->assertEquals($expected, $this->fixture->getRenderers('bar'));
170
	}
171
172
	/**
173
	 * @test
174
	 */
175
	public function getFieldsAndCheckWhetherItsPositionReturnsTheCorrectFieldName() {
176
		$fields = array_keys($this->fixture->getFields());
177
		for ($index = 0; $index < count($fields); $index++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
178
			$actual = $this->fixture->getFieldNameByPosition($index);
179
			$this->assertSame($fields[$index], $actual);
180
		}
181
	}
182
183
	/**
184
	 * @test
185
	 */
186
	public function canGetLabelKeyCodeForFakeFieldUserGroups() {
187
		$fieldName = 'usergroup';
188
		$this->assertEquals($GLOBALS['TCA']['tx_foo']['grid']['columns'][$fieldName]['label'], $this->fixture->getLabelKey($fieldName));
189
	}
190
191
}
192