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

canNotGetElementOfUnsupportedTable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
rs 9.4285
cc 1
eloc 9
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\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 tx_languagevisibility_element returned!");
72
		$this->assertTrue($element instanceof PageElement, "not object of type tx_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('tx_languagevisibility_daocommon');
106
107
		/* @var $factory tx_languagevisibility_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 tx_languagevisibility_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  tx_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 tx_languagevisibility_element returned!");
165
		$this->assertTrue($element instanceof TtnewsElement, "not object of type tx_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 instanciation an catch expected exception
188
		try {
189
			$element = $factory->getElementForTable($_table, $_uid);
0 ignored issues
show
Unused Code introduced by
$element is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
190
		} catch ( Exception $e ) {
0 ignored issues
show
Bug introduced by
The class AOE\Languagevisibility\Tests\Functional\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
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 tx_languagevisibility_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