Changed quoting function for oracleDB.
[mediawiki.git] / tests / phpunit / includes / SeleniumConfigurationTest.php
blob4b49f639e811a42917fe1efec242e4e31b110dd3
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;
11 /**
12 * String containing the a sample selenium settings
14 private $testConfig0 = '
15 [SeleniumSettings]
16 browsers[firefox] = "*firefox"
17 browsers[iexplorer] = "*iexploreproxy"
18 browsers[chrome] = "*chrome"
19 host = "localhost"
20 port = "foobarr"
21 wikiUrl = "http://localhost/deployment"
22 username = "xxxxxxx"
23 userPassword = ""
24 testBrowser = "chrome"
25 startserver =
26 stopserver =
27 jUnitLogFile =
28 runAgainstGrid = false
30 [SeleniumTests]
31 testSuite[SimpleSeleniumTestSuite] = "tests/selenium/SimpleSeleniumTestSuite.php"
32 testSuite[TestSuiteName] = "testSuitePath"
34 /**
35 * Array of expected browsers from $testConfig0
37 private $testBrowsers0 = array( 'firefox' => '*firefox',
38 'iexplorer' => '*iexploreproxy',
39 'chrome' => '*chrome'
41 /**
42 * Array of expected selenium settings from $testConfig0
44 private $testSettings0 = array(
45 'host' => 'localhost',
46 'port' => 'foobarr',
47 'wikiUrl' => 'http://localhost/deployment',
48 'username' => 'xxxxxxx',
49 'userPassword' => '',
50 'testBrowser' => 'chrome',
51 'startserver' => null,
52 'stopserver' => null,
53 'seleniumserverexecpath' => null,
54 'jUnitLogFile' => null,
55 'runAgainstGrid' => null
57 /**
58 * Array of expected testSuites from $testConfig0
60 private $testSuites0 = array(
61 'SimpleSeleniumTestSuite' => 'tests/selenium/SimpleSeleniumTestSuite.php',
62 'TestSuiteName' => 'testSuitePath'
65 /**
66 * Another sample selenium settings file contents
68 private $testConfig1 =
70 [SeleniumSettings]
71 host = "localhost"
72 testBrowser = "firefox"
74 /**
75 * Expected browsers from $testConfig1
77 private $testBrowsers1 = null;
78 /**
79 * Expected selenium settings from $testConfig1
81 private $testSettings1 = array(
82 'host' => 'localhost',
83 'port' => null,
84 'wikiUrl' => null,
85 'username' => null,
86 'userPassword' => null,
87 'testBrowser' => 'firefox',
88 'startserver' => null,
89 'stopserver' => null,
90 'seleniumserverexecpath' => null,
91 'jUnitLogFile' => null,
92 'runAgainstGrid' => null
94 /**
95 * Expected test suites from $testConfig1
97 private $testSuites1 = null;
100 protected function setUp() {
101 parent::setUp();
102 if ( !defined( 'SELENIUMTEST' ) ) {
103 define( 'SELENIUMTEST', true );
108 * Clean up the temporary file used to store the selenium settings.
110 protected function tearDown() {
111 if ( strlen( $this->tempFileName ) > 0 ) {
112 unlink( $this->tempFileName );
113 unset( $this->tempFileName );
115 parent::tearDown();
119 * @expectedException MWException
120 * @group SeleniumFramework
122 public function testErrorOnIncorrectConfigFile() {
123 $seleniumSettings = array();
124 $seleniumBrowsers = array();
125 $seleniumTestSuites = array();
127 SeleniumConfig::getSeleniumSettings( $seleniumSettings,
128 $seleniumBrowsers,
129 $seleniumTestSuites,
130 "Some_fake_settings_file.ini" );
134 * @expectedException MWException
135 * @group SeleniumFramework
137 public function testErrorOnMissingConfigFile() {
138 $seleniumSettings = array();
139 $seleniumBrowsers = array();
140 $seleniumTestSuites = array();
141 $this->setMwGlobals( 'wgSeleniumConfigFile', '' );
143 SeleniumConfig::getSeleniumSettings( $seleniumSettings,
144 $seleniumBrowsers,
145 $seleniumTestSuites );
149 * @group SeleniumFramework
151 public function testUsesGlobalVarForConfigFile() {
152 $seleniumSettings = array();
153 $seleniumBrowsers = array();
154 $seleniumTestSuites = array();
155 $this->writeToTempFile( $this->testConfig0 );
156 $this->setMwGlobals( 'wgSeleniumConfigFile', $this->tempFileName );
158 SeleniumConfig::getSeleniumSettings( $seleniumSettings,
159 $seleniumBrowsers,
160 $seleniumTestSuites );
161 $this->assertEquals( $seleniumSettings, $this->testSettings0,
162 'The selenium settings should have been read from the file defined in $wgSeleniumConfigFile'
164 $this->assertEquals( $seleniumBrowsers, $this->testBrowsers0,
165 'The available browsers should have been read from the file defined in $wgSeleniumConfigFile'
167 $this->assertEquals( $seleniumTestSuites, $this->testSuites0,
168 'The test suites should have been read from the file defined in $wgSeleniumConfigFile'
173 * @group SeleniumFramework
174 * @dataProvider sampleConfigs
176 public function testgetSeleniumSettings( $sampleConfig, $expectedSettings, $expectedBrowsers, $expectedSuites ) {
177 $this->writeToTempFile( $sampleConfig );
178 $seleniumSettings = array();
179 $seleniumBrowsers = array();
180 $seleniumTestSuites = null;
182 SeleniumConfig::getSeleniumSettings( $seleniumSettings,
183 $seleniumBrowsers,
184 $seleniumTestSuites,
185 $this->tempFileName );
187 $this->assertEquals( $seleniumSettings, $expectedSettings,
188 "The selenium settings for the following test configuration was not retrieved correctly" . $sampleConfig
190 $this->assertEquals( $seleniumBrowsers, $expectedBrowsers,
191 "The available browsers for the following test configuration was not retrieved correctly" . $sampleConfig
193 $this->assertEquals( $seleniumTestSuites, $expectedSuites,
194 "The test suites for the following test configuration was not retrieved correctly" . $sampleConfig
199 * create a temp file and write text to it.
200 * @param $testToWrite the text to write to the temp file
202 private function writeToTempFile( $textToWrite ) {
203 $this->tempFileName = tempnam( sys_get_temp_dir(), 'test_settings.' );
204 $tempFile = fopen( $this->tempFileName, "w" );
205 fwrite( $tempFile, $textToWrite );
206 fclose( $tempFile );
210 * Returns an array containing:
211 * The contents of the selenium cingiguration ini file
212 * The expected selenium configuration array that getSeleniumSettings should return
213 * The expected available browsers array that getSeleniumSettings should return
214 * The expected test suites arrya that getSeleniumSettings should return
216 public function sampleConfigs() {
217 return array(
218 array( $this->testConfig0, $this->testSettings0, $this->testBrowsers0, $this->testSuites0 ),
219 array( $this->testConfig1, $this->testSettings1, $this->testBrowsers1, $this->testSuites1 )