MediaWiki  master
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         protected function setUp() {
00103                 parent::setUp();
00104                 if ( !defined( 'SELENIUMTEST' ) ) {
00105                         define( 'SELENIUMTEST', true );
00106                 }
00107         }
00108 
00112         protected function tearDown() {
00113                 if ( strlen( $this->tempFileName ) > 0 ) {
00114                         unlink( $this->tempFileName );
00115                         unset( $this->tempFileName );
00116                 }
00117                 parent::tearDown();
00118         }
00119 
00124         public function testErrorOnIncorrectConfigFile() {
00125                 $seleniumSettings = array();
00126                 $seleniumBrowsers = array();
00127                 $seleniumTestSuites = array();
00128 
00129                 SeleniumConfig::getSeleniumSettings($seleniumSettings,
00130                         $seleniumBrowsers,
00131                         $seleniumTestSuites,
00132                         "Some_fake_settings_file.ini" );
00133 
00134         }
00135 
00140         public function testErrorOnMissingConfigFile() {
00141                 $seleniumSettings = array();
00142                 $seleniumBrowsers = array();
00143                 $seleniumTestSuites = array();
00144                 global $wgSeleniumConfigFile;
00145                 $wgSeleniumConfigFile = '';
00146                 SeleniumConfig::getSeleniumSettings($seleniumSettings,
00147                         $seleniumBrowsers,
00148                         $seleniumTestSuites);
00149         }
00150 
00154         public function testUsesGlobalVarForConfigFile() {
00155                 $seleniumSettings = array();
00156                 $seleniumBrowsers = array();
00157                 $seleniumTestSuites = array();
00158                 global $wgSeleniumConfigFile;
00159                 $this->writeToTempFile( $this->testConfig0 );
00160                 $wgSeleniumConfigFile = $this->tempFileName;
00161                 SeleniumConfig::getSeleniumSettings($seleniumSettings,
00162                         $seleniumBrowsers,
00163                         $seleniumTestSuites);
00164                 $this->assertEquals($seleniumSettings, $this->testSettings0 ,
00165                 'The selenium settings should have been read from the file defined in $wgSeleniumConfigFile'
00166                 );
00167                 $this->assertEquals($seleniumBrowsers, $this->testBrowsers0,
00168                 'The available browsers should have been read from the file defined in $wgSeleniumConfigFile'
00169                 );
00170                 $this->assertEquals($seleniumTestSuites, $this->testSuites0,
00171                 'The test suites should have been read from the file defined in $wgSeleniumConfigFile'
00172                 );
00173         }
00174 
00179         public function testgetSeleniumSettings($sampleConfig, $expectedSettings, $expectedBrowsers, $expectedSuites ) {
00180                 $this->writeToTempFile( $sampleConfig );
00181                 $seleniumSettings = array();
00182                 $seleniumBrowsers = array();
00183                 $seleniumTestSuites = null;
00184 
00185                 SeleniumConfig::getSeleniumSettings($seleniumSettings,
00186                         $seleniumBrowsers,
00187                         $seleniumTestSuites,
00188                         $this->tempFileName );
00189 
00190                 $this->assertEquals($seleniumSettings, $expectedSettings,
00191                 "The selenium settings for the following test configuration was not retrieved correctly" . $sampleConfig
00192                 );
00193                 $this->assertEquals($seleniumBrowsers, $expectedBrowsers,
00194                 "The available browsers for the following test configuration was not retrieved correctly" . $sampleConfig
00195                 );
00196                 $this->assertEquals($seleniumTestSuites, $expectedSuites,
00197                 "The test suites for the following test configuration was not retrieved correctly" . $sampleConfig
00198                 );
00199 
00200 
00201         }
00202 
00207         private function writeToTempFile($textToWrite) {
00208                 $this->tempFileName = tempnam(sys_get_temp_dir(), 'test_settings.');
00209                 $tempFile =      fopen( $this->tempFileName, "w" );
00210                 fwrite($tempFile , $textToWrite);
00211                 fclose($tempFile);
00212         }
00213 
00221         public function sampleConfigs() {
00222                 return array(
00223                         array($this->testConfig0, $this->testSettings0, $this->testBrowsers0, $this->testSuites0 ),
00224                         array($this->testConfig1, $this->testSettings1, $this->testBrowsers1, $this->testSuites1 )
00225                 );
00226         }
00227 
00228 
00229 }