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 =
17 browsers[firefox] = "*firefox"
18 browsers[iexplorer] = "*iexploreproxy"
19 browsers[chrome] = "*chrome"
22 wikiUrl = "http://localhost/deployment"
25 testBrowser = "chrome"
29 runAgainstGrid = false
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',
43 * Array of expected selenium settings from $testConfig0
45 private $testSettings0 = array(
46 'host' => 'localhost',
48 'wikiUrl' => 'http://localhost/deployment',
49 'username' => 'xxxxxxx',
51 'testBrowser' => 'chrome',
52 'startserver' => 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 =
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',
88 'userPassword' => null,
89 'testBrowser' => 'firefox',
90 'startserver' => null,
92 'seleniumserverexecpath' => null,
93 'jUnitLogFile' => null,
94 'runAgainstGrid' => null
97 * Expected test suites from $testConfig1
99 private $testSuites1 = null;
102 protected function setUp() {
104 if ( !defined( 'SELENIUMTEST' ) ) {
105 define( 'SELENIUMTEST', true );
110 * Clean up the temporary file used to store the selenium settings.
112 protected function tearDown() {
113 if ( strlen( $this->tempFileName
) > 0 ) {
114 unlink( $this->tempFileName
);
115 unset( $this->tempFileName
);
121 * @expectedException MWException
122 * @group SeleniumFramework
124 public function testErrorOnIncorrectConfigFile() {
125 $seleniumSettings = array();
126 $seleniumBrowsers = array();
127 $seleniumTestSuites = array();
129 SeleniumConfig
::getSeleniumSettings($seleniumSettings,
132 "Some_fake_settings_file.ini" );
137 * @expectedException MWException
138 * @group SeleniumFramework
140 public function testErrorOnMissingConfigFile() {
141 $seleniumSettings = array();
142 $seleniumBrowsers = array();
143 $seleniumTestSuites = array();
144 global $wgSeleniumConfigFile;
145 $wgSeleniumConfigFile = '';
146 SeleniumConfig
::getSeleniumSettings($seleniumSettings,
148 $seleniumTestSuites);
152 * @group SeleniumFramework
154 public function testUsesGlobalVarForConfigFile() {
155 $seleniumSettings = array();
156 $seleniumBrowsers = array();
157 $seleniumTestSuites = array();
158 global $wgSeleniumConfigFile;
159 $this->writeToTempFile( $this->testConfig0
);
160 $wgSeleniumConfigFile = $this->tempFileName
;
161 SeleniumConfig
::getSeleniumSettings($seleniumSettings,
163 $seleniumTestSuites);
164 $this->assertEquals($seleniumSettings, $this->testSettings0
,
165 'The selenium settings should have been read from the file defined in $wgSeleniumConfigFile'
167 $this->assertEquals($seleniumBrowsers, $this->testBrowsers0
,
168 'The available browsers should have been read from the file defined in $wgSeleniumConfigFile'
170 $this->assertEquals($seleniumTestSuites, $this->testSuites0
,
171 'The test suites should have been read from the file defined in $wgSeleniumConfigFile'
176 * @group SeleniumFramework
177 * @dataProvider sampleConfigs
179 public function testgetSeleniumSettings($sampleConfig, $expectedSettings, $expectedBrowsers, $expectedSuites ) {
180 $this->writeToTempFile( $sampleConfig );
181 $seleniumSettings = array();
182 $seleniumBrowsers = array();
183 $seleniumTestSuites = null;
185 SeleniumConfig
::getSeleniumSettings($seleniumSettings,
188 $this->tempFileName
);
190 $this->assertEquals($seleniumSettings, $expectedSettings,
191 "The selenium settings for the following test configuration was not retrieved correctly" . $sampleConfig
193 $this->assertEquals($seleniumBrowsers, $expectedBrowsers,
194 "The available browsers for the following test configuration was not retrieved correctly" . $sampleConfig
196 $this->assertEquals($seleniumTestSuites, $expectedSuites,
197 "The test suites for the following test configuration was not retrieved correctly" . $sampleConfig
204 * create a temp file and write text to it.
205 * @param $testToWrite the text to write to the temp file
207 private function writeToTempFile($textToWrite) {
208 $this->tempFileName
= tempnam(sys_get_temp_dir(), 'test_settings.');
209 $tempFile = fopen( $this->tempFileName
, "w" );
210 fwrite($tempFile , $textToWrite);
215 * Returns an array containing:
216 * The contents of the selenium cingiguration ini file
217 * The expected selenium configuration array that getSeleniumSettings should return
218 * The expected available browsers array that getSeleniumSettings should return
219 * The expected test suites arrya that getSeleniumSettings should return
221 public function sampleConfigs() {
223 array($this->testConfig0
, $this->testSettings0
, $this->testBrowsers0
, $this->testSuites0
),
224 array($this->testConfig1
, $this->testSettings1
, $this->testBrowsers1
, $this->testSuites1
)