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

_create_fixture_fcecontentrecordoverlay()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

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