* upgrade patches for oracle 1.17->1.19
[mediawiki.git] / tests / phpunit / includes / SeleniumConfigurationTest.php
blob750524ebb668b181cccc72cd1f0cc11a401739ec
1 <?php
3 class SeleniumConfigurationTest extends MediaWikiTestCase {
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;
12 * String containing the a sample selenium settings
14 private $testConfig0 =
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
31 [SeleniumTests]
32 testSuite[SimpleSeleniumTestSuite] = "tests/selenium/SimpleSeleniumTestSuite.php"
33 testSuite[TestSuiteName] = "testSuitePath"
36 * Array of expected browsers from $testConfig0
38 private $testBrowsers0 = array( 'firefox' => '*firefox',
39 'iexplorer' => '*iexploreproxy',
40 'chrome' => '*chrome'
43 * Array of expected selenium settings from $testConfig0
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
59 * Array of expected testSuites from $testConfig0
61 private $testSuites0 = array(
62 'SimpleSeleniumTestSuite' => 'tests/selenium/SimpleSeleniumTestSuite.php',
63 'TestSuiteName' => 'testSuitePath'
68 * Another sample selenium settings file contents
70 private $testConfig1 =
72 [SeleniumSettings]
73 host = "localhost"
74 testBrowser = "firefox"
77 * Expected browsers from $testConfig1
79 private $testBrowsers1 = null;
81 * Expected selenium settings from $testConfig1
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
97 * Expected test suites from $testConfig1
99 private $testSuites1 = null;
102 public function setUp() {
103 if ( !defined( 'SELENIUMTEST' ) ) {
104 define( 'SELENIUMTEST', true );
109 * Clean up the temporary file used to store the selenium settings.
111 public function tearDown() {
112 if ( strlen( $this->tempFileName ) > 0 ) {
113 unlink( $this->tempFileName );
114 unset( $this->tempFileName );
116 parent::tearDown();
120 * @expectedException MWException
121 * @group SeleniumFramework
123 public function testErrorOnIncorrectConfigFile() {
124 $seleniumSettings = array();
125 $seleniumBrowsers = array();
126 $seleniumTestSuites = array();
128 SeleniumConfig::getSeleniumSettings($seleniumSettings,
129 $seleniumBrowsers,
130 $seleniumTestSuites,
131 "Some_fake_settings_file.ini" );
136 * @expectedException MWException
137 * @group SeleniumFramework
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);
151 * @group SeleniumFramework
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'
166 $this->assertEquals($seleniumBrowsers, $this->testBrowsers0,
167 'The available browsers should have been read from the file defined in $wgSeleniumConfigFile'
169 $this->assertEquals($seleniumTestSuites, $this->testSuites0,
170 'The test suites should have been read from the file defined in $wgSeleniumConfigFile'
175 * @group SeleniumFramework
176 * @dataProvider sampleConfigs
178 public function testgetSeleniumSettings($sampleConfig, $expectedSettings, $expectedBrowsers, $expectedSuites ) {
179 $this->writeToTempFile( $sampleConfig );
180 $seleniumSettings = array();
181 $seleniumBrowsers = array();
182 $seleniumTestSuites = null;
184 SeleniumConfig::getSeleniumSettings($seleniumSettings,
185 $seleniumBrowsers,
186 $seleniumTestSuites,
187 $this->tempFileName );
189 $this->assertEquals($seleniumSettings, $expectedSettings,
190 "The selenium settings for the following test configuration was not retrieved correctly" . $sampleConfig
192 $this->assertEquals($seleniumBrowsers, $expectedBrowsers,
193 "The available browsers for the following test configuration was not retrieved correctly" . $sampleConfig
195 $this->assertEquals($seleniumTestSuites, $expectedSuites,
196 "The test suites for the following test configuration was not retrieved correctly" . $sampleConfig
203 * create a temp file and write text to it.
204 * @param $testToWrite the text to write to the temp file
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);
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
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 )