This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace AOE\Languagevisibility\Tests\Unit\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\DaoCommonStub; |
||
29 | use AOE\Languagevisibility\ElementFactory; |
||
30 | use AOE\Languagevisibility\Language; |
||
31 | use AOE\Languagevisibility\PageElement; |
||
32 | use AOE\Languagevisibility\Services\VisibilityService; |
||
33 | use AOE\Languagevisibility\TtnewsElement; |
||
34 | |||
35 | /** |
||
36 | * Test case for checking the PHPUnit 3.1.9 |
||
37 | * |
||
38 | * WARNING: Never ever run a unit test like this on a live site! |
||
39 | * |
||
40 | * @author Daniel Pötzinger |
||
41 | */ |
||
42 | class VisibilityServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { |
||
43 | |||
44 | public function setUp() { |
||
45 | $this->markTestIncomplete('Needs refactoring'); |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * @test |
||
50 | */ |
||
51 | public function canGetSupportedTables() { |
||
52 | $expectedSupportedTables = array('pages', 'pages_language_overlay', 'tt_content', 'tt_news'); |
||
53 | $supportedTables = VisibilityService::getSupportedTables(); |
||
54 | |||
55 | $this->assertTrue(is_array($supportedTables)); |
||
56 | |||
57 | foreach ($expectedSupportedTables as $expectedSupportedTable) { |
||
58 | $this->assertContains($expectedSupportedTable, $supportedTables); |
||
59 | } |
||
60 | } |
||
61 | |||
62 | public function test_visibility() { |
||
63 | |||
64 | // Create the language object fixture. |
||
65 | $fixture = array('uid' => 1, 'tx_languagevisibility_fallbackorder' => '2' ); |
||
66 | $language1 = new Language(); |
||
67 | $language1->setData($fixture); |
||
68 | |||
69 | $rep = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('AOE\\Languagevisibility\\LanguageRepository'); |
||
70 | $deflanguage = $rep->getDefaultLanguage(); |
||
71 | //Create the element object fixture. |
||
72 | $_table = 'tt_content'; |
||
73 | $_uid = 1; |
||
74 | $visibility = array('0' => 'yes', '1' => 't', '2' => '' ); |
||
75 | $fixture = array('uid' => $_uid, 'tx_languagevisibility_visibility' => serialize($visibility) ); |
||
76 | $daostub = new DaoCommonStub(); |
||
77 | $daostub->stub_setRow($fixture, $_table); |
||
78 | |||
79 | $factory = new ElementFactory($daostub); |
||
80 | //get element from factory: |
||
81 | $element = $factory->getElementForTable($_table, $_uid); |
||
82 | |||
83 | //test |
||
84 | $visibility = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('AOE\\Languagevisibility\\Services\\VisibilityService'); |
||
85 | |||
86 | // language 1 should be set local to "t" |
||
87 | $this->assertEquals('t', $visibility->getVisibilitySetting($language1, $element), "setting t expected"); |
||
88 | $this->assertEquals(TRUE, $visibility->isVisible($deflanguage, $element), "default lang should be visible"); |
||
89 | } |
||
90 | |||
91 | public function test_visibility_fixture_ce() { |
||
92 | |||
93 | $language = $this->_fixture_getLanguageOneWithDefaultFallback(); |
||
94 | $element = $this->_fixture_getElementWithDefaultVisibility(); |
||
95 | |||
96 | //test |
||
97 | $visibility = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('AOE\\Languagevisibility\\Services\\VisibilityService'); |
||
98 | |||
99 | // language 1 should be set local to "t" |
||
100 | $this->assertEquals('-', $element->getLocalVisibilitySetting(1), "setting d expected"); |
||
101 | $this->assertEquals('f', $visibility->getVisibilitySetting($language, $element), "setting f expected (because default is used)"); |
||
102 | $this->assertEquals(TRUE, $visibility->isVisible($language, $element), "default lang should be visible"); |
||
103 | $this->assertEquals(0, $visibility->getOverlayLanguageIdForLanguageAndElement($language, $element), "default should be overlay"); |
||
104 | } |
||
105 | |||
106 | public function test_visibility_fixture_page() { |
||
107 | |||
108 | $language = $this->_fixture_getLanguageOneWithDefaultFallback(); |
||
109 | $element = $this->_fixture_getPageElementWithDefaultVisibility(); |
||
110 | |||
111 | //test |
||
112 | $visibility = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('AOE\\Languagevisibility\\Services\\VisibilityService'); |
||
113 | |||
114 | // language 1 should be set local to "t" |
||
115 | $this->assertTrue($element instanceof PageElement, 'factory return instance of wrong type'); |
||
116 | $this->assertEquals('-', $element->getLocalVisibilitySetting(1), "setting d expected"); |
||
117 | $this->assertEquals('f', $visibility->getVisibilitySetting($language, $element), "setting f expected (because default is used)"); |
||
118 | $this->assertEquals(TRUE, $visibility->isVisible($language, $element), "default lang should be visible"); |
||
119 | $this->assertEquals(0, $visibility->getOverlayLanguageIdForLanguageAndElement($language, $element), "default record should be overlay"); |
||
120 | } |
||
121 | |||
122 | public function test_visibility_fixture_news() { |
||
123 | |||
124 | if (!\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('tt_news')) { |
||
125 | $this->markTestSkipped('Not relevant if "tt_news" is not installed'); |
||
126 | } |
||
127 | |||
128 | $language = $this->_fixture_getLanguageOneWithDefaultFallback(); |
||
129 | $element = $this->_fixture_getNewsElementWithDefaultVisibility(); |
||
130 | |||
131 | $visibility = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('AOE\\Languagevisibility\\Services\\VisibilityService'); |
||
132 | |||
133 | $this->assertTrue($element instanceof TtnewsElement, 'factory returned instance of wrong type'); |
||
134 | $this->assertEquals('-', $element->getLocalVisibilitySetting(1), "setting d expected"); |
||
135 | $this->assertEquals('f', $visibility->getVisibilitySetting($language, $element), "setting f expected (because default is used)"); |
||
136 | $this->assertEquals(TRUE, $visibility->isVisible($language, $element), "default lang should be visible"); |
||
137 | |||
138 | } |
||
139 | |||
140 | function _fixture_getLanguageOneWithDefaultFallback() { |
||
0 ignored issues
–
show
|
|||
141 | // Create the language object fixture. |
||
142 | $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' ); |
||
143 | $language1 = new Language(); |
||
144 | $language1->setData($fixture); |
||
145 | return $language1; |
||
146 | } |
||
147 | |||
148 | function _fixture_getLanguageThreeWithMultiFallback() { |
||
0 ignored issues
–
show
|
|||
149 | // Create the language object fixture. |
||
150 | $fixture = array('uid' => 1, 'tx_languagevisibility_fallbackorder' => '0,1', 'tx_languagevisibility_fallbackorderel' => '0,1', 'tx_languagevisibility_defaultvisibility' => 'f', 'tx_languagevisibility_defaultvisibilityel' => 'f' ); |
||
151 | $language1 = new Language(); |
||
152 | $language1->setData($fixture); |
||
153 | return $language1; |
||
154 | } |
||
155 | |||
156 | function _fixture_getLanguageFourWithElementFallback() { |
||
0 ignored issues
–
show
|
|||
157 | $fixture = array('uid' => 2, 'tx_languagevisibility_fallbackorder' => '0,1', 'tx_languagevisibility_fallbackorderel' => '1', 'tx_languagevisibility_defaultvisibility' => 'f', 'tx_languagevisibility_defaultvisibilityel' => 'f' ); |
||
158 | $language4 = new Language(); |
||
159 | $language4->setData($fixture); |
||
160 | return $language4; |
||
161 | } |
||
162 | |||
163 | function _fixture_getElementWithDefaultVisibility() { |
||
0 ignored issues
–
show
|
|||
164 | //Create the element object fixture. |
||
165 | $_table = 'tt_content'; |
||
166 | $_uid = 9999; |
||
167 | $visibility = array('0' => '-', '1' => '-', '2' => '-' ); |
||
168 | $fixture = array('uid' => $_uid, 'sys_language_uid' => '0', 'tx_languagevisibility_visibility' => serialize($visibility) ); |
||
169 | $daostub = new DaoCommonStub(); |
||
170 | $daostub->stub_setRow($fixture, $_table); |
||
171 | |||
172 | $factory = new ElementFactory($daostub); |
||
173 | //get element from factory: |
||
174 | $element = $factory->getElementForTable($_table, $_uid); |
||
175 | return $element; |
||
176 | } |
||
177 | |||
178 | function _fixture_getElementWithLangOneVisibility() { |
||
0 ignored issues
–
show
|
|||
179 | //Create the element object fixture. |
||
180 | $_table = 'tt_content'; |
||
181 | $_uid = 9999; |
||
182 | $visibility = array('0' => '-', '1' => '-', '2' => '-' ); |
||
183 | $fixtureL1Rec = array('uid' => $_uid, 'l18n_parent' => $_uid - 1, 'sys_language_uid' => 1, 'tx_languagevisibility_visibility' => serialize($visibility) ); |
||
184 | $fixtureL0Rec = array('uid' => $_uid - 1, 'sys_language_uid' => 0 ); |
||
185 | $daostub = new DaoCommonStub(); |
||
186 | $daostub->stub_setRow($fixtureL1Rec, $_table); |
||
187 | $daostub->stub_setRow($fixtureL0Rec, $_table); |
||
188 | |||
189 | $factory = new ElementFactory($daostub); |
||
190 | //get element from factory: |
||
191 | $element = $factory->getElementForTable($_table, $_uid); |
||
192 | return $element; |
||
193 | } |
||
194 | |||
195 | function _fixture_getFCEElementWithDefaultVisibility() { |
||
0 ignored issues
–
show
|
|||
196 | //Create the element object fixture. |
||
197 | $_table = 'tt_content'; |
||
198 | $_uid = 9999; |
||
199 | $visibility = array('0' => '-', '1' => '-', '2' => '-' ); |
||
200 | $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" ?> |
||
201 | <T3FlexForms> |
||
202 | <data> |
||
203 | <sheet index="sDEF"> |
||
204 | <language index="lDEF"> |
||
205 | <field index="field_text"> |
||
206 | <value index="vDEF">free trial</value> |
||
207 | <value index="vEN">aust: free trial</value> |
||
208 | <value index="vPT"></value> |
||
209 | <value index="v_2"></value> |
||
210 | <value index="vZH"></value> |
||
211 | <value index="vFR"></value> |
||
212 | <value index="vDE"></value> |
||
213 | <value index="vJA"></value> |
||
214 | <value index="vES"></value> |
||
215 | </field> |
||
216 | <field index="field_smalltext"> |
||
217 | <value index="vDEF"></value> |
||
218 | <value index="vEN"></value> |
||
219 | <value index="vPT"></value> |
||
220 | <value index="v_2"></value> |
||
221 | <value index="vZH"></value> |
||
222 | <value index="vFR"></value> |
||
223 | <value index="vDE"></value> |
||
224 | <value index="vJA"></value> |
||
225 | <value index="vES"></value> |
||
226 | </field> |
||
227 | <field index="field_link"> |
||
228 | <value index="vDEF"></value> |
||
229 | <value index="vEN"></value> |
||
230 | <value index="vPT"></value> |
||
231 | <value index="v_2"></value> |
||
232 | <value index="vZH"></value> |
||
233 | <value index="vFR"></value> |
||
234 | <value index="vDE"></value> |
||
235 | <value index="vJA"></value> |
||
236 | <value index="vES"></value> |
||
237 | </field> |
||
238 | </language> |
||
239 | </sheet> |
||
240 | </data> |
||
241 | </T3FlexForms>' ); |
||
242 | $daostub = new DaoCommonStub(); |
||
243 | $daostub->stub_setRow($fixture, $_table); |
||
244 | |||
245 | $factory = new ElementFactory($daostub); |
||
246 | //get element from factory: |
||
247 | $element = $factory->getElementForTable($_table, $_uid); |
||
248 | return $element; |
||
249 | } |
||
250 | |||
251 | function _fixture_getPageElementWithDefaultVisibility() { |
||
0 ignored issues
–
show
|
|||
252 | //Create the element object fixture. |
||
253 | $_table = 'pages'; |
||
254 | $_uid = 99999999999; |
||
255 | $visibility = array('0' => '-', '1' => '-', '2' => '-' ); |
||
256 | $fixture = array('uid' => $_uid, 'tx_languagevisibility_visibility' => serialize($visibility), 'tx_languagevisibility_inheritanceflag_original' => 0, 'tx_languagevisibility_inheritanceflag_overlayed' => 0 ); |
||
257 | $daostub = new DaoCommonStub(); |
||
258 | $daostub->stub_setRow($fixture, $_table); |
||
259 | |||
260 | $factory = new ElementFactory($daostub); |
||
261 | //get element from factory: |
||
262 | $element = $factory->getElementForTable($_table, $_uid); |
||
263 | return $element; |
||
264 | } |
||
265 | |||
266 | function _fixture_getNewsElementWithDefaultVisibility() { |
||
0 ignored issues
–
show
|
|||
267 | //Create the element object fixture. |
||
268 | $_table = 'tt_news'; |
||
269 | $_uid = 99999; |
||
270 | $visibility = array('0' => '-', '1' => '-', '2' => '-' ); |
||
271 | $fixture = array('uid' => $_uid, 'tx_languagevisibility_visibility' => serialize($visibility), 'tx_languagevisibility_inheritanceflag_original' => 0, 'tx_languagevisibility_inheritanceflag_overlayed' => 0 ); |
||
272 | $daostub = new DaoCommonStub(); |
||
273 | $daostub->stub_setRow($fixture, $_table); |
||
274 | |||
275 | $factory = new ElementFactory($daostub); |
||
276 | //get element from factory: |
||
277 | $element = $factory->getElementForTable($_table, $_uid); |
||
278 | return $element; |
||
279 | } |
||
280 | } |
||
281 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.