CachedWorkflowTest::setUp()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 3
nop 0
1
<?php
2
3
namespace AOE\Languagevisibility\Tests\Functional;
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\CacheManager;
29
use AOE\Languagevisibility\Dao\DaoCommon;
30
use AOE\Languagevisibility\ElementFactory;
31
use AOE\Languagevisibility\Language;
32
use AOE\Languagevisibility\Services\VisibilityService;
33
34
/**
35
 * Class CachedWorkflowTest
36
 * @package AOE\Languagevisibility\Tests\Functional
37
 */
38
class CachedWorkflowTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase {
39
40
	/**
41
	 * @var array
42
	 */
43
	protected $coreExtensionsToLoad = array('version', 'workspaces');
44
45
	/**
46
	 * @var array
47
	 */
48
	protected $testExtensionsToLoad = array('typo3conf/ext/languagevisibility');
49
50
	/**
51
	 * Force the enable state of the cache and flush it.
52
	 *
53
	 * @param void
54
	 * @return void
55
	 */
56
	public function setUp() {
57
		$optionalExtensionKeys = array('static_info_tables', 'templavoila');
58
		foreach ($optionalExtensionKeys as $extensionKey) {
59
			$extensionPath = 'typo3conf/ext/' . $extensionKey;
60
			if (is_dir(ORIGINAL_ROOT . $extensionPath)) {
61
				$this->testExtensionsToLoad[] = $extensionPath;
62
			}
63
		}
64
		parent::setUp();
65
		$GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['languagevisibility'] = serialize(array('useCache' => 1));
66
	}
67
68
	/**
69
	 * Situation:
70
	 *
71
	 * We have a page structure like the following:
72
	 *
73
	 *  a (uid 1)
74
	 *  |
75
	 *  +--- b (uid 2)
76
	 *       |
77
	 *       +---- c (uid 3)
78
	 *
79
	 * Page a has the inherited force to no setting (no +),
80
	 * therefore the element should not be visible.
81
	 *
82
	 * @test
83
	 */
84
	public function canDetermineInheritedVisibility() {
85
		$this->importDataSet(__DIR__ . '/Fixtures/canDetermineInheritedVisibility.xml');
86
87
		$fixtureLanguageRow = array('uid' => 1, 'tx_languagevisibility_defaultvisibility' => 't');
88
		$fixtureLanguage 	= new Language();
89
		$fixtureLanguage->setData($fixtureLanguageRow);
90
91
		$dao				= new DaoCommon();
92
		$elementFactory 	= new ElementFactory($dao);
93
		$fixtureElement 	= $elementFactory->getElementForTable('pages', 3);
94
95
		$visibilityService 	= new VisibilityService();
96
		$visibilityService->setUseInheritance();
97
		$visibilityResult 	= $visibilityService->isVisible($fixtureLanguage, $fixtureElement);
98
99
		$this->assertFalse($visibilityResult, 'The element should not be visible because of the inherited force to no setting');
100
	}
101
102
	/**
103
	 * We have the same situation as before but in this
104
	 * test we check the visibility of page c and change
105
	 * the pid afterward. Because the visibility is forced
106
	 * to no by inheritance, it should normally be visible,
107
	 * but the result of the visibility is cached in
108
	 * that situation and the visibility will only change afterwards
109
	 * when the cache was flushed.
110
	 *
111
	 * @param void
112
	 * @return void
113
	 * @test
114
	 */
115
	public function changeOfPidDoesNotInfluenceCachedResult() {
116
		$cacheManager	= CacheManager::getInstance();
117
		$isCacheEnabled	= $cacheManager->isCacheEnabled();
118
		$this->assertTrue($isCacheEnabled, 'Cache needs to be enabled to perform this test');
119
120
		// Same code as in canDetermineInheritedVisibility() used to populate the cache now
121
		$this->importDataSet(__DIR__ . '/Fixtures/canDetermineInheritedVisibility.xml');
122
123
		$fixtureLanguageRow = array('uid' => 1, 'tx_languagevisibility_defaultvisibility' => 't');
124
		$fixtureLanguage 	= new Language();
125
		$fixtureLanguage->setData($fixtureLanguageRow);
126
127
		$dao				= new DaoCommon();
128
		$elementFactory 	= new ElementFactory($dao);
129
		$fixtureElement 	= $elementFactory->getElementForTable('pages', 3);
130
131
		$visibilityService 	= new VisibilityService();
132
		$visibilityService->setUseInheritance();
133
		$visibilityResult 	= $visibilityService->isVisible($fixtureLanguage, $fixtureElement);
134
135
		$this->assertFalse($visibilityResult, 'The element should not be visible because of the inherited force to no setting');
136
137
		$db = $GLOBALS['TYPO3_DB'];
138
		/** @var \TYPO3\CMS\Core\Database\DatabaseConnection $db */
139
		$db->exec_UPDATEquery('pages', 'pid=2', array('pid' => 0));
140
		$visibilityResult 	= $visibilityService->isVisible($fixtureLanguage, $fixtureElement);
141
		$this->assertFalse($visibilityResult, 'The element should not still not be visible because the visibility result is cached');
142
143
		CacheManager::getInstance()->flushAllCaches();
144
145
		$visibilityResult 	= $visibilityService->isVisible($fixtureLanguage, $fixtureElement);
146
		$this->assertTrue($visibilityResult, 'Now the element should be visible because the cache was flushed');
147
	}
148
}
149