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

changeOfPidDoesNotInfluenceCachedResult()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 33
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 33
rs 8.8571
cc 1
eloc 22
nc 1
nop 0
1
<?php
2
3
namespace AOE\Languagevisibility\Tests\Functional;
4
use AOE\Languagevisibility\CacheManager;
5
use AOE\Languagevisibility\Dao\DaoCommon;
6
use AOE\Languagevisibility\ElementFactory;
7
use AOE\Languagevisibility\Language;
8
use AOE\Languagevisibility\Services\VisibilityService;
9
10
/***************************************************************
11
 * Copyright notice
12
 *
13
 * (c) 2007 AOE media ([email protected])
14
 * All rights reserved
15
 *
16
 * This script is part of the TYPO3 project. The TYPO3 project is
17
 * free software; you can redistribute it and/or modify
18
 * it under the terms of the GNU General Public License as published by
19
 * the Free Software Foundation; either version 2 of the License, or
20
 * (at your option) any later version.
21
 *
22
 * The GNU General Public License can be found at
23
 * http://www.gnu.org/copyleft/gpl.html.
24
 *
25
 * This script is distributed in the hope that it will be useful,
26
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28
 * GNU General Public License for more details.
29
 *
30
 * This copyright notice MUST APPEAR in all copies of the script!
31
 ***************************************************************/
32
class CachedWorkflowTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase {
33
34
	/**
35
	 * @var array
36
	 */
37
	protected $coreExtensionsToLoad = array('version', 'workspaces');
38
39
	/**
40
	 * @var array
41
	 */
42
	protected $testExtensionsToLoad = array('typo3conf/ext/languagevisibility');
43
44
	/**
45
	 * Force the enable state of the cache and flush it.
46
	 *
47
	 * @param void
48
	 * @return void
49
	 */
50
	public function setUp() {
51
		$optionalExtensionKeys = array('static_info_tables', 'templavoila');
52
		foreach ($optionalExtensionKeys as $extensionKey) {
53
			$extensionPath = 'typo3conf/ext/' . $extensionKey;
54
			if (is_dir(ORIGINAL_ROOT . $extensionPath)) {
55
				$this->testExtensionsToLoad[] = $extensionPath;
56
			}
57
		}
58
		parent::setUp();
59
		$GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['languagevisibility'] = serialize(array('useCache' => 1));
60
	}
61
62
	/**
63
	 * Situation:
64
	 *
65
	 * We have a page structure like the following:
66
	 *
67
	 *  a (uid 1)
68
	 *  |
69
	 *  +--- b (uid 2)
70
	 *       |
71
	 *       +---- c (uid 3)
72
	 *
73
	 * Page a has the inherited force to no setting (no +) for the
74
	 * language 3. Therefore the element should not be visible.
75
	 *
76
	 * @test
77
	 */
78
	public function canDetermineInheritedVisibility() {
79
		$this->importDataSet(__DIR__ . '/Fixtures/canDetermineInheritedVisibility.xml');
80
81
		$fixtureLanguageRow = array('uid' => 1, 'tx_languagevisibility_defaultvisibility' => 't');
82
		$fixtureLanguage 	= new Language();
83
		$fixtureLanguage->setData($fixtureLanguageRow);
84
85
		$dao				= new DaoCommon();
86
		$elementFactory 	= new ElementFactory($dao);
87
		$fixtureElement 	= $elementFactory->getElementForTable('pages', 3);
88
89
		$visibilityService 	= new VisibilityService();
90
		$visibilityService->setUseInheritance();
91
		$visibilityResult 	= $visibilityService->isVisible($fixtureLanguage, $fixtureElement);
0 ignored issues
show
Documentation introduced by
$fixtureLanguage is of type object<AOE\Languagevisibility\Language>, but the function expects a object<AOE\Languagevisibility\Services\Language>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$fixtureElement is of type object<AOE\Languagevisibility\Element>, but the function expects a object<AOE\Languagevisibility\Services\Element>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
92
93
		$this->assertFalse($visibilityResult, 'The element should not be visible because of the inherited force to no setting');
94
	}
95
96
	/**
97
	 * We have the same situation as before but in this
98
	 * test we check the visibility of page c and change
99
	 * the pid afterward. Because the visibility is forced
100
	 * to no by inheritance, it should normally be visible,
101
	 * but the result of the visibility is cached in
102
	 * that situation and the visibility will only change afterwards
103
	 * when the cache was flushed.
104
	 *
105
	 * @param void
106
	 * @return void
107
	 * @test
108
	 */
109
	public function changeOfPidDoesNotInfluenceCachedResult() {
110
		$cacheManager	= CacheManager::getInstance();
111
		$isCacheEnabled	= $cacheManager->isCacheEnabled();
112
		$this->assertTrue($isCacheEnabled, 'Cache needs to be enabled to perform this test');
113
114
		// Same code as in canDetermineInheritedVisibility() used to populate the cache now
115
		$this->importDataSet(__DIR__ . '/Fixtures/canDetermineInheritedVisibility.xml');
116
117
		$fixtureLanguageRow = array('uid' => 1, 'tx_languagevisibility_defaultvisibility' => 't');
118
		$fixtureLanguage 	= new Language();
119
		$fixtureLanguage->setData($fixtureLanguageRow);
120
121
		$dao				= new DaoCommon();
122
		$elementFactory 	= new ElementFactory($dao);
123
		$fixtureElement 	= $elementFactory->getElementForTable('pages', 3);
124
125
		$visibilityService 	= new VisibilityService();
126
		$visibilityService->setUseInheritance();
127
		$visibilityResult 	= $visibilityService->isVisible($fixtureLanguage, $fixtureElement);
0 ignored issues
show
Documentation introduced by
$fixtureLanguage is of type object<AOE\Languagevisibility\Language>, but the function expects a object<AOE\Languagevisibility\Services\Language>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$fixtureElement is of type object<AOE\Languagevisibility\Element>, but the function expects a object<AOE\Languagevisibility\Services\Element>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
128
129
		$this->assertFalse($visibilityResult, 'The element should not be visible because of the inherited force to no setting');
130
131
		$db = $GLOBALS['TYPO3_DB'];
132
		/** @var \TYPO3\CMS\Core\Database\DatabaseConnection $db */
133
		$db->exec_UPDATEquery('pages', 'pid=2', array('pid' => 0));
134
		$visibilityResult 	= $visibilityService->isVisible($fixtureLanguage, $fixtureElement);
0 ignored issues
show
Documentation introduced by
$fixtureLanguage is of type object<AOE\Languagevisibility\Language>, but the function expects a object<AOE\Languagevisibility\Services\Language>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$fixtureElement is of type object<AOE\Languagevisibility\Element>, but the function expects a object<AOE\Languagevisibility\Services\Element>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
135
		$this->assertFalse($visibilityResult, 'The element should not still not be visible because the visibility result is cached');
136
137
		CacheManager::getInstance()->flushAllCaches();
138
139
		$visibilityResult 	= $visibilityService->isVisible($fixtureLanguage, $fixtureElement);
0 ignored issues
show
Documentation introduced by
$fixtureLanguage is of type object<AOE\Languagevisibility\Language>, but the function expects a object<AOE\Languagevisibility\Services\Language>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$fixtureElement is of type object<AOE\Languagevisibility\Element>, but the function expects a object<AOE\Languagevisibility\Services\Element>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
140
		$this->assertTrue($visibilityResult, 'Now the element should be visible because the cache was flushed');
141
	}
142
}
143