3 class SeleniumConfigurationTest
extends MediaWikiTestCase
{
6 * The file where the test temporarity stores the selenium config.
7 * This should be cleaned up as part of teardown.
12 * String containing the a sample selenium settings
14 private $testConfig0 = '
16 browsers[firefox] = "*firefox"
17 browsers[iexplorer] = "*iexploreproxy"
18 browsers[chrome] = "*chrome"
21 wikiUrl = "http://localhost/deployment"
24 testBrowser = "chrome"
28 runAgainstGrid = false
31 testSuite[SimpleSeleniumTestSuite] = "tests/selenium/SimpleSeleniumTestSuite.php"
32 testSuite[TestSuiteName] = "testSuitePath"
35 * Array of expected browsers from $testConfig0
37 private $testBrowsers0 = array( 'firefox' => '*firefox',
38 'iexplorer' => '*iexploreproxy',
42 * Array of expected selenium settings from $testConfig0
44 private $testSettings0 = array(
45 'host' => 'localhost',
47 'wikiUrl' => 'http://localhost/deployment',
48 'username' => 'xxxxxxx',
50 'testBrowser' => 'chrome',
51 'startserver' => null,
53 'seleniumserverexecpath' => null,
54 'jUnitLogFile' => null,
55 'runAgainstGrid' => null
58 * Array of expected testSuites from $testConfig0
60 private $testSuites0 = array(
61 'SimpleSeleniumTestSuite' => 'tests/selenium/SimpleSeleniumTestSuite.php',
62 'TestSuiteName' => 'testSuitePath'
66 * Another sample selenium settings file contents
68 private $testConfig1 =
72 testBrowser = "firefox"
75 * Expected browsers from $testConfig1
77 private $testBrowsers1 = null;
79 * Expected selenium settings from $testConfig1
81 private $testSettings1 = array(
82 'host' => 'localhost',
86 'userPassword' => null,
87 'testBrowser' => 'firefox',
88 'startserver' => null,
90 'seleniumserverexecpath' => null,
91 'jUnitLogFile' => null,
92 'runAgainstGrid' => null
95 * Expected test suites from $testConfig1
97 private $testSuites1 = null;
100 protected function 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
);
119 * @expectedException MWException
120 * @group SeleniumFramework
122 public function testErrorOnIncorrectConfigFile() {
123 $seleniumSettings = array();
124 $seleniumBrowsers = array();
125 $seleniumTestSuites = array();
127 SeleniumConfig
::getSeleniumSettings( $seleniumSettings,
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,
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,
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,
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 );
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() {
218 array( $this->testConfig0
, $this->testSettings0
, $this->testBrowsers0
, $this->testSuites0
),
219 array( $this->testConfig1
, $this->testSettings1
, $this->testBrowsers1
, $this->testSuites1
)