1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AOE\Languagevisibility\Tests\Unit; |
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\Language; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Test case for checking the PHPUnit 3.1.9 |
31
|
|
|
* |
32
|
|
|
* WARNING: Never ever run a unit test like this on a live site! |
33
|
|
|
* |
34
|
|
|
* @author Daniel Pötzinger |
35
|
|
|
*/ |
36
|
|
|
class LanguageTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @return void |
40
|
|
|
*/ |
41
|
|
|
public function setUp() { |
42
|
|
|
unset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['languagevisibility']); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* |
47
|
|
|
* @test |
48
|
|
|
* @return void |
49
|
|
|
*/ |
50
|
|
|
public function getLanguageUidDB() { |
51
|
|
|
// Create the Array fixture. |
52
|
|
|
$fixture = array('uid' => 1 ); |
53
|
|
|
|
54
|
|
|
$language = new \AOE\Languagevisibility\Language(); |
55
|
|
|
$language->setData($fixture); |
56
|
|
|
|
57
|
|
|
// Assert that the size of the Array fixture is 0. |
58
|
|
|
$this->assertEquals(1, $language->getUid(), 'wrong uid 1'); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* |
63
|
|
|
* @test |
64
|
|
|
* @return void |
65
|
|
|
*/ |
66
|
|
|
public function getFallbackOrder() { |
67
|
|
|
|
68
|
|
|
$el = $this->getMockForAbstractClass('AOE\\Languagevisibility\\Element', array(), 'tx_languagevisibility_element_x', FALSE); |
69
|
|
|
|
70
|
|
|
// Create the Array fixture. |
71
|
|
|
$fixture = array('uid' => 1, 'tx_languagevisibility_complexfallbacksetting' => '0', 'tx_languagevisibility_fallbackorder' => '0,1,2', 'tx_languagevisibility_fallbackorderel' => '0,1', 'tx_languagevisibility_fallbackorderttnewsel' => '0,2' ); |
72
|
|
|
|
73
|
|
|
$language = new Language(); |
74
|
|
|
$language->setData($fixture); |
75
|
|
|
|
76
|
|
|
$this->assertEquals(array('0', '1', '2' ), $language->getFallbackOrder($el), "wrong getFallbackOrder"); |
77
|
|
|
$this->assertEquals(array('0', '1', '2' ), $language->getFallbackOrderElement($el), "wrong getFallbackOrder - complex applied where normal is excepted"); |
78
|
|
|
$this->assertEquals(array('0', '1', '2' ), $language->getFallbackOrderTTNewsElement($el), "wrong getFallbackOrder - complex applied where normal is excepted"); // Create the Array fixture. |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
$this->assertTrue($language->isLanguageUidInFallbackOrder(0, $el)); |
82
|
|
|
$this->assertTrue($language->isLanguageUidInFallbackOrder(2, $el)); |
83
|
|
|
$this->assertFalse($language->isLanguageUidInFallbackOrder(4711, $el)); |
84
|
|
|
|
85
|
|
|
$fixture = array('uid' => 1, 'tx_languagevisibility_complexfallbacksetting' => '1', 'tx_languagevisibility_fallbackorder' => '0,1,2', 'tx_languagevisibility_fallbackorderel' => '0,1', 'tx_languagevisibility_fallbackorderttnewsel' => '0,2' ); |
86
|
|
|
|
87
|
|
|
$language = new Language(); |
88
|
|
|
$language->setData($fixture); |
89
|
|
|
|
90
|
|
|
$this->assertEquals(array('0', '1', '2' ), $language->getFallbackOrder($el), "wrong getFallbackOrder"); |
91
|
|
|
$this->assertEquals(array('0', '1' ), $language->getFallbackOrderElement($el), "wrong getFallbackOrder"); |
92
|
|
|
$this->assertEquals(array('0', '2' ), $language->getFallbackOrderTTNewsElement($el), "wrong getFallbackOrder"); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* |
97
|
|
|
* @return void |
98
|
|
|
*/ |
99
|
|
|
public function canGetGlobalVisibility() { |
100
|
|
|
// Create the Array fixture. |
101
|
|
|
$fixture = array('uid' => 1, 'tx_languagevisibility_defaultvisibility' => 't', 'tx_languagevisibility_defaultvisibilityel' => 'f', 'tx_languagevisibility_defaultvisibilityttnewsel' => 'y' ); |
102
|
|
|
|
103
|
|
|
$language = new Language(); |
104
|
|
|
$language->setData($fixture); |
105
|
|
|
|
106
|
|
|
$this->assertEquals('y', $language->getDefaultVisibilityForTTNewsElement(), "wrong visibility"); |
|
|
|
|
107
|
|
|
$this->assertEquals('f', $language->getDefaultVisibilityForElement(), "wrong visibility"); |
|
|
|
|
108
|
|
|
$this->assertEquals('t', $language->getDefaultVisibilityForPage(), "wrong visibility"); |
|
|
|
|
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* |
113
|
|
|
* @test |
114
|
|
|
* @return void |
115
|
|
|
*/ |
116
|
|
|
public function getIsoCode() { |
117
|
|
|
// TODO ->getIsoCode should be refactored so that we do not need to mock internals |
118
|
|
|
// or remove this unit test altogether or move this to functional tests |
119
|
|
|
$databaseMock = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection'); |
120
|
|
|
$databaseMock->expects($this->once()) |
121
|
|
|
->method('exec_SELECTquery') |
122
|
|
|
->with('lg_iso_2', 'static_languages', 'uid=49', '', ''); |
123
|
|
|
$databaseMock->expects($this->once()) |
124
|
|
|
->method('sql_fetch_assoc') |
125
|
|
|
->will($this->returnValue(array('lg_iso_2' => 'HE'))); |
126
|
|
|
$GLOBALS['TYPO3_DB'] = $databaseMock; |
127
|
|
|
|
128
|
|
|
// Create the Array fixture. |
129
|
|
|
$fixture = array('uid' => 1, 'static_lang_isocode' => '49' ); |
130
|
|
|
|
131
|
|
|
$language = new Language(); |
132
|
|
|
$language->setData($fixture); |
133
|
|
|
|
134
|
|
|
// Assert that the size of the Array fixture is 0. |
135
|
|
|
$this->assertEquals('HE', $language->getIsoCode(), "wrong getIsoCode"); |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|
This check looks for function calls that miss required arguments.