diff --git a/test/README b/test/README deleted file mode 100644 index a7e287ad42..0000000000 --- a/test/README +++ /dev/null @@ -1,11 +0,0 @@ -PhpMyAdmin test suite -===================== - -This directory is protected from web visitors by a .htaccess file. - -For more information on allowing http access to this directory see: -http://httpd.apache.org/docs/current/mod/mod_authz_host.html#allow - -Please visit the wiki for more information on unit testing: -https://wiki.phpmyadmin.net/pma/UnitTesting - diff --git a/test/README.rst b/test/README.rst new file mode 100644 index 0000000000..3d250453a4 --- /dev/null +++ b/test/README.rst @@ -0,0 +1,47 @@ +PhpMyAdmin test suite +===================== + +This directory is protected from web visitors by a .htaccess file. + +For more information on allowing http access to this directory see: +http://httpd.apache.org/docs/current/mod/mod_authz_host.html#allow + +Please visit the wiki for more information on unit testing: +https://wiki.phpmyadmin.net/pma/UnitTesting + +Selenium tests +-------------- + +To be able to run Selenium tests, you need to have webserver, database +and Selenium running. Following environment variables configure where +testsuite connects: + +TESTSUITE_SERVER + Database server to use. +TESTSUITE_USER + Username for connecting to database. +TESTSUITE_PASSWORD + Password for connecting to database. +TESTSUITE_DATABASE + Database to use for testing. +TESTSUITE_URL + URL where tested phpMyAdmin is available. + +Additionally you need to configure link to Selenium and browsers. You +can either setup Selenium locally or use BrowserStack automated testing. + +For local setup, define following: + +TESTSUITE_SELENIUM_HOST + Host where Selenium is running. +TESTSUITE_SELENIUM_PORT + Port where to connect. +TESTSUITE_SELENIUM_BROWSER + Browser to use for testing inside Selenium. + +With BrowserStack, set following: + +TESTSUITE_BROWSERSTACK_UNAME + BrowserStack username. +TESTSUITE_BROWSERSTACK_KEY + BrowserStack access key. diff --git a/test/bootstrap-dist.php b/test/bootstrap-dist.php index 858327a986..7ac14f0521 100644 --- a/test/bootstrap-dist.php +++ b/test/bootstrap-dist.php @@ -19,24 +19,19 @@ define('PHPMYADMIN', 1); define('TESTSUITE', 1); define('PMA_MYSQL_INT_VERSION', 55000); -// BrowserStack integration -$bs_uname = getenv('BS_UNAME'); -$bs_key = getenv('BS_KEY'); - -if ($bs_uname && $bs_key) { - define('PHPUNIT_HOST', $bs_uname . ":" . $bs_key . "@hub.browserstack.com:80"); -} else { - define('PHPUNIT_HOST', "127.0.0.1"); -} - // Selenium tests setup $test_defaults = array( 'TESTSUITE_SERVER' => 'localhost', 'TESTSUITE_USER' => 'root', 'TESTSUITE_PASSWORD' => '', 'TESTSUITE_DATABASE' => 'test', - 'TESTSUITE_PHPMYADMIN_HOST' => 'http://localhost', - 'TESTSUITE_PHPMYADMIN_URL' => '/phpmyadmin', + 'TESTSUITE_URL' => 'http://localhost/phpmyadmin/', + 'TESTSUITE_SELENIUM_HOST' => '', + 'TESTSUITE_SELENIUM_PORT' => '4444', + 'TESTSUITE_SELENIUM_BROWSER' => 'firefox', + 'TESTSUITE_BROWSERSTACK_USER' => '', + 'TESTSUITE_BROWSERSTACK_KEY' => '', + 'TESTSUITE_FULL' => '', ); foreach ($test_defaults as $varname => $defvalue) { $envvar = getenv($varname); diff --git a/test/selenium/README b/test/selenium/README deleted file mode 100644 index f28a8b54b8..0000000000 --- a/test/selenium/README +++ /dev/null @@ -1,18 +0,0 @@ -Guide to run the AllSeleniumTests.php (Yasitha Pandithawatta) -============================================================= - -1. Tested with version 4.0 -2. Configure the testing environment - Browser and add the following fields to - phpunit.xml.dist - - - - - - - - -3. Start the selenium server -4. Run $ phpunit test/AllSeleniumTests.php - -Note: Only PmaSeleniumLoginTest.php is fixed and added to the test suit. diff --git a/test/selenium/TestBase.php b/test/selenium/TestBase.php index 6b8fc1d0ee..a10edd2fcd 100644 --- a/test/selenium/TestBase.php +++ b/test/selenium/TestBase.php @@ -31,6 +31,14 @@ abstract class PMA_SeleniumBase extends PHPUnit_Extensions_Selenium2TestCase */ public $database_name; + /** + * Whether Selenium testing should be enabled. + * + * @access private + * @var boolean + */ + private $_selenium_enabled = False; + /** * Lists browsers to test * @@ -38,75 +46,87 @@ abstract class PMA_SeleniumBase extends PHPUnit_Extensions_Selenium2TestCase */ public static function browsers() { - $username = getenv('BS_UNAME'); - $key = getenv('BS_KEY'); - if (! $username || ! $key) { + if (! empty(TESTSUITE_BROWSERSTACK_USER) + && ! empty(TESTSUITE_BROWSERSTACK_KEY) + ) { + /* BrowserStack integration */ + self::$_selenium_enabled = True; + + $build_id = 'Manual'; + if (getenv('BUILD_TAG')) { + $build_id = getenv('BUILD_TAG'); + } elseif (getenv('TRAVIS_JOB_NUMBER')) { + $build_id = 'travis-' . getenv('TRAVIS_JOB_NUMBER'); + } + + $result = array(); + $result[] = array( + 'browserName' => 'chrome', + 'host' => 'hub.browserstack.com', + 'port' => 80, + 'timeout' => 30000, + 'desiredCapabilities' => array( + 'browserstack.user' => TESTSUITE_BROWSERSTACK_USER, + 'browserstack.key' => TESTSUITE_BROWSERSTACK_KEY, + 'project' => 'phpMyAdmin', + 'build' => $build_id, + ) + ); + if (!empty(TESTSUITE_FULL)) { + $result[] = array( + 'browserName' => 'firefox', + 'host' => 'hub.browserstack.com', + 'port' => 80, + 'timeout' => 30000, + 'desiredCapabilities' => array( + 'browserstack.user' => TESTSUITE_BROWSERSTACK_USER, + 'browserstack.key' => TESTSUITE_BROWSERSTACK_KEY, + 'project' => 'phpMyAdmin', + 'build' => $build_id, + ) + ); + $result[] = array( + 'browserName' => 'internet explorer', + 'host' => 'hub.browserstack.com', + 'port' => 80, + 'timeout' => 30000, + 'desiredCapabilities' => array( + 'browserstack.user' => TESTSUITE_BROWSERSTACK_USER, + 'browserstack.key' => TESTSUITE_BROWSERSTACK_KEY, + 'project' => 'phpMyAdmin', + 'build' => $build_id, + 'os' => 'windows', + 'os_version' => '7', + ) + ); + $result[] = array( + 'browserName' => 'Safari', + 'host' => 'hub.browserstack.com', + 'port' => 80, + 'timeout' => 30000, + 'desiredCapabilities' => array( + 'browserstack.user' => TESTSUITE_BROWSERSTACK_USER, + 'browserstack.key' => TESTSUITE_BROWSERSTACK_KEY, + 'project' => 'phpMyAdmin', + 'build' => $build_id, + 'os' => 'OS X', + 'os_version' => 'Mavericks', + ) + ); + } + return $result; + } elseif (! empty(TESTSUITE_SELENIUM_HOST)) { + self::$_selenium_enabled = True; + return array( + array( + 'browserName' => TESTSUITE_SELENIUM_BROWSER, + 'host' => TESTSUITE_SELENIUM_HOST, + 'port' => TESTSUITE_SELENIUM_PORT, + ) + ); + } else { return array(); } - - $build_id = 'Manual'; - if (getenv('BUILD_TAG')) { - $build_id = getenv('BUILD_TAG'); - } elseif (getenv('TRAVIS_JOB_NUMBER')) { - $build_id = 'travis-' . getenv('TRAVIS_JOB_NUMBER'); - } - - $result = array(); - $result[] = array( - 'browserName' => 'chrome', - 'host' => 'hub.browserstack.com', - 'port' => 80, - 'timeout' => 30000, - 'desiredCapabilities' => array( - 'browserstack.user' => BS_UNAME, - 'browserstack.key' => BS_KEY, - 'project' => 'phpMyAdmin', - 'build' => $build_id, - ) - ); - if (getenv('TESTSUITE_FULL')) { - $result[] = array( - 'browserName' => 'firefox', - 'host' => 'hub.browserstack.com', - 'port' => 80, - 'timeout' => 30000, - 'desiredCapabilities' => array( - 'browserstack.user' => BS_UNAME, - 'browserstack.key' => BS_KEY, - 'project' => 'phpMyAdmin', - 'build' => $build_id, - ) - ); - $result[] = array( - 'browserName' => 'internet explorer', - 'host' => 'hub.browserstack.com', - 'port' => 80, - 'timeout' => 30000, - 'desiredCapabilities' => array( - 'browserstack.user' => BS_UNAME, - 'browserstack.key' => BS_KEY, - 'project' => 'phpMyAdmin', - 'build' => $build_id, - 'os' => 'windows', - 'os_version' => '7', - ) - ); - $result[] = array( - 'browserName' => 'Safari', - 'host' => 'hub.browserstack.com', - 'port' => 80, - 'timeout' => 30000, - 'desiredCapabilities' => array( - 'browserstack.user' => BS_UNAME, - 'browserstack.key' => BS_KEY, - 'project' => 'phpMyAdmin', - 'build' => $build_id, - 'os' => 'OS X', - 'os_version' => 'Mavericks', - ) - ); - } - return $result; } /** @@ -116,10 +136,14 @@ abstract class PMA_SeleniumBase extends PHPUnit_Extensions_Selenium2TestCase */ protected function setUp() { + if (! $this->_selenium_enabled) { + $this->markTestSkipped('Selenium testing not configured.'); + } + parent::setUp(); - $this->setBrowserUrl(TESTSUITE_PHPMYADMIN_HOST . TESTSUITE_PHPMYADMIN_URL); + $this->setBrowserUrl(TESTSUITE_URL); $this->_mysqli = new mysqli( - "localhost", + TESTSUITE_SERVER, TESTSUITE_USER, TESTSUITE_PASSWORD );