Bug #20784 » 0011585_test.patch

Administrator Admin, 2009-07-27 15:39

View differences:

tests/t3lib/t3lib_matchcondition_testcase.php (Revision 0)
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
		$_SERVER['HTTP_USER_AGENT'] = 'Opera/9.25 (Windows NT 6.0; U; en)';
91

  
92
		$browserInfoHookMock = $this->getMock(uniqid('tx_browserInfoHook'), array('browserInfo'));
93
		$browserInfoHookMock->expects($this->atLeastOnce())->method('browserInfo');
94
		$this->matchCondition->hookObjectsArr = array($browserInfoHookMock);
95

  
96
		$this->matchCondition->match('[browser = msie] && [version = 7] && [system = winNT]');
97
	}
98
}
99
?>
(2-2/4)