3 class SeleniumConfigurationTest
extends PHPUnit_Framework_TestCase
{
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"
28 testSuite[SimpleSeleniumTestSuite] = "maintenance/tests/selenium/SimpleSeleniumTestSuite.php"
29 testSuite[TestSuiteName] = "testSuitePath"
32 * Array of expected browsers from $testConfig0
34 private $testBrowsers0 = array( 'firefox' => '*firefox',
35 'iexplorer' => '*iexploreproxy',
39 * Array of expected selenium settings from $testConfig0
41 private $testSettings0 = array(
42 'host' => 'localhost',
44 'wikiUrl' => 'http://localhost/deployment',
45 'username' => 'xxxxxxx',
47 'testBrowser' => 'chrome'
50 * Array of expected testSuites from $testConfig0
52 private $testSuites0 = array(
53 'SimpleSeleniumTestSuite' => 'maintenance/tests/selenium/SimpleSeleniumTestSuite.php',
54 'TestSuiteName' => 'testSuitePath'
59 * Another sample selenium settings file contents
61 private $testConfig1 =
65 testBrowser = "firefox"
68 * Expected browsers from $testConfig1
70 private $testBrowsers1 = null;
72 * Expected selenium settings from $testConfig1
74 private $testSettings1 = array(
75 'host' => 'localhost',
79 'userPassword' => null,
80 'testBrowser' => 'firefox'
83 * Expected test suites from $testConfig1
85 private $testSuites1 = null;
88 public function setUp() {
89 if ( !defined( 'SELENIUMTEST' ) ) {
90 define( 'SELENIUMTEST', true );
95 * Clean up the temporary file used to store the selenium settings.
97 public function tearDown() {
98 if ( strlen( $this->tempFileName
) > 0 ) {
99 unlink( $this->tempFileName
);
100 unset( $this->tempFileName
);
106 * @expectedException MWException
107 * @group SeleniumFramework
109 public function testErrorOnIncorrectConfigFile() {
114 SeleniumConfig
::getSeleniumSettings($seleniumSettings,
117 "Some_fake_settings_file.ini" );
122 * @expectedException MWException
123 * @group SeleniumFramework
125 public function testErrorOnMissingConfigFile() {
129 global $wgSeleniumConfigFile;
130 $wgSeleniumConfigFile = '';
131 SeleniumConfig
::getSeleniumSettings($seleniumSettings,
133 $seleniumTestSuites);
137 * @group SeleniumFramework
139 public function testUsesGlobalVarForConfigFile() {
143 global $wgSeleniumConfigFile;
144 $this->writeToTempFile( $this->testConfig0
);
145 $wgSeleniumConfigFile = $this->tempFileName
;
146 SeleniumConfig
::getSeleniumSettings($seleniumSettings,
148 $seleniumTestSuites);
149 $this->assertEquals($seleniumSettings, $this->testSettings0
,
150 'The selenium settings should have been read from the file defined in $wgSeleniumConfigFile'
152 $this->assertEquals($seleniumBrowsers, $this->testBrowsers0
,
153 'The available browsers should have been read from the file defined in $wgSeleniumConfigFile'
155 $this->assertEquals($seleniumTestSuites, $this->testSuites0
,
156 'The test suites should have been read from the file defined in $wgSeleniumConfigFile'
161 * @group SeleniumFramework
162 * @dataProvider sampleConfigs
164 public function testgetSeleniumSettings($sampleConfig, $expectedSettings, $expectedBrowsers, $expectedSuites ) {
165 $this->writeToTempFile( $sampleConfig );
170 SeleniumConfig
::getSeleniumSettings($seleniumSettings,
173 $this->tempFileName
);
175 $this->assertEquals($seleniumSettings, $expectedSettings,
176 "The selenium settings for the following test configuration was not retrieved correctly" . $sampleConfig
178 $this->assertEquals($seleniumBrowsers, $expectedBrowsers,
179 "The available browsers for the following test configuration was not retrieved correctly" . $sampleConfig
181 $this->assertEquals($seleniumTestSuites, $expectedSuites,
182 "The test suites for the following test configuration was not retrieved correctly" . $sampleConfig
189 * create a temp file and write text to it.
190 * @param $testToWrite the text to write to the temp file
192 private function writeToTempFile($textToWrite) {
193 $this->tempFileName
= tempnam(sys_get_temp_dir(), 'test_settings.');
194 $tempFile = fopen( $this->tempFileName
, "w" );
195 fwrite($tempFile , $textToWrite);
200 * Returns an array containing:
201 * The contents of the selenium cingiguration ini file
202 * The expected selenium configuration array that getSeleniumSettings should return
203 * The expected available browsers array that getSeleniumSettings should return
204 * The expected test suites arrya that getSeleniumSettings should return
206 public function sampleConfigs() {
208 array($this->testConfig0
, $this->testSettings0
, $this->testBrowsers0
, $this->testSuites0
),
209 array($this->testConfig1
, $this->testSettings1
, $this->testBrowsers1
, $this->testSuites1
)