MediaWiki
REL1_21
|
00001 <?php 00002 00003 class SeleniumConfigurationTest extends MediaWikiTestCase { 00004 00009 private $tempFileName; 00010 00014 private $testConfig0 = ' 00015 [SeleniumSettings] 00016 browsers[firefox] = "*firefox" 00017 browsers[iexplorer] = "*iexploreproxy" 00018 browsers[chrome] = "*chrome" 00019 host = "localhost" 00020 port = "foobarr" 00021 wikiUrl = "http://localhost/deployment" 00022 username = "xxxxxxx" 00023 userPassword = "" 00024 testBrowser = "chrome" 00025 startserver = 00026 stopserver = 00027 jUnitLogFile = 00028 runAgainstGrid = false 00029 00030 [SeleniumTests] 00031 testSuite[SimpleSeleniumTestSuite] = "tests/selenium/SimpleSeleniumTestSuite.php" 00032 testSuite[TestSuiteName] = "testSuitePath" 00033 '; 00037 private $testBrowsers0 = array( 'firefox' => '*firefox', 00038 'iexplorer' => '*iexploreproxy', 00039 'chrome' => '*chrome' 00040 ); 00044 private $testSettings0 = array( 00045 'host' => 'localhost', 00046 'port' => 'foobarr', 00047 'wikiUrl' => 'http://localhost/deployment', 00048 'username' => 'xxxxxxx', 00049 'userPassword' => '', 00050 'testBrowser' => 'chrome', 00051 'startserver' => null, 00052 'stopserver' => null, 00053 'seleniumserverexecpath' => null, 00054 'jUnitLogFile' => null, 00055 'runAgainstGrid' => null 00056 ); 00060 private $testSuites0 = array( 00061 'SimpleSeleniumTestSuite' => 'tests/selenium/SimpleSeleniumTestSuite.php', 00062 'TestSuiteName' => 'testSuitePath' 00063 ); 00064 00068 private $testConfig1 = 00069 ' 00070 [SeleniumSettings] 00071 host = "localhost" 00072 testBrowser = "firefox" 00073 '; 00077 private $testBrowsers1 = null; 00081 private $testSettings1 = array( 00082 'host' => 'localhost', 00083 'port' => null, 00084 'wikiUrl' => null, 00085 'username' => null, 00086 'userPassword' => null, 00087 'testBrowser' => 'firefox', 00088 'startserver' => null, 00089 'stopserver' => null, 00090 'seleniumserverexecpath' => null, 00091 'jUnitLogFile' => null, 00092 'runAgainstGrid' => null 00093 ); 00097 private $testSuites1 = null; 00098 00099 00100 protected function setUp() { 00101 parent::setUp(); 00102 if ( !defined( 'SELENIUMTEST' ) ) { 00103 define( 'SELENIUMTEST', true ); 00104 } 00105 } 00106 00110 protected function tearDown() { 00111 if ( strlen( $this->tempFileName ) > 0 ) { 00112 unlink( $this->tempFileName ); 00113 unset( $this->tempFileName ); 00114 } 00115 parent::tearDown(); 00116 } 00117 00122 public function testErrorOnIncorrectConfigFile() { 00123 $seleniumSettings = array(); 00124 $seleniumBrowsers = array(); 00125 $seleniumTestSuites = array(); 00126 00127 SeleniumConfig::getSeleniumSettings( $seleniumSettings, 00128 $seleniumBrowsers, 00129 $seleniumTestSuites, 00130 "Some_fake_settings_file.ini" ); 00131 } 00132 00137 public function testErrorOnMissingConfigFile() { 00138 $seleniumSettings = array(); 00139 $seleniumBrowsers = array(); 00140 $seleniumTestSuites = array(); 00141 global $wgSeleniumConfigFile; 00142 $wgSeleniumConfigFile = ''; 00143 SeleniumConfig::getSeleniumSettings( $seleniumSettings, 00144 $seleniumBrowsers, 00145 $seleniumTestSuites ); 00146 } 00147 00151 public function testUsesGlobalVarForConfigFile() { 00152 $seleniumSettings = array(); 00153 $seleniumBrowsers = array(); 00154 $seleniumTestSuites = array(); 00155 global $wgSeleniumConfigFile; 00156 $this->writeToTempFile( $this->testConfig0 ); 00157 $wgSeleniumConfigFile = $this->tempFileName; 00158 SeleniumConfig::getSeleniumSettings( $seleniumSettings, 00159 $seleniumBrowsers, 00160 $seleniumTestSuites ); 00161 $this->assertEquals( $seleniumSettings, $this->testSettings0, 00162 'The selenium settings should have been read from the file defined in $wgSeleniumConfigFile' 00163 ); 00164 $this->assertEquals( $seleniumBrowsers, $this->testBrowsers0, 00165 'The available browsers should have been read from the file defined in $wgSeleniumConfigFile' 00166 ); 00167 $this->assertEquals( $seleniumTestSuites, $this->testSuites0, 00168 'The test suites should have been read from the file defined in $wgSeleniumConfigFile' 00169 ); 00170 } 00171 00176 public function testgetSeleniumSettings( $sampleConfig, $expectedSettings, $expectedBrowsers, $expectedSuites ) { 00177 $this->writeToTempFile( $sampleConfig ); 00178 $seleniumSettings = array(); 00179 $seleniumBrowsers = array(); 00180 $seleniumTestSuites = null; 00181 00182 SeleniumConfig::getSeleniumSettings( $seleniumSettings, 00183 $seleniumBrowsers, 00184 $seleniumTestSuites, 00185 $this->tempFileName ); 00186 00187 $this->assertEquals( $seleniumSettings, $expectedSettings, 00188 "The selenium settings for the following test configuration was not retrieved correctly" . $sampleConfig 00189 ); 00190 $this->assertEquals( $seleniumBrowsers, $expectedBrowsers, 00191 "The available browsers for the following test configuration was not retrieved correctly" . $sampleConfig 00192 ); 00193 $this->assertEquals( $seleniumTestSuites, $expectedSuites, 00194 "The test suites for the following test configuration was not retrieved correctly" . $sampleConfig 00195 ); 00196 } 00197 00202 private function writeToTempFile( $textToWrite ) { 00203 $this->tempFileName = tempnam( sys_get_temp_dir(), 'test_settings.' ); 00204 $tempFile = fopen( $this->tempFileName, "w" ); 00205 fwrite( $tempFile, $textToWrite ); 00206 fclose( $tempFile ); 00207 } 00208 00216 public function sampleConfigs() { 00217 return array( 00218 array( $this->testConfig0, $this->testSettings0, $this->testBrowsers0, $this->testSuites0 ), 00219 array( $this->testConfig1, $this->testSettings1, $this->testBrowsers1, $this->testSuites1 ) 00220 ); 00221 } 00222 }