test_visibility_complexOverlay()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 0
1
<?php
2
3
namespace AOE\Languagevisibility\Tests\Functional\Services;
4
5
/***************************************************************
6
 * Copyright notice
7
 *
8
 * (c) 2016 AOE GmbH <[email protected]>
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
28
use AOE\Languagevisibility\Dao\DaoCommon;
29
use AOE\Languagevisibility\ElementFactory;
30
use AOE\Languagevisibility\PageElement;
31
use AOE\Languagevisibility\Services\VisibilityService;
32
use AOE\Languagevisibility\Tests\Functional\DatabaseTtContentTest;
33
34
/**
35
 * Test case for checking the PHPUnit 3.1.9
36
 *
37
 * WARNING: Never ever run a unit test like this on a live site!
38
 *
39
 * @author	Tolleiv Nietsch
40
 */
41
class VisibilityServiceDbTest extends DatabaseTtContentTest {
42
43
	/**
44
	 * Check the visibility of a regular content element
45
	 *
46
	 * @test
47
	 * @param void
48
	 * @return void
49
	 * @see \\AOE\\Languagevisibility\\Services\\VisibilityService
50
	 */
51
	public function visibility_ce() {
52
		$language = $this->_getLang(1);
53
		$visibility = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('AOE\\Languagevisibility\\Services\\VisibilityService');
54
55
		$fixturesWithoutOverlay = array('tt_content' => 1, 'pages' => 1 );
56
57
		foreach ($fixturesWithoutOverlay as $table => $uid ) {
58
			$element = $this->_getContent($table, $uid);
59
			$this->assertEquals('-', $element->getLocalVisibilitySetting(1), 'setting d expected');
60
			$this->assertEquals('f', $visibility->getVisibilitySetting($language, $element), 'setting f expected (because default is used)');
61
			$this->assertEquals(TRUE, $visibility->isVisible($language, $element), 'default lang should be visible');
62
			$this->assertEquals(0, $visibility->getOverlayLanguageIdForLanguageAndElement($language, $element), sprintf('default should be overlay table:%s uid:%d', $table, $uid));
63
		}
64
	}
65
66
	/**
67
	 * Check the visibility of a regular content element
68
	 *
69
	 * @test
70
	 * @param void
71
	 * @return void
72
	 * @see \\AOE\\Languagevisibility\\Services\\VisibilityService
73
	 */
74
	public function visibility_ceForcedToYesWithoutOverlay() {
75
		$language = $this->_getLang(1);
76
		$visibility = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('AOE\\Languagevisibility\\Services\\VisibilityService');
77
78
		$fixturesWithoutOverlay = array('tt_content' => 19);
79
80
		foreach ( $fixturesWithoutOverlay as $table => $uid ) {
81
			$element = $this->_getContent($table, $uid);
82
			$this->assertEquals('yes', $element->getLocalVisibilitySetting(1), 'setting d expected');
83
			$this->assertEquals('yes', $visibility->getVisibilitySetting($language, $element), 'setting f expected (because default is used)');
84
			$this->assertEquals(TRUE, $visibility->isVisible($language, $element), 'element should be visible');
85
			$this->assertEquals(0, $visibility->getOverlayLanguageIdForLanguageAndElement($language, $element), sprintf('default language should be choosen here table:%s uid:%d', $table, $uid));
86
		}
87
	}
88
89
	/**
90
	 * Check the visibility of a regular content element
91
	 *
92
	 * @test
93
	 * @param void
94
	 * @return void
95
	 * @see \\AOE\\Languagevisibility\\Services\\VisibilityService
96
	 */
97
	public function visibility_ceForcedToYesWithOverlay() {
98
		$language = $this->_getLang(1);
99
		$visibility = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('AOE\\Languagevisibility\\Services\\VisibilityService');
100
101
		$fixturesWithoutOverlay = array('tt_content' => 20);
102
103
		foreach ( $fixturesWithoutOverlay as $table => $uid ) {
104
			$element = $this->_getContent($table, $uid);
105
			$this->assertEquals('yes', $element->getLocalVisibilitySetting(1), 'setting d expected');
106
			$this->assertEquals('yes', $visibility->getVisibilitySetting($language, $element), 'setting f expected (because default is used)');
107
			$this->assertEquals(TRUE, $visibility->isVisible($language, $element), 'element should be visible');
108
			$this->assertEquals(TRUE, $element->hasTranslation(1), 'translation should be detected');
109
			$this->assertEquals(1, $visibility->getOverlayLanguageIdForLanguageAndElement($language, $element), sprintf('language 1 should be choosen here table:%s uid:%d', $table, $uid));
110
		}
111
	}
112
113
	/**
114
	 * Check the visibility of some content elements with overlay-records
115
	 *
116
	 * @test
117
	 * @param void
118
	 * @return void
119
	 * @see \\AOE\\Languagevisibility\\Services\\VisibilityService
120
	 */
121
	public function visibility_overlayCe() {
122
		$element = $this->_getContent('tt_content', 2 /* element with L1 overlay */);
123
		$visibility = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('AOE\\Languagevisibility\\Services\\VisibilityService');
124
125
		$expectedResults = array(1 => 1, 2 => 1, 3 => 0, 4 => 1 );
126
		foreach ( $expectedResults as $langUid => $expectedResult ) {
127
			$language = $this->_getLang($langUid);
128
129
			$this->assertEquals(TRUE, $visibility->isVisible($language, $element), 'element should be visible in lang ' . $expectedResult);
130
			$this->assertEquals($expectedResult, $visibility->getOverlayLanguageIdForLanguageAndElement($language, $element), sprintf('Element Overlay used wrong fallback - language %d - should be %d ', $langUid, $expectedResult));
131
		}
132
	}
133
134
	/**
135
	 * Check the visibility of some content elements with overlay-records
136
	 *
137
	 * @test
138
	 * @param void
139
	 * @return void
140
	 * @see \\AOE\\Languagevisibility\\Services\\VisibilityService
141
	 */
142
	public function visibility_hiddenOverlayCe() {
143
144
		if (!\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('version')) {
145
			$this->markTestSkipped('Not relevant if "version" is not installed');
146
		}
147
148
		if (is_object($GLOBALS['TSFE'])) {
149
			$this->markTestSkipped('Please turn off the fake frontend (phpunit extension configuration) - this test won\'t work with "fake" frontends ;)');
150
		}
151
152
		/** @var $element tx_languagevisibility_element */
153
		$element = $this->_getContent('tt_content', 15 /* element with L1 overlay */);
154
		/** @var $visibility \\AOE\\Languagevisibility\\Services\\VisibilityService */
155
		$visibility = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('AOE\\Languagevisibility\\Services\\VisibilityService');
156
157
		//Test language 4 to see that this is working if something exists
158
		$language = $this->_getLang(4);
159
		$this->assertEquals('t', $visibility->getVisibilitySetting($language, $element));
160
		$this->assertTrue($visibility->isVisible($language, $element), 'There\'s an overlay for this language - therefore it should be visible');
161
		$this->assertTrue($element->hasTranslation(4));
162
163
		//the overlay(17) has no configured visiblity and is hidden. The original (15) has the following visibility:
164
		// a:5:{i:0;s:1:"-";i:1;s:1:"-";i:2;s:1:"-";i:4;s:1:"t";i:5;s:1:"t";}
165
		// because the overlay is hidden it should not be visible
166
		$language = $this->_getLang(5);
167
		$this->assertEquals('t', $visibility->getVisibilitySetting($language, $element));
168
		$this->assertFalse($visibility->isVisible($language, $element), 'This one shouldn\'t be visible because there\'s no valid overlay');
169
		$this->assertFalse($element->hasTranslation(5));
170
171
		$this->_fakeWorkspaceContext(5);
172
		$language = $this->_getLang(5);
173
		$this->assertEquals('t', $visibility->getVisibilitySetting($language, $element));
174
		$this->assertTrue($visibility->isVisible($language, $element), 'This one should be visible because there\'s a valid overlay in the workspace (5)');
175
		$this->assertTrue($element->hasTranslation(5));
176
		$this->_fakeWorkspaceContext(0);
177
	}
178
179
	function test_visibility_overlayPage() {
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...
180
		$language = $this->_getLang(1);
181
		$element = $this->_getContent('pages', '2');
182
183
		$visibility = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('AOE\\Languagevisibility\\Services\\VisibilityService');
184
185
		$this->assertEquals(TRUE, $visibility->isVisible($language, $element), 'page should be visible');
186
		$this->assertEquals(1, $visibility->getOverlayLanguageIdForLanguageAndElement($language, $element), 'Page-Overlay should be defined for lang 1 ...');
187
	}
188
189
	public function test_visibility_complexOverlay() {
190
		$language = $this->_getLang(3);
191
		$visibility = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('AOE\\Languagevisibility\\Services\\VisibilityService');
192
193
		$fixtures = array('tt_content' => array('uid' => 2, 'result' => 0 ), 'pages' => array('uid' => 2, 'result' => 1 ) );
194
		foreach ( $fixtures as $table => $tableFixtures ) {
195
			$element = $this->_getContent($table, $tableFixtures['uid']);
196
			$this->assertEquals($tableFixtures['result'], $visibility->getOverlayLanguageIdForLanguageAndElement($language, $element), sprintf('Element Overlay used wrong fallback - language 2  table %s:%d- should be %d ', $table, $tableFixtures['uid'], $tableFixtures['result']));
197
		}
198
	}
199
200
	/**
201
	 * As discussed in issue 6863 an editor should be able to set the languagevisibility right
202
	 * "force to no" in the overlay record.
203
	 *
204
	 * @param void
205
	 * @return void
206
	 * @see \\AOE\\Languagevisibility\\Services\\VisibilityService
207
	 */
208
	public function test_visibility_ttcontentOverlayForceToNoAffectsVisibility() {
209
		$language = $this->_getLang(1);
210
211
		/**
212
		 * The xml structure is used to to create a fixture tt_content element
213
		 * with the visibility "yes" for all languages. For the same element
214
		 * an overlay in language 1 exists with the setting "force to no".
215
		 * In this case the "force to no" setting in the overlay should overwrite
216
		 * the "yes" setting in the content element. Therefore the element should not be
217
		 * visible.
218
		 */
219
220
		$element = $this->_getContent('tt_content', 4);
221
222
		$service = new VisibilityService();
223
224
		$visibilityResult = $service->isVisible($language, $element);
225
226
		$this->assertFalse($visibilityResult, 'tt-content element is visible, but should not be visible');
227
	}
228
229
	/**
230
	 * This testcase does exactly the same as the previos testcase (test_visibility_ttcontentOverlayForceToNoAffectsVisibility)
231
	 * but uses page elements.
232
	 *
233
	 * @param void
234
	 * @return void
235
	 * @see \\AOE\\Languagevisibility\\Services\\VisibilityService
236
	 * @return
237
	 */
238
	public function test_visibility_pagesOverlayForceToNoAffectsVisibility() {
239
		$language = $this->_getLang(1);
240
		$element = $this->_getContent('pages', 4);
241
242
		$service = new VisibilityService();
243
		$visibilityResult = $service->isVisible($language, $element);
244
245
		$this->assertFalse($visibilityResult, 'page element is visible, but should not be visible');
246
	}
247
248
	/**
249
	 * This testcase is used to test if an "force to no"-setting  in an overlay record in the workspace
250
	 * affects the original element in the workspace.
251
	 *
252
	 */
253
	public function test_visibility_ttcontentOverlayForceToNoAffectsVisibilityAlsoInWorkspaces() {
254
255
		if (!\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('version')) {
256
			$this->markTestSkipped('Not relevant if "version" is not installed');
257
		}
258
259
		if (is_object($GLOBALS['TSFE'])) {
260
			$this->markTestSkipped('Please turn off the fake frontend (phpunit extension configuration) - this test won\'t work with "fake" frontends ;)');
261
		}
262
263
		$this->_fakeWorkspaceContext(4711);
264
265
		$language = $this->_getLang(1);
266
		$element = $this->_getContent('tt_content', 6);
267
		$service = new VisibilityService();
268
269
		$visibilityResult = $service->isVisible($language, $element);
270
271
		$this->assertFalse($visibilityResult, 'element is visible, but should not be visible');
272
	}
273
274
	/**
275
	 * The visibility setting in an overlay should only overwrite the visibility
276
	 * when it is set to "force to no" a "force to yes" setting should not affect the orginal record.
277
	 *
278
	 */
279
	public function test_visibility_ttcontentOverlayForceToYesNotAffectsVisibility() {
280
		$language = $this->_getLang(1);
281
		$element = $this->_getContent('tt_content', 10);
282
283
		$service = new VisibilityService();
284
285
		$visibilityResult = $service->isVisible($language, $element);
286
287
		$this->assertFalse($visibilityResult, 'visibility setting in overlay makes orginal element visible');
288
	}
289
290
	public function test_visibility_ttcontentOverlayCorruptedNotAffectsVisibilits() {
291
		$language = $this->_getLang(1);
292
		$element = $this->_getContent('tt_content', 12);
293
294
		$service = new VisibilityService();
295
296
		$visibilityResult = $service->isVisible($language, $element);
297
298
		$this->assertTrue($visibilityResult, 'corrupted element forces visibility to no');
299
300
	}
301
302
	public function test_visibility_ttcontentHasTranslationInAnyWorkspace() {
303
		$element = $this->_getContent('tt_content', 14);
304
305
		$hasTranslation = TRUE;
0 ignored issues
show
Unused Code introduced by
$hasTranslation is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
306
		$hasTranslation = $element->hasAnyTranslationInAnyWorkspace();
307
308
		$this->assertFalse($element->supportsInheritance());
309
		$this->assertFalse($hasTranslation, 'Element without translation is determined as element with translation.');
310
	}
311
312
	/**
313
	 * When an element has configured -1 as sys_language_uid it is configured to be
314
	 * visible in all languages. This testcase should ensure that this is evaluated
315
	 * correctly.
316
	 *
317
	 * @test
318
	 * @param void
319
	 * @return void
320
	 */
321
	public function canDetermineCorrectVisiblityForContentelementWithLanguageSetToAll() {
322
		$this->importDataSet(__DIR__ . '/../Fixtures/canDetermineCorrectVisiblityForContentelementWithLanguageSetToAll.xml');
323
		$service = new VisibilityService();
324
325
		$language = $this->_getLang(1);
326
327
		$dao = new DaoCommon();
328
329
		$factory = new ElementFactory($dao);
330
331
		$visibilityResult = TRUE;
0 ignored issues
show
Unused Code introduced by
$visibilityResult is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
332
		/* @var $element PageElement  */
333
		$element = $factory->getElementForTable('tt_content', 1111);
334
		$visibilityResult = $service->isVisible($language, $element);
335
336
		$this->assertTrue($visibilityResult, 'An element with language set to all is not visible');
337
		$this->assertTrue($element->isLanguageSetToAll());
338
		$this->assertFalse($element->isLanguageSetToDefault());
339
		$this->assertTrue($element->isLiveWorkspaceElement());
340
	}
341
342
	/**
343
	 * This testcase ensures that the state "force to no inherited" affects the visibility of a page in
344
	 * it's rootline.
345
	 *
346
	 * We have the following pages
347
	 *
348
	 * uid: 5 (has n+ for the language uk)
349
	 * uid 6 (pid 6) simple page for fixture rootline
350
	 * uid 7 (pid 7) is used to evaluate the visibility	and has no local visibility
351
	 *
352
	 * @test
353
	 * @param void
354
	 * @return void
355
	 */
356
	public function inheritanceForceToNoAffectsSubpage() {
357
		$this->importDataSet(__DIR__ . '/../Fixtures/inheritanceForceToNoAffectsSubpage.xml');
358
		$language = $this->_getLang(1);
359
		$service = new VisibilityService();
360
		$service->setUseInheritance();
361
362
		$dao = new DaoCommon();
363
364
		$factory = new ElementFactory($dao);
365
366
		$visibilityResult = TRUE;
0 ignored issues
show
Unused Code introduced by
$visibilityResult is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
367
368
		/* @var $element PageElement */
369
		$element = $factory->getElementForTable('pages', 6);
370
		$visibilityResult = $service->isVisible($language, $element);
371
372
		$this->assertTrue($element->supportsInheritance());
373
		$this->assertFalse($visibilityResult, 'element should be invisible because  a page in the rootline has an inherited no+ setting');
374
375
		$element = $factory->getElementForTable('pages', 7);
376
		$this->assertTrue($element->supportsInheritance());
377
		$visibilityResult = $service->isVisible($language, $element);
378
379
		$this->assertFalse($visibilityResult, 'element should be invisible because a page in the rootline has an inherited no+ setting');
380
	}
381
382
	/**
383
	 * This testcase ensures that the state "force to no inherited" affects the visibility of a page in
384
	 * it's rootline.
385
	 *
386
	 * We have the following pages
387
	 *
388
	 * uid: 5 (has n+ for the language uk)
389
	 * uid 6 (pid 6) simple page for fixture rootline
390
	 * uid 7 (pid 7) is used to evaluate the visibility	and has no local visibility
391
	 *
392
	 * @test
393
	 * @param void
394
	 * @return void
395
	 */
396
	public function inheritanceForceToNoInOverlayAffectsSubpage() {
397
		$this->importDataSet(__DIR__ . '/../Fixtures/inheritanceForceToNoInOverlayAffectsSubpage.xml');
398
		$language = $this->_getLang(1);
399
		$service = new VisibilityService();
400
		$service->setUseInheritance();
401
402
		$dao = new DaoCommon();
403
404
		$factory = new ElementFactory($dao);
405
406
		/* @var $element PageElement */
407
		$element = $factory->getElementForTable('pages', 6);
408
		$visibilityResult = $service->isVisible($language, $element);
409
410
		$this->assertTrue($element->supportsInheritance());
411
		$this->assertFalse($visibilityResult, 'element should be invisible because  a page in the rootline has an inherited no+ setting');
412
413
		$element = $factory->getElementForTable('pages', 7);
414
		$this->assertTrue($element->supportsInheritance());
415
		$visibilityResult = $service->isVisible($language, $element);
416
417
		$this->assertFalse($visibilityResult, 'element should be invisible because a page in the rootline has an inherited no+ setting');
418
	}
419
420
	/**
421
	 * The force to no inheritance (no+) setting should only affect subpages if
422
	 * the flag is also set without the flag the setting should not be evaluated.
423
	 *
424
	 * We have the following pages
425
	 *
426
	 * uid: 5 (has n+ for the language uk) BUT NO inheritance flag
427
	 * uid 6 (pid 6) simple page for fixture rootline
428
	 * uid 7 (pid 7) is used to evaluate the visibility	and has no local visibility
429
	 *
430
	 * @test
431
	 * @param void
432
	 * @return void
433
	 */
434
	public function inheritanceForceToNoDoesNotAffectSubpageWithoutAGivenInheritanceFlag() {
435
		$this->importDataSet(__DIR__ . '/../Fixtures/inheritanceForceToNoDoesNotAffectSubpageWithoutAGivenInheritanceFlag.xml');
436
437
		$language = $this->_getLang(1);
438
		$service = new VisibilityService();
439
		$service->setUseInheritance();
440
441
		$dao = new DaoCommon();
442
443
		$factory = new ElementFactory($dao);
444
445
		$element = $factory->getElementForTable('pages', 6);
446
		$visibilityResult = $service->isVisible($language, $element);
447
448
		$this->assertTrue($visibilityResult, 'element should be visible because  a page in the rootline has an inherited no+ setting but no inheritance flag');
449
450
		$element = $factory->getElementForTable('pages', 7);
451
		$visibilityResult = $service->isVisible($language, $element);
452
453
		$this->assertTrue($visibilityResult, 'element should be visible because a page in the rootline has an inherited no+ setting but no inheritance flag');
454
	}
455
456
	/**
457
	 * The no+ should also only affect pages in the language it has been configured for in the following
458
	 * testcase we have a page with a no+ setting for the australian language but we evaluate it for uk
459
	 * therefore the no+ setting should not have any impact on the visibility of the element.
460
	 * We have the following pages
461
	 *
462
	 * uid: 5 (has n+ for the language aus) and also the inheritance flag
463
	 * uid 6 (pid 6) simple page for fixture rootline
464
	 * uid 7 (pid 7) is used to evaluate the visibility	and has no local visibility
465
	 *
466
	 * @test
467
	 * @param void
468
	 * @return void
469
	 */
470
	public function inheritanceForceToNoInOtherLanguageDoesNotAffectRecordInCurrentLanguage() {
471
		$this->importDataSet(__DIR__ . '/../Fixtures/inheritanceForceToNoInOtherLanguageDoesNotAffectRecordInCurrentLanguage.xml');
472
473
		$language = $this->_getLang(1);
474
		$service = new VisibilityService();
475
		$service->setUseInheritance();
476
477
		$dao = new DaoCommon();
478
479
		$factory = new ElementFactory($dao);
480
481
		$element = $factory->getElementForTable('pages', 6);
482
		$visibilityResult = $service->isVisible($language, $element);
483
484
		$this->assertTrue($visibilityResult, 'element should be visible because  a page in the rootline has an inherited no+ setting but in another language');
485
486
		$element = $factory->getElementForTable('pages', 7);
487
		$visibilityResult = $service->isVisible($language, $element);
488
489
		$this->assertTrue($visibilityResult, 'element should be visible because  a page in the rootline has an inherited no+ setting but in another language');
490
	}
491
492
	/**
493
	 * When an element has the setting yes and an element in the rootline has the setting no+ (inherited no)
494
	 * the element should be visible (rootline should not be evaluated for inherited settings).
495
	 *
496
	 * uid: 5 (has n+ for the language uk) and also the inheritance flag
497
	 * uid 6 (pid 6) simple page for fixture rootline
498
	 * uid 7 (pid 7) is used to evaluate the visibility and has the visibility setting "yes"
499
	 *
500
	 * @test
501
	 * @param void
502
	 * @return void
503
	 */
504
	public function yesInPageAnnulatesInheritedForceToNoOfRootlineRecord() {
505
		$this->importDataSet(__DIR__ . '/../Fixtures/yesInPageAnnulatesInheritedForceToNoOfRootlineRecord.xml');
506
507
		$language = $this->_getLang(1);
508
		$service = new VisibilityService();
509
		$service->setUseInheritance();
510
511
		$dao = new DaoCommon();
512
513
		$factory = new ElementFactory($dao);
514
515
		$element = $factory->getElementForTable('pages', 6);
516
		$visibilityResult = $service->isVisible($language, $element);
517
518
		$this->assertFalse($visibilityResult, 'element should be invisible because  a page in the rootline has an inherited no+ setting there is no local overwriting setting');
519
520
		$element = $factory->getElementForTable('pages', 7);
521
		$visibilityResult = $service->isVisible($language, $element);
522
523
		$this->assertTrue($visibilityResult, 'element should be visible because  a page in the rootline has an inherited no+ setting but the local setting is forced to yes');
524
	}
525
526
	/**
527
	 * The inheritance of the languagevisibility is controlled by a visibility flag
528
	 *
529
	 * @test
530
	 */
531
	public function overlayOverwritesInheritingVisibilityOfPageElements() {
532
		$this->importDataSet(__DIR__ . '/../Fixtures/overlayOverwritesInheritingVisibilityOfPageElements.xml');
533
534
		$language = $this->_getLang(1);
535
		$service = new VisibilityService();
536
		$service->setUseInheritance();
537
538
		$dao = new DaoCommon();
539
540
		$factory = new ElementFactory($dao);
541
542
		$element = $factory->getElementForTable('pages', 6);
543
		$visibilityResult = $service->isVisible($language, $element);
544
545
		$this->assertFalse($visibilityResult, 'element should be invisible because overlay overwrites inheriting visibility on page 5');
546
547
		$element = $factory->getElementForTable('pages', 7);
548
		$visibilityResult = $service->isVisible($language, $element);
549
550
		$this->assertFalse($visibilityResult, 'element should be invisible because overlay overwrites inheriting visibility on page 5');
551
	}
552
553
	/**
554
	 * Every element can be tested if it is visible for a given language. In addition a
555
	 * description can be delivered why an element is visible or not.
556
	 *
557
	 * @param void
558
	 * @return void
559
	 * @test
560
	 */
561
	public function canGetCorrectVisiblityDescriptionForElementWithInheritedVisibility() {
562
		$this->importDataSet(__DIR__ . '/../Fixtures/canGetCorrectVisiblityDescriptionForElementWithInheritedVisibility.xml');
563
564
		$language = $this->_getLang(1);
565
		$service = new VisibilityService();
566
		$service->setUseInheritance();
567
568
		$dao = new DaoCommon();
569
570
		$factory = new ElementFactory($dao);
571
572
		/* @var $element PageElement*/
573
		$element = $factory->getElementForTable('pages', 7);
574
		$visibilityDescription = $service->getVisibilityDescription($language, $element);
575
576
		$this->assertEquals('force to no (inherited from uid 5)', $visibilityDescription, 'invalid visibility description of element with inheritance');
577
	}
578
}
579