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