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\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\Dao\DaoCommon; |
||
29 | use AOE\Languagevisibility\Dao\DaoCommonStub; |
||
30 | use AOE\Languagevisibility\ElementFactory; |
||
31 | use AOE\Languagevisibility\FceElement; |
||
32 | use AOE\Languagevisibility\FceOverlayElement; |
||
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 | * |
||
40 | * @author Daniel Pötzinger |
||
41 | */ |
||
42 | class ElementTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase { |
||
43 | |||
44 | /** |
||
45 | * @var array |
||
46 | */ |
||
47 | protected $coreExtensionsToLoad = array('version', 'workspaces'); |
||
48 | |||
49 | /** |
||
50 | * @var array |
||
51 | */ |
||
52 | protected $testExtensionsToLoad = array('typo3conf/ext/languagevisibility'); |
||
53 | |||
54 | function setUp() { |
||
0 ignored issues
–
show
|
|||
55 | $optionalExtensionKeys = array('static_info_tables', 'templavoila'); |
||
56 | foreach ($optionalExtensionKeys as $extensionKey) { |
||
57 | $extensionPath = 'typo3conf/ext/' . $extensionKey; |
||
58 | if (is_dir(ORIGINAL_ROOT . $extensionPath)) { |
||
59 | $this->testExtensionsToLoad[] = $extensionPath; |
||
60 | } |
||
61 | } |
||
62 | parent::setUp(); |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * @test |
||
67 | * @throws \UnexpectedValueException |
||
68 | */ |
||
69 | public function test_hasTranslation_pageelement() { |
||
70 | //this time data in DB is tested! |
||
71 | $this->_create_fixture_pagerecords(); |
||
72 | $this->_create_fixture_languagerecords(); |
||
73 | $_uid = 9990; |
||
74 | $_table = 'pages'; |
||
75 | |||
76 | $dao = new DaoCommon(); |
||
77 | $factory = new ElementFactory($dao); |
||
78 | |||
79 | //get element from factory: |
||
80 | $element = $factory->getElementForTable($_table, $_uid); |
||
81 | |||
82 | $this->assertTrue($element->hasTranslation('98'), 'element 9990 should have translation for language 98'); |
||
83 | $this->assertTrue($element->hasTranslation('0'), 'default translation should be there always'); |
||
84 | $this->assertEquals('page', $element->getFieldToUseForDefaultVisibility(), 'page element should return page as field to use for default visibility'); |
||
85 | $this->assertFalse($element->hasTranslation('99'), 'element 9990 should not be translated for 99!'); |
||
86 | } |
||
87 | |||
88 | public function test_hasTranslation_celement() { |
||
89 | $_table = 'tt_content'; |
||
90 | |||
91 | // this time data in DB is tested! |
||
92 | $this->_create_fixture_ttcontentrecords(); |
||
93 | $this->_create_fixture_languagerecords(); |
||
94 | |||
95 | $dao = new DaoCommon(); |
||
96 | $factory = new ElementFactory($dao); |
||
97 | |||
98 | // get element from factory: |
||
99 | $element = $factory->getElementForTable($_table, 9990); |
||
100 | |||
101 | $this->assertTrue($element->hasTranslation('98'), 'record should have translation'); |
||
102 | $this->assertTrue($element->hasTranslation('0'), 'default translation should always be there'); |
||
103 | $this->assertFalse($element->hasTranslation('99'), 'element 9992 should not be translated!'); |
||
104 | } |
||
105 | |||
106 | public function test_hasTranslation_normalfcelement() { |
||
107 | |||
108 | if (!in_array('typo3conf/ext/templavoila', $this->testExtensionsToLoad)) { |
||
109 | $this->markTestSkipped('This test needs templavoila being present and loaded'); |
||
110 | } |
||
111 | |||
112 | //this time data in DB is tested! |
||
113 | $this->_create_fixture_fcecontentrecord(); |
||
114 | $this->_create_fixture_fcedatastructures(); |
||
115 | $this->_create_static_inforecords(); |
||
116 | $this->_create_fixture_languagerecords(); |
||
117 | $_uid = 9992; |
||
118 | $_table = 'tt_content'; |
||
119 | |||
120 | $dao = new DaoCommon(); |
||
121 | $factory = new ElementFactory($dao); |
||
122 | |||
123 | //get element from factory: |
||
124 | $element = $factory->getElementForTable($_table, $_uid); |
||
125 | |||
126 | $this->assertEquals(TRUE, ($element instanceof FceElement), 'not object of type tx_languagevisibility_fcelement returned!'); |
||
127 | $this->assertEquals(TRUE, $element->hasTranslation('98'), 'record should have translation'); |
||
128 | $this->assertEquals(TRUE, $element->hasTranslation('0'), 'default transla should be there always'); |
||
129 | $this->assertEquals(FALSE, $element->hasTranslation('99'), 'element should not be translated!'); |
||
130 | |||
131 | } |
||
132 | |||
133 | public function test_hasTranslation_overlayfcelement() { |
||
134 | |||
135 | if (!in_array('typo3conf/ext/templavoila', $this->testExtensionsToLoad)) { |
||
136 | $this->markTestSkipped('This test needs templavoila being present and loaded'); |
||
137 | } |
||
138 | |||
139 | // this time data in DB is tested! |
||
140 | $this->_create_fixture_fcecontentrecordoverlay(); |
||
141 | $this->_create_fixture_fcedatastructures(); |
||
142 | $this->_create_fixture_languagerecords(); |
||
143 | $_uid = '9993'; |
||
144 | $_table = 'tt_content'; |
||
145 | |||
146 | $dao = new DaoCommon(); |
||
147 | $factory = new ElementFactory($dao); |
||
148 | |||
149 | //get element from factory: |
||
150 | $element = $factory->getElementForTable($_table, $_uid); |
||
151 | |||
152 | $this->assertTrue($element instanceof FceOverlayElement, 'not object of type tx_languagevisibility_fceoverlayelement returned!'); |
||
153 | $this->assertTrue($element->hasTranslation('98'), 'record should have translation'); |
||
154 | $this->assertTrue($element->hasTranslation('0'), 'default transla should be there always'); |
||
155 | |||
156 | $this->assertFalse($element->hasTranslation('99'), 'element should not be translated!'); |
||
157 | } |
||
158 | |||
159 | public function test_getLocalVisibilitySetting_celement() { |
||
160 | //this time data in DB is tested! |
||
161 | $_table = 'tt_content'; |
||
162 | $_uid = 1; |
||
163 | $visibility = array('0' => 'yes', '1' => t, '2' => '' ); |
||
164 | |||
165 | $fixture = array('uid' => $_uid, 'tx_languagevisibility_visibility' => serialize($visibility) ); |
||
166 | $daostub = new DaoCommonStub(); |
||
167 | $daostub->stub_setRow($fixture, $_table); |
||
168 | |||
169 | $factory = new ElementFactory($daostub); |
||
170 | |||
171 | //get element from factory: |
||
172 | $element = $factory->getElementForTable($_table, $_uid); |
||
173 | |||
174 | //test |
||
175 | $this->assertEquals($element->getLocalVisibilitySetting('1'), 't', 't expected'); |
||
176 | $this->assertEquals($element->getLocalVisibilitySetting('0'), 'yes', 'yes expected'); |
||
177 | } |
||
178 | |||
179 | /***************************************************************************************************** |
||
180 | ************************************ FICTURE Creation |
||
181 | ********************************************************************************************************/ |
||
182 | function fixture_getDefaultVisibilityArrayString() { |
||
0 ignored issues
–
show
|
|||
183 | return serialize(array('0' => '-', '98' => '-', '99' => '-' )); |
||
184 | } |
||
185 | |||
186 | function _create_fixture_ttcontentrecords() { |
||
0 ignored issues
–
show
|
|||
187 | $fields_values = array('uid' => 9990, 'pid' => 1, 'sys_language_uid' => 0, 'header' => 'test', 't3ver_oid' => '0', 't3ver_state' => '0', 'CType' => 'text', 'bodytext' => 'test', 'tx_languagevisibility_visibility' => $this->fixture_getDefaultVisibilityArrayString() ); |
||
188 | $GLOBALS['TYPO3_DB']->exec_DELETEquery('tt_content', 'uid=9990'); |
||
189 | $GLOBALS['TYPO3_DB']->exec_INSERTquery('tt_content', $fields_values); |
||
190 | |||
191 | $fields_values = array('uid' => 9991, 'pid' => 1, 'l18n_parent' => 9990, 'sys_language_uid' => 98, 'header' => 'test', 't3ver_oid' => '0', 't3ver_state' => '0', 'CType' => 'text', 'bodytext' => 'test_translated', 'tx_languagevisibility_visibility' => '' ); |
||
192 | $GLOBALS['TYPO3_DB']->exec_DELETEquery('tt_content', 'uid=9991'); |
||
193 | $GLOBALS['TYPO3_DB']->exec_INSERTquery('tt_content', $fields_values); |
||
194 | } |
||
195 | |||
196 | function _create_fixture_fcecontentrecord() { |
||
0 ignored issues
–
show
|
|||
197 | $fields_values = array('uid' => 9992, 'pid' => 1, 'sys_language_uid' => 0, 'header' => 'test', 'tx_templavoila_ds' => 9990, 'tx_templavoila_to' => 9990, 't3ver_oid' => '0', 't3ver_state' => '0', 'CType' => 'templavoila_pi1', 'bodytext' => '', 'tx_languagevisibility_visibility' => $this->fixture_getDefaultVisibilityArrayString(), 'tx_templavoila_flex' => file_get_contents(__DIR__ . '/Fixtures/fce_buttonelement_contentxml.xml') ); |
||
198 | |||
199 | $GLOBALS['TYPO3_DB']->exec_DELETEquery('tt_content', 'uid=9992'); |
||
200 | $GLOBALS['TYPO3_DB']->exec_INSERTquery('tt_content', $fields_values); |
||
201 | } |
||
202 | |||
203 | function _create_fixture_fcecontentrecordoverlay() { |
||
0 ignored issues
–
show
|
|||
204 | $fields_values = array('uid' => 9993, 'pid' => 1, 'sys_language_uid' => 0, 'header' => 'test', 'tx_templavoila_ds' => 9991, 'tx_templavoila_to' => 9991, 't3ver_oid' => '0', 't3ver_state' => '0', 'CType' => 'templavoila_pi1', 'bodytext' => '', 'tx_languagevisibility_visibility' => $this->fixture_getDefaultVisibilityArrayString(), 'tx_templavoila_flex' => file_get_contents(__DIR__ . '/Fixtures/fce_buttonelement_contentxml.xml') ); |
||
205 | $GLOBALS['TYPO3_DB']->exec_DELETEquery('tt_content', 'uid=9993'); |
||
206 | $GLOBALS['TYPO3_DB']->exec_INSERTquery('tt_content', $fields_values); |
||
207 | |||
208 | $fields_values = array('uid' => 9994, 'pid' => 1, 'l18n_parent' => 9993, 'sys_language_uid' => 98, 'header' => 'test', 'tx_templavoila_ds' => 9991, 'tx_templavoila_to' => 9991, 't3ver_oid' => '0', 't3ver_state' => '0', 'CType' => 'templavoila_pi1', 'bodytext' => '', 'tx_languagevisibility_visibility' => $this->fixture_getDefaultVisibilityArrayString(), 'tx_templavoila_flex' => file_get_contents(__DIR__ . '/Fixtures/fce_buttonelement_contentxml.xml') ); |
||
209 | $GLOBALS['TYPO3_DB']->exec_DELETEquery('tt_content', 'uid=9994'); |
||
210 | $GLOBALS['TYPO3_DB']->exec_INSERTquery('tt_content', $fields_values); |
||
211 | |||
212 | } |
||
213 | |||
214 | function _create_fixture_fcedatastructures() { |
||
0 ignored issues
–
show
|
|||
215 | $fields_values = array('uid' => 9990, 'pid' => 1, 'title' => 'testds for normal fces', 't3ver_oid' => '0', 't3ver_state' => '0', 'scope' => '2', 'dataprot' => file_get_contents(__DIR__ . '/Fixtures/fce_buttonelement_datastructure.xml') ); |
||
216 | $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_templavoila_datastructure', 'uid=9990'); |
||
217 | $GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_templavoila_datastructure', $fields_values); |
||
218 | |||
219 | $fields_values = array('uid' => 9990, 'pid' => 1, 'datastructure' => 9990, 'title' => 'testds for normal fces', 't3ver_oid' => '0', 't3ver_state' => '0' ); |
||
220 | $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_templavoila_tmplobj', 'uid=9990'); |
||
221 | $GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_templavoila_tmplobj', $fields_values); |
||
222 | |||
223 | //DS / TO 2 |
||
224 | //************************** |
||
225 | $fields_values = array('uid' => 9991, 'pid' => 1, 'title' => 'testds for overlay fces', 't3ver_oid' => '0', 't3ver_state' => '0', 'scope' => '2', 'dataprot' => file_get_contents(__DIR__ . '/Fixtures/fce_buttonelement_datastructure_useOverlay.xml') ); |
||
226 | $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_templavoila_datastructure', 'uid=9991'); |
||
227 | $GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_templavoila_datastructure', $fields_values); |
||
228 | |||
229 | $fields_values = array('uid' => 9991, 'pid' => 1, 'datastructure' => 9991, 'title' => 'testds for normal overlay fces', 't3ver_oid' => '0', 't3ver_state' => '0' ); |
||
230 | $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_templavoila_tmplobj', 'uid=9991'); |
||
231 | $GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_templavoila_tmplobj', $fields_values); |
||
232 | } |
||
233 | |||
234 | function _create_fixture_pagerecords() { |
||
0 ignored issues
–
show
|
|||
235 | $fields_values = array('uid' => 9990, 'pid' => 1, 'title' => 'test', 't3ver_oid' => '0', 't3ver_state' => '0', 'tx_languagevisibility_visibility' => $this->fixture_getDefaultVisibilityArrayString() ); |
||
236 | $GLOBALS['TYPO3_DB']->exec_DELETEquery('pages', 'uid=9990'); |
||
237 | $GLOBALS['TYPO3_DB']->exec_INSERTquery('pages', $fields_values); |
||
238 | |||
239 | $fields_values = array('uid' => 9990, 'pid' => 9990, 'sys_language_uid' => 98, 'title' => 'test_translated', 'tx_languagevisibility_visibility' => ''); |
||
240 | $GLOBALS['TYPO3_DB']->exec_DELETEquery('pages_language_overlay', 'uid=9990'); |
||
241 | $GLOBALS['TYPO3_DB']->exec_INSERTquery('pages_language_overlay', $fields_values); |
||
242 | |||
243 | } |
||
244 | |||
245 | function _create_fixture_languagerecords() { |
||
0 ignored issues
–
show
|
|||
246 | //normal language |
||
247 | $fields_values = array('uid' => 98, 'pid' => 0, 'static_lang_isocode' => '999', 'title' => 'testlanguage(translatedmode)', 'tx_languagevisibility_defaultvisibility' => 't', 'tx_languagevisibility_defaultvisibilityel' => 't' ); |
||
248 | |||
249 | $GLOBALS['TYPO3_DB']->exec_DELETEquery('sys_language', 'uid=98'); |
||
250 | $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_language', $fields_values); |
||
251 | //fallback language |
||
252 | $fields_values = array('uid' => 99, 'pid' => 0, 'title' => 'testlanguage(translatedmode)', 'tx_languagevisibility_defaultvisibility' => 'f', 'tx_languagevisibility_defaultvisibilityel' => 'f', 'tx_languagevisibility_fallbackorder' => '98' ); |
||
253 | |||
254 | $GLOBALS['TYPO3_DB']->exec_DELETEquery('sys_language', 'uid=99'); |
||
255 | $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_language', $fields_values); |
||
256 | |||
257 | } |
||
258 | |||
259 | function _create_static_inforecords() { |
||
0 ignored issues
–
show
|
|||
260 | $fields_values = array('uid' => 999, 'pid' => 0, 'lg_iso_2' => 'EN', 'lg_name_en' => 'English' ); |
||
261 | $GLOBALS['TYPO3_DB']->exec_DELETEquery('static_languages', 'uid=999'); |
||
262 | $GLOBALS['TYPO3_DB']->exec_INSERTquery('static_languages', $fields_values); |
||
263 | } |
||
264 | } |
||
265 |
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.