Fixed dependencies for jquery.collapsibleTabs
[lhc/web/wiklou.git] / tests / phpunit / includes / SeleniumConfigurationTest.php
1 <?php
2
3 class SeleniumConfigurationTest extends MediaWikiTestCase {
4
5 /**
6 * The file where the test temporarity stores the selenium config.
7 * This should be cleaned up as part of teardown.
8 */
9 private $tempFileName;
10
11 /**
12 * String containing the a sample selenium settings
13 */
14 private $testConfig0 =
15 '
16 [SeleniumSettings]
17 browsers[firefox] = "*firefox"
18 browsers[iexplorer] = "*iexploreproxy"
19 browsers[chrome] = "*chrome"
20 host = "localhost"
21 port = "foobarr"
22 wikiUrl = "http://localhost/deployment"
23 username = "xxxxxxx"
24 userPassword = ""
25 testBrowser = "chrome"
26 startserver =
27 stopserver =
28 jUnitLogFile =
29 runAgainstGrid = false
30
31 [SeleniumTests]
32 testSuite[SimpleSeleniumTestSuite] = "tests/selenium/SimpleSeleniumTestSuite.php"
33 testSuite[TestSuiteName] = "testSuitePath"
34 ';
35 /**
36 * Array of expected browsers from $testConfig0
37 */
38 private $testBrowsers0 = array( 'firefox' => '*firefox',
39 'iexplorer' => '*iexploreproxy',
40 'chrome' => '*chrome'
41 );
42 /**
43 * Array of expected selenium settings from $testConfig0
44 */
45 private $testSettings0 = array(
46 'host' => 'localhost',
47 'port' => 'foobarr',
48 'wikiUrl' => 'http://localhost/deployment',
49 'username' => 'xxxxxxx',
50 'userPassword' => '',
51 'testBrowser' => 'chrome',
52 'startserver' => null,
53 'stopserver' => null,
54 'seleniumserverexecpath' => null,
55 'jUnitLogFile' => null,
56 'runAgainstGrid' => null
57 );
58 /**
59 * Array of expected testSuites from $testConfig0
60 */
61 private $testSuites0 = array(
62 'SimpleSeleniumTestSuite' => 'tests/selenium/SimpleSeleniumTestSuite.php',
63 'TestSuiteName' => 'testSuitePath'
64 );
65
66
67 /**
68 * Another sample selenium settings file contents
69 */
70 private $testConfig1 =
71 '
72 [SeleniumSettings]
73 host = "localhost"
74 testBrowser = "firefox"
75 ';
76 /**
77 * Expected browsers from $testConfig1
78 */
79 private $testBrowsers1 = null;
80 /**
81 * Expected selenium settings from $testConfig1
82 */
83 private $testSettings1 = array(
84 'host' => 'localhost',
85 'port' => null,
86 'wikiUrl' => null,
87 'username' => null,
88 'userPassword' => null,
89 'testBrowser' => 'firefox',
90 'startserver' => null,
91 'stopserver' => null,
92 'seleniumserverexecpath' => null,
93 'jUnitLogFile' => null,
94 'runAgainstGrid' => null
95 );
96 /**
97 * Expected test suites from $testConfig1
98 */
99 private $testSuites1 = null;
100
101
102 public function setUp() {
103 if ( !defined( 'SELENIUMTEST' ) ) {
104 define( 'SELENIUMTEST', true );
105 }
106 }
107
108 /**
109 * Clean up the temporary file used to store the selenium settings.
110 */
111 public function tearDown() {
112 if ( strlen( $this->tempFileName ) > 0 ) {
113 unlink( $this->tempFileName );
114 unset( $this->tempFileName );
115 }
116 parent::tearDown();
117 }
118
119 /**
120 * @expectedException MWException
121 * @group SeleniumFramework
122 */
123 public function testErrorOnIncorrectConfigFile() {
124 $seleniumSettings = array();
125 $seleniumBrowsers = array();
126 $seleniumTestSuites = array();
127
128 SeleniumConfig::getSeleniumSettings($seleniumSettings,
129 $seleniumBrowsers,
130 $seleniumTestSuites,
131 "Some_fake_settings_file.ini" );
132
133 }
134
135 /**
136 * @expectedException MWException
137 * @group SeleniumFramework
138 */
139 public function testErrorOnMissingConfigFile() {
140 $seleniumSettings = array();
141 $seleniumBrowsers = array();
142 $seleniumTestSuites = array();
143 global $wgSeleniumConfigFile;
144 $wgSeleniumConfigFile = '';
145 SeleniumConfig::getSeleniumSettings($seleniumSettings,
146 $seleniumBrowsers,
147 $seleniumTestSuites);
148 }
149
150 /**
151 * @group SeleniumFramework
152 */
153 public function testUsesGlobalVarForConfigFile() {
154 $seleniumSettings = array();
155 $seleniumBrowsers = array();
156 $seleniumTestSuites = array();
157 global $wgSeleniumConfigFile;
158 $this->writeToTempFile( $this->testConfig0 );
159 $wgSeleniumConfigFile = $this->tempFileName;
160 SeleniumConfig::getSeleniumSettings($seleniumSettings,
161 $seleniumBrowsers,
162 $seleniumTestSuites);
163 $this->assertEquals($seleniumSettings, $this->testSettings0 ,
164 'The selenium settings should have been read from the file defined in $wgSeleniumConfigFile'
165 );
166 $this->assertEquals($seleniumBrowsers, $this->testBrowsers0,
167 'The available browsers should have been read from the file defined in $wgSeleniumConfigFile'
168 );
169 $this->assertEquals($seleniumTestSuites, $this->testSuites0,
170 'The test suites should have been read from the file defined in $wgSeleniumConfigFile'
171 );
172 }
173
174 /**
175 * @group SeleniumFramework
176 * @dataProvider sampleConfigs
177 */
178 public function testgetSeleniumSettings($sampleConfig, $expectedSettings, $expectedBrowsers, $expectedSuites ) {
179 $this->writeToTempFile( $sampleConfig );
180 $seleniumSettings = array();
181 $seleniumBrowsers = array();
182 $seleniumTestSuites = null;
183
184 SeleniumConfig::getSeleniumSettings($seleniumSettings,
185 $seleniumBrowsers,
186 $seleniumTestSuites,
187 $this->tempFileName );
188
189 $this->assertEquals($seleniumSettings, $expectedSettings,
190 "The selenium settings for the following test configuration was not retrieved correctly" . $sampleConfig
191 );
192 $this->assertEquals($seleniumBrowsers, $expectedBrowsers,
193 "The available browsers for the following test configuration was not retrieved correctly" . $sampleConfig
194 );
195 $this->assertEquals($seleniumTestSuites, $expectedSuites,
196 "The test suites for the following test configuration was not retrieved correctly" . $sampleConfig
197 );
198
199
200 }
201
202 /**
203 * create a temp file and write text to it.
204 * @param $testToWrite the text to write to the temp file
205 */
206 private function writeToTempFile($textToWrite) {
207 $this->tempFileName = tempnam(sys_get_temp_dir(), 'test_settings.');
208 $tempFile = fopen( $this->tempFileName, "w" );
209 fwrite($tempFile , $textToWrite);
210 fclose($tempFile);
211 }
212
213 /**
214 * Returns an array containing:
215 * The contents of the selenium cingiguration ini file
216 * The expected selenium configuration array that getSeleniumSettings should return
217 * The expected available browsers array that getSeleniumSettings should return
218 * The expected test suites arrya that getSeleniumSettings should return
219 */
220 public function sampleConfigs() {
221 return array(
222 array($this->testConfig0, $this->testSettings0, $this->testBrowsers0, $this->testSuites0 ),
223 array($this->testConfig1, $this->testSettings1, $this->testBrowsers1, $this->testSuites1 )
224 );
225 }
226
227
228 }