Completed
Push — 7LTS_compatible ( 4a528e...8b7547 )
by Tomas Norre
02:51
created

VisibilityServiceTest   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 239
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 16
c 1
b 0
f 0
lcom 1
cbo 5
dl 0
loc 239
rs 10

14 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 3 1
A canGetSupportedTables() 0 10 2
B test_visibility() 0 28 1
A test_visibility_fixture_ce() 0 14 1
A test_visibility_fixture_page() 0 15 1
A test_visibility_fixture_news() 0 17 2
A _fixture_getLanguageOneWithDefaultFallback() 0 7 1
A _fixture_getLanguageThreeWithMultiFallback() 0 7 1
A _fixture_getLanguageFourWithElementFallback() 0 6 1
A _fixture_getElementWithDefaultVisibility() 0 14 1
A _fixture_getElementWithLangOneVisibility() 0 16 1
A _fixture_getFCEElementWithDefaultVisibility() 0 55 1
A _fixture_getPageElementWithDefaultVisibility() 0 14 1
A _fixture_getNewsElementWithDefaultVisibility() 0 14 1
1
<?php
2
3
namespace AOE\Languagevisibility\Tests\Unit\Services;
4
/***************************************************************
5
 * Copyright notice
6
 *
7
 * (c) 2007 AOE media ([email protected])
8
 * All rights reserved
9
 *
10
 * This script is part of the TYPO3 project. The TYPO3 project is
11
 * free software; you can redistribute it and/or modify
12
 * it under the terms of the GNU General Public License as published by
13
 * the Free Software Foundation; either version 2 of the License, or
14
 * (at your option) any later version.
15
 *
16
 * The GNU General Public License can be found at
17
 * http://www.gnu.org/copyleft/gpl.html.
18
 *
19
 * This script is distributed in the hope that it will be useful,
20
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 * GNU General Public License for more details.
23
 *
24
 * This copyright notice MUST APPEAR in all copies of the script!
25
 ***************************************************************/
26
use AOE\Languagevisibility\Dao\DaoCommonStub;
27
use AOE\Languagevisibility\ElementFactory;
28
use AOE\Languagevisibility\Language;
29
use AOE\Languagevisibility\PageElement;
30
use AOE\Languagevisibility\Services\VisibilityService;
31
use AOE\Languagevisibility\TtnewsElement;
32
33
/**
34
 * Test case for checking the PHPUnit 3.1.9
35
 *
36
 * WARNING: Never ever run a unit test like this on a live site!
37
 *
38
 * @author	Daniel Pötzinger
39
 */
40
class VisibilityServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
41
42
	public function setUp() {
43
		$this->markTestIncomplete('Needs refactoring');
44
	}
45
46
	/**
47
	 * @test
48
	 */
49
	public function canGetSupportedTables() {
50
		$expectedSupportedTables = array('pages', 'pages_language_overlay', 'tt_content', 'tt_news');
51
		$supportedTables = VisibilityService::getSupportedTables();
52
53
		$this->assertTrue(is_array($supportedTables));
54
55
		foreach ($expectedSupportedTables as $expectedSupportedTable) {
56
			$this->assertContains($expectedSupportedTable, $supportedTables);
57
		}
58
	}
59
60
	public function test_visibility() {
61
62
		// Create the language object fixture.
63
		$fixture = array('uid' => 1, 'tx_languagevisibility_fallbackorder' => '2' );
64
		$language1 = new Language();
65
		$language1->setData($fixture);
66
67
		$rep = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tx_languagevisibility_languagerepository');
68
		$deflanguage = $rep->getDefaultLanguage();
69
		//Create the element object fixture.
70
		$_table = 'tt_content';
71
		$_uid = 1;
72
		$visibility = array('0' => 'yes', '1' => 't', '2' => '' );
73
		$fixture = array('uid' => $_uid, 'tx_languagevisibility_visibility' => serialize($visibility) );
74
		$daostub = new DaoCommonStub();
75
		$daostub->stub_setRow($fixture, $_table);
76
77
		$factory = new ElementFactory($daostub);
78
		//get element from factory:
79
		$element = $factory->getElementForTable($_table, $_uid);
80
81
		//test
82
		$visibility = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tx_languagevisibility_visibilityService');
83
84
		// language 1 should be set local to "t"
85
		$this->assertEquals('t', $visibility->getVisibilitySetting($language1, $element), "setting t expected");
86
		$this->assertEquals(TRUE, $visibility->isVisible($deflanguage, $element), "default lang should be visible");
87
	}
88
89
	public function test_visibility_fixture_ce() {
90
91
		$language = $this->_fixture_getLanguageOneWithDefaultFallback();
92
		$element = $this->_fixture_getElementWithDefaultVisibility();
93
94
		//test
95
		$visibility = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tx_languagevisibility_visibilityService');
96
97
		// language 1 should be set local to "t"
98
		$this->assertEquals('-', $element->getLocalVisibilitySetting(1), "setting d expected");
99
		$this->assertEquals('f', $visibility->getVisibilitySetting($language, $element), "setting f expected (because default is used)");
100
		$this->assertEquals(TRUE, $visibility->isVisible($language, $element), "default lang should be visible");
101
		$this->assertEquals(0, $visibility->getOverlayLanguageIdForLanguageAndElement($language, $element), "default should be overlay");
102
	}
103
104
	public function test_visibility_fixture_page() {
105
106
		$language = $this->_fixture_getLanguageOneWithDefaultFallback();
107
		$element = $this->_fixture_getPageElementWithDefaultVisibility();
108
109
		//test
110
		$visibility = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tx_languagevisibility_visibilityService');
111
112
		// language 1 should be set local to "t"
113
		$this->assertTrue($element instanceof PageElement, 'factory return instance of wrong type');
114
		$this->assertEquals('-', $element->getLocalVisibilitySetting(1), "setting d expected");
115
		$this->assertEquals('f', $visibility->getVisibilitySetting($language, $element), "setting f expected (because default is used)");
116
		$this->assertEquals(TRUE, $visibility->isVisible($language, $element), "default lang should be visible");
117
		$this->assertEquals(0, $visibility->getOverlayLanguageIdForLanguageAndElement($language, $element), "default record should be overlay");
118
	}
119
120
	public function test_visibility_fixture_news() {
121
122
		if (!\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('tt_news')) {
123
			$this->markTestSkipped('Not relevant if "tt_news" is not installed');
124
		}
125
126
		$language = $this->_fixture_getLanguageOneWithDefaultFallback();
127
		$element = $this->_fixture_getNewsElementWithDefaultVisibility();
128
129
		$visibility = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tx_languagevisibility_visibilityService');
130
131
		$this->assertTrue($element instanceof TtnewsElement, 'factory returned instance of wrong type');
132
		$this->assertEquals('-', $element->getLocalVisibilitySetting(1), "setting d expected");
133
		$this->assertEquals('f', $visibility->getVisibilitySetting($language, $element), "setting f expected (because default is used)");
134
		$this->assertEquals(TRUE, $visibility->isVisible($language, $element), "default lang should be visible");
135
136
	}
137
138
	function _fixture_getLanguageOneWithDefaultFallback() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
139
		// Create the language object fixture.
140
		$fixture = array('uid' => 1, 'tx_languagevisibility_fallbackorder' => '0,1', 'tx_languagevisibility_fallbackorderel' => '0,1', 'tx_languagevisibility_defaultvisibility' => 'f', 'tx_languagevisibility_defaultvisibilityel' => 'f', 'tx_languagevisibility_defaultvisibilityttnewsel' => 'f' );
141
		$language1 = new Language();
142
		$language1->setData($fixture);
143
		return $language1;
144
	}
145
146
	function _fixture_getLanguageThreeWithMultiFallback() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
147
		// Create the language object fixture.
148
		$fixture = array('uid' => 1, 'tx_languagevisibility_fallbackorder' => '0,1', 'tx_languagevisibility_fallbackorderel' => '0,1', 'tx_languagevisibility_defaultvisibility' => 'f', 'tx_languagevisibility_defaultvisibilityel' => 'f' );
149
		$language1 = new Language();
150
		$language1->setData($fixture);
151
		return $language1;
152
	}
153
154
	function _fixture_getLanguageFourWithElementFallback() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
155
		$fixture = array('uid' => 2, 'tx_languagevisibility_fallbackorder' => '0,1', 'tx_languagevisibility_fallbackorderel' => '1', 'tx_languagevisibility_defaultvisibility' => 'f', 'tx_languagevisibility_defaultvisibilityel' => 'f' );
156
		$language4 = new Language();
157
		$language4->setData($fixture);
158
		return $language4;
159
	}
160
161
	function _fixture_getElementWithDefaultVisibility() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
162
		//Create the element object fixture.
163
		$_table = 'tt_content';
164
		$_uid = 9999;
165
		$visibility = array('0' => '-', '1' => '-', '2' => '-' );
166
		$fixture = array('uid' => $_uid, 'sys_language_uid' => '0', 'tx_languagevisibility_visibility' => serialize($visibility) );
167
		$daostub = new DaoCommonStub();
168
		$daostub->stub_setRow($fixture, $_table);
169
170
		$factory = new ElementFactory($daostub);
171
		//get element from factory:
172
		$element = $factory->getElementForTable($_table, $_uid);
173
		return $element;
174
	}
175
176
	function _fixture_getElementWithLangOneVisibility() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
177
		//Create the element object fixture.
178
		$_table = 'tt_content';
179
		$_uid = 9999;
180
		$visibility = array('0' => '-', '1' => '-', '2' => '-' );
181
		$fixtureL1Rec = array('uid' => $_uid, 'l18n_parent' => $_uid - 1, 'sys_language_uid' => 1, 'tx_languagevisibility_visibility' => serialize($visibility) );
182
		$fixtureL0Rec = array('uid' => $_uid - 1, 'sys_language_uid' => 0 );
183
		$daostub = new DaoCommonStub();
184
		$daostub->stub_setRow($fixtureL1Rec, $_table);
185
		$daostub->stub_setRow($fixtureL0Rec, $_table);
186
187
		$factory = new ElementFactory($daostub);
188
		//get element from factory:
189
		$element = $factory->getElementForTable($_table, $_uid);
190
		return $element;
191
	}
192
193
	function _fixture_getFCEElementWithDefaultVisibility() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
194
		//Create the element object fixture.
195
		$_table = 'tt_content';
196
		$_uid = 9999;
197
		$visibility = array('0' => '-', '1' => '-', '2' => '-' );
198
		$fixture = array('uid' => $_uid, 'tx_languagevisibility_visibility' => serialize($visibility), 'CType' => 'templavoila_pi1', 'tx_templavoila_to' => '39', 'tx_templavoila_ds' => '28', 'tx_templavoila_flex' => '<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
199
<T3FlexForms>
200
   <data>
201
       <sheet index="sDEF">
202
           <language index="lDEF">
203
               <field index="field_text">
204
                   <value index="vDEF">free trial</value>
205
                   <value index="vEN">aust: free trial</value>
206
                   <value index="vPT"></value>
207
                   <value index="v_2"></value>
208
                   <value index="vZH"></value>
209
                   <value index="vFR"></value>
210
                   <value index="vDE"></value>
211
                   <value index="vJA"></value>
212
                   <value index="vES"></value>
213
               </field>
214
               <field index="field_smalltext">
215
                   <value index="vDEF"></value>
216
                   <value index="vEN"></value>
217
                   <value index="vPT"></value>
218
                   <value index="v_2"></value>
219
                   <value index="vZH"></value>
220
                   <value index="vFR"></value>
221
                   <value index="vDE"></value>
222
                   <value index="vJA"></value>
223
                   <value index="vES"></value>
224
               </field>
225
               <field index="field_link">
226
                   <value index="vDEF"></value>
227
                   <value index="vEN"></value>
228
                   <value index="vPT"></value>
229
                   <value index="v_2"></value>
230
                   <value index="vZH"></value>
231
                   <value index="vFR"></value>
232
                   <value index="vDE"></value>
233
                   <value index="vJA"></value>
234
                   <value index="vES"></value>
235
               </field>
236
           </language>
237
       </sheet>
238
   </data>
239
</T3FlexForms>' );
240
		$daostub = new DaoCommonStub();
241
		$daostub->stub_setRow($fixture, $_table);
242
243
		$factory = new ElementFactory($daostub);
244
		//get element from factory:
245
		$element = $factory->getElementForTable($_table, $_uid);
246
		return $element;
247
	}
248
249
	function _fixture_getPageElementWithDefaultVisibility() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
250
		//Create the element object fixture.
251
		$_table = 'pages';
252
		$_uid = 99999999999;
253
		$visibility = array('0' => '-', '1' => '-', '2' => '-' );
254
		$fixture = array('uid' => $_uid, 'tx_languagevisibility_visibility' => serialize($visibility), 'tx_languagevisibility_inheritanceflag_original' => 0, 'tx_languagevisibility_inheritanceflag_overlayed' => 0 );
255
		$daostub = new DaoCommonStub();
256
		$daostub->stub_setRow($fixture, $_table);
257
258
		$factory = new ElementFactory($daostub);
259
		//get element from factory:
260
		$element = $factory->getElementForTable($_table, $_uid);
261
		return $element;
262
	}
263
264
	function _fixture_getNewsElementWithDefaultVisibility() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
265
		//Create the element object fixture.
266
		$_table = 'tt_news';
267
		$_uid = 99999;
268
		$visibility = array('0' => '-', '1' => '-', '2' => '-' );
269
		$fixture = array('uid' => $_uid, 'tx_languagevisibility_visibility' => serialize($visibility), 'tx_languagevisibility_inheritanceflag_original' => 0, 'tx_languagevisibility_inheritanceflag_overlayed' => 0 );
270
		$daostub = new DaoCommonStub();
271
		$daostub->stub_setRow($fixture, $_table);
272
273
		$factory = new ElementFactory($daostub);
274
		//get element from factory:
275
		$element = $factory->getElementForTable($_table, $_uid);
276
		return $element;
277
	}
278
}
279