Added test #11626: Extend unit tests for t3lib_matchCondition globalVar comparison
[Packages/TYPO3.CMS.git] / tests / t3lib / t3lib_matchcondition_testcase.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 Oliver Hader <oliver@typo3.org>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25
26 /**
27 * Testcase for class t3lib_matchCondition.
28 *
29 * @author Oliver Hader <oliver@typo3.org>
30 * @package TYPO3
31 * @subpackage t3lib
32 */
33 class t3lib_matchCondition_testcase extends tx_phpunit_testcase {
34 /**
35 * @var boolean
36 */
37 protected $backupGlobals = true;
38
39 /**
40 * @var array
41 */
42 private $backupServer;
43
44 /**
45 * @var t3lib_matchCondition
46 */
47 private $matchCondition;
48
49 public function setUp() {
50 $this->backupServer = $_SERVER;
51 $this->matchCondition = t3lib_div::makeInstance('t3lib_matchCondition');
52 }
53
54 public function tearDown() {
55 unset($this->matchCondition);
56 $_SERVER = $this->backupServer;
57 }
58
59 /**
60 * Tests whether a condition matches Internet Explorer 7 on Windows.
61 *
62 * @return void
63 * @test
64 */
65 public function conditionMatchesInternetExplorer7Windows() {
66 $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)';
67 $result = $this->matchCondition->match('[browser = msie] && [version = 7] && [system = winNT]');
68 $this->assertTrue($result);
69 }
70
71 /**
72 * Tests whether a condition does not match Internet Explorer 7 on Windows.
73 *
74 * @return void
75 * @test
76 */
77 public function conditionDoesNotMatchInternetExplorer7Windows() {
78 $_SERVER['HTTP_USER_AGENT'] = 'Opera/9.25 (Windows NT 6.0; U; en)';
79 $result = $this->matchCondition->match('[browser = msie] && [version = 7] && [system = winNT]');
80 $this->assertFalse($result);
81 }
82
83 /**
84 * Tests whether the browserInfo hook is called.
85 *
86 * @return void
87 * @test
88 */
89 public function browserInfoHookIsCalled() {
90 $browserInfoHookMock = $this->getMock(uniqid('tx_browserInfoHook'), array('browserInfo'));
91 $browserInfoHookMock->expects($this->atLeastOnce())->method('browserInfo');
92 $this->matchCondition->hookObjectsArr = array($browserInfoHookMock);
93
94 $this->matchCondition->match('[browser = msie] && [version = 7] && [system = winNT]');
95 }
96
97 /**
98 * Tests whether numerical comparison matches.
99 * @test
100 */
101 public function conditionMatchesOnEqualExpression() {
102 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 = 10]'));
103 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 = 10.1]'));
104
105 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 == 10]'));
106 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 == 10.1]'));
107 }
108
109 /**
110 * Tests whether numerical comparison matches.
111 * @test
112 */
113 public function conditionMatchesOnNotEqualExpression() {
114 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 != 20]'));
115 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 != 10.2]'));
116 }
117
118 /**
119 * Tests whether numerical comparison matches.
120 * @test
121 */
122 public function conditionMatchesOnLowerThanExpression() {
123 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 < 20]'));
124 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 < 10.2]'));
125 }
126
127 /**
128 * Tests whether numerical comparison matches.
129 * @test
130 */
131 public function conditionMatchesOnLowerThanOrEqualExpression() {
132 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 <= 10]'));
133 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 <= 20]'));
134
135 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 <= 10.1]'));
136 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 <= 10.2]'));
137 }
138
139 /**
140 * Tests whether numerical comparison matches.
141 * @test
142 */
143 public function conditionMatchesOnGreaterThanExpression() {
144 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:20 > 10]'));
145 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.2 > 10.1]'));
146 }
147
148 /**
149 * Tests whether numerical comparison matches.
150 * @test
151 */
152 public function conditionMatchesOnGreaterThanOrEqualExpression() {
153 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 >= 10]'));
154 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:20 >= 10]'));
155
156 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 >= 10.1]'));
157 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.2 >= 10.1]'));
158 }
159 }
160 ?>