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
|
|
|
use AOE\Languagevisibility\CElement; |
28
|
|
|
use AOE\Languagevisibility\Dao\DaoCommonStub; |
29
|
|
|
use AOE\Languagevisibility\Element; |
30
|
|
|
use AOE\Languagevisibility\ElementFactory; |
31
|
|
|
use AOE\Languagevisibility\FceElement; |
32
|
|
|
use AOE\Languagevisibility\PageElement; |
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 ElementFactoryTest 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
|
|
|
/** |
55
|
|
|
* |
56
|
|
|
* @test |
57
|
|
|
*/ |
58
|
|
|
public function getElementForTable_pageelement() { |
59
|
|
|
// Create the Array fixture. |
60
|
|
|
$uid = 1; |
61
|
|
|
$table = 'pages'; |
62
|
|
|
$fixture = array('uid' => $uid ); |
63
|
|
|
$daoStub = new DaoCommonStub(); |
64
|
|
|
$daoStub->stub_setRow($fixture, $table); |
65
|
|
|
|
66
|
|
|
//get element from factory: |
67
|
|
|
$factory = new ElementFactory($daoStub); |
68
|
|
|
$element = $factory->getElementForTable($table, $uid); |
69
|
|
|
|
70
|
|
|
$this->assertEquals($element->getTable(), 'pages'); |
71
|
|
|
$this->assertTrue($element instanceof Element, 'not object of type \AOE\Languagevisibility\Element returned!'); |
72
|
|
|
$this->assertTrue($element instanceof PageElement, 'not object of type \AOE\Languagevisibility\PageElement returned!'); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* |
77
|
|
|
* @test |
78
|
|
|
*/ |
79
|
|
|
public function getElementForTable_celement() { |
80
|
|
|
// Create the Array fixture. |
81
|
|
|
$_uid = 1; |
82
|
|
|
$_table = 'tt_content'; |
83
|
|
|
|
84
|
|
|
$fixture = array('uid' => $_uid ); |
85
|
|
|
$daostub = new DaoCommonStub(); |
86
|
|
|
$daostub->stub_setRow($fixture, $_table); |
87
|
|
|
|
88
|
|
|
$factory = new ElementFactory($daostub); |
89
|
|
|
|
90
|
|
|
$element = $factory->getElementForTable($_table, $_uid); |
91
|
|
|
|
92
|
|
|
$this->assertEquals($element->getTable(), 'tt_content'); |
93
|
|
|
$this->assertTrue($element instanceof Element, "not object of type tx_languagevisibility_element returned!"); |
94
|
|
|
$this->assertTrue($element instanceof CElement, "not object of type tx_languagevisibility_celement returned!"); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* |
99
|
|
|
* @test |
100
|
|
|
*/ |
101
|
|
|
public function canCreateDraftWorkspaceElementFromLiveWorkspaceUidInWorkspaceContext() { |
102
|
|
|
$this->importDataSet(__DIR__ . '/Fixtures/getLiveWorkspaceElementFromWorkspaceUid.xml'); |
103
|
|
|
|
104
|
|
|
$GLOBALS['BE_USER'] = $this->getMock('TYPO3\\CMS\\Core\\Authentication\\BackendUserAuthentication'); |
105
|
|
|
$dao = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('AOE\\Languagevisibility\\Dao\\DaoCommon'); |
106
|
|
|
|
107
|
|
|
/* @var $factory ElementFactory */ |
108
|
|
|
$factory = new ElementFactory($dao); |
109
|
|
|
|
110
|
|
|
//store context |
111
|
|
|
$oldWS = $GLOBALS['BE_USER']->workspace; |
112
|
|
|
$GLOBALS['BE_USER']->workspace = 12; |
113
|
|
|
|
114
|
|
|
/* @var $element CElement */ |
115
|
|
|
$element = $factory->getElementForTable('tt_content', 10); |
116
|
|
|
$this->assertEquals($element->getTitle(), 'WS header'); |
117
|
|
|
|
118
|
|
|
//restore context |
119
|
|
|
$GLOBALS['BE_USER']->workspace = $oldWS; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* |
124
|
|
|
* @test |
125
|
|
|
*/ |
126
|
|
|
public function getElementForTable_fcelement() { |
127
|
|
|
// Create the Array fixture. |
128
|
|
|
$_uid = 1; |
129
|
|
|
$_table = 'tt_content'; |
130
|
|
|
|
131
|
|
|
$fixture = array('uid' => $_uid, 'CType' => 'templavoila_pi1' ); |
132
|
|
|
$daostub = new DaoCommonStub(); |
133
|
|
|
$daostub->stub_setRow($fixture, $_table); |
134
|
|
|
|
135
|
|
|
$factory = new ElementFactory($daostub); |
136
|
|
|
|
137
|
|
|
$element = $factory->getElementForTable($_table, $_uid); |
138
|
|
|
|
139
|
|
|
$this->assertEquals($element->getTable(), 'tt_content'); |
140
|
|
|
$this->assertTrue($element instanceof Element, "not object of type tx_languagevisibility_element returned!"); |
141
|
|
|
$this->assertTrue($element instanceof FceElement, "not object of type tx_languagevisibility_fcelement returned!"); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Test to ensure the factory delivers an instance for a tt_news element. |
146
|
|
|
* |
147
|
|
|
* @test |
148
|
|
|
*/ |
149
|
|
|
public function canGetElementForTTNEWS() { |
150
|
|
|
// Create the Array fixture. |
151
|
|
|
$uid = 1; |
152
|
|
|
$table = 'tt_news'; |
153
|
|
|
|
154
|
|
|
$fixture = array('uid' => $uid, 'title' => 'news' ); |
155
|
|
|
$daoStub = new DaoCommonStub(); |
156
|
|
|
$daoStub->stub_setRow($fixture, $table); |
157
|
|
|
|
158
|
|
|
$factory = new ElementFactory($daoStub); |
159
|
|
|
|
160
|
|
|
/* @var $element \AOE\Languagevisibility\TtnewsElement */ |
161
|
|
|
$element = $factory->getElementForTable($table, $uid); |
162
|
|
|
|
163
|
|
|
$this->assertEquals($element->getTable(), 'tt_news'); |
164
|
|
|
$this->assertTrue($element instanceof Element, 'not object of type AOE\Languagevisibility\Element returned!'); |
165
|
|
|
$this->assertTrue($element instanceof TtnewsElement, get_class($element) . ':not object of type AOE\Languagevisibility\TtnewsElement returned!'); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Records elements store theire translation in the same table. The factory class should |
170
|
|
|
* not allow to get an element from this table which is an overlay. |
171
|
|
|
* |
172
|
|
|
* @test |
173
|
|
|
*/ |
174
|
|
|
public function canNotGetElementForOverlayElement() { |
175
|
|
|
$uid = 1; |
176
|
|
|
$table = 'tt_content'; |
177
|
|
|
|
178
|
|
|
//create fixture element |
179
|
|
|
$fixture = array('uid' => 1, 'title' => 'overlay', 'sys_language_uid' => 1, 'l18n_parent' => 12 ); |
180
|
|
|
$daoStub = new DaoCommonStub(); |
181
|
|
|
$daoStub->stub_setRow($fixture, 'tt_content'); |
182
|
|
|
|
183
|
|
|
$factory = new ElementFactory($daoStub); |
184
|
|
|
|
185
|
|
|
$exceptionCatched = FALSE; |
186
|
|
|
|
187
|
|
|
//try instantiation an catch expected exception |
188
|
|
|
try { |
189
|
|
|
$factory->getElementForTable($table, $uid); |
190
|
|
|
} catch ( \Exception $e ) { |
191
|
|
|
$exceptionCatched = TRUE; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
$this->assertTrue($exceptionCatched, 'Error: Factory can create instance of overlay element'); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* This testcase is used to test that an element from an unsupported table can |
199
|
|
|
* not be created. |
200
|
|
|
* |
201
|
|
|
* @test |
202
|
|
|
* @expectedException \UnexpectedValueException |
203
|
|
|
*/ |
204
|
|
|
public function canNotGetElementOfUnsupportedTable() { |
205
|
|
|
$_uid = 4711; |
206
|
|
|
$_table = 'tx_notexisting'; |
207
|
|
|
$fixture = array('uid' => $_uid, 'title' => 'record' ); |
208
|
|
|
$daostub = new DaoCommonStub(); |
209
|
|
|
$daostub->stub_setRow($fixture, 'tx_notexisting'); |
210
|
|
|
|
211
|
|
|
/* @var $factory ElementFactory */ |
212
|
|
|
$factory = new ElementFactory($daostub); |
213
|
|
|
|
214
|
|
|
$element = $factory->getElementForTable($_table, $_uid); |
215
|
|
|
|
216
|
|
|
$this->assertNull($element, 'Element should be null'); |
217
|
|
|
} |
218
|
|
|
} |
219
|
|
|
|