2 /***************************************************************
5 * (c) 2009 Oliver Hader <oliver@typo3.org>
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.
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
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.
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
27 * Testcase for class t3lib_matchCondition.
29 * @author Oliver Hader <oliver@typo3.org>
33 class t3lib_matchCondition_testcase
extends tx_phpunit_testcase
{
37 protected $backupGlobals = true;
42 private $backupServer;
45 * @var t3lib_matchCondition
47 private $matchCondition;
49 public function setUp() {
50 $this->backupServer
= $_SERVER;
51 $this->matchCondition
= t3lib_div
::makeInstance('t3lib_matchCondition');
54 public function tearDown() {
55 unset($this->matchCondition
);
56 $_SERVER = $this->backupServer
;
60 * Tests whether a condition matches Internet Explorer 7 on Windows.
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);
72 * Tests whether a condition does not match Internet Explorer 7 on Windows.
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);
84 * Tests whether the browserInfo hook is called.
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);
94 $this->matchCondition
->match('[browser = msie] && [version = 7] && [system = winNT]');
98 * Tests whether numerical comparison matches.
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]'));
105 $this->assertTrue($this->matchCondition
->match('[globalVar = LIT:10 == 10]'));
106 $this->assertTrue($this->matchCondition
->match('[globalVar = LIT:10.1 == 10.1]'));
110 * Tests whether numerical comparison matches.
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]'));
119 * Tests whether numerical comparison matches.
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]'));
128 * Tests whether numerical comparison matches.
131 public function conditionMatchesOnLowerThanOrEqualExpression() {
132 $this->assertTrue($this->matchCondition
->match('[globalVar = LIT:10 <= 10]'));
133 $this->assertTrue($this->matchCondition
->match('[globalVar = LIT:10 <= 20]'));
135 $this->assertTrue($this->matchCondition
->match('[globalVar = LIT:10.1 <= 10.1]'));
136 $this->assertTrue($this->matchCondition
->match('[globalVar = LIT:10.1 <= 10.2]'));
140 * Tests whether numerical comparison matches.
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]'));
149 * Tests whether numerical comparison matches.
152 public function conditionMatchesOnGreaterThanOrEqualExpression() {
153 $this->assertTrue($this->matchCondition
->match('[globalVar = LIT:10 >= 10]'));
154 $this->assertTrue($this->matchCondition
->match('[globalVar = LIT:20 >= 10]'));
156 $this->assertTrue($this->matchCondition
->match('[globalVar = LIT:10.1 >= 10.1]'));
157 $this->assertTrue($this->matchCondition
->match('[globalVar = LIT:10.2 >= 10.1]'));