From da6dae9af2ac7103cf5b9135ffd3f3ff9369eb73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Tue, 18 Feb 2014 08:52:04 +0100 Subject: [PATCH 1/8] Properly mark Selenium tests as skipped if not configured MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Čihař --- test/selenium/TestBase.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/selenium/TestBase.php b/test/selenium/TestBase.php index 6b8fc1d0ee..59b6a2449c 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 * @@ -43,6 +51,7 @@ abstract class PMA_SeleniumBase extends PHPUnit_Extensions_Selenium2TestCase if (! $username || ! $key) { return array(); } + self::$_selenium_enabled = True; $build_id = 'Manual'; if (getenv('BUILD_TAG')) { @@ -116,6 +125,10 @@ 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->_mysqli = new mysqli( From e50caedee86dfab33335d6e1012a8e12c3095651 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Tue, 18 Feb 2014 08:53:22 +0100 Subject: [PATCH 2/8] Use single variable for server URL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Čihař --- test/bootstrap-dist.php | 3 +-- test/selenium/TestBase.php | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/test/bootstrap-dist.php b/test/bootstrap-dist.php index 858327a986..3a9a95d48c 100644 --- a/test/bootstrap-dist.php +++ b/test/bootstrap-dist.php @@ -35,8 +35,7 @@ $test_defaults = array( 'TESTSUITE_USER' => 'root', 'TESTSUITE_PASSWORD' => '', 'TESTSUITE_DATABASE' => 'test', - 'TESTSUITE_PHPMYADMIN_HOST' => 'http://localhost', - 'TESTSUITE_PHPMYADMIN_URL' => '/phpmyadmin', + 'TESTSUITE_URL' => 'http://localhost/phpmyadmin/', ); foreach ($test_defaults as $varname => $defvalue) { $envvar = getenv($varname); diff --git a/test/selenium/TestBase.php b/test/selenium/TestBase.php index 59b6a2449c..ce3ba91188 100644 --- a/test/selenium/TestBase.php +++ b/test/selenium/TestBase.php @@ -130,7 +130,7 @@ abstract class PMA_SeleniumBase extends PHPUnit_Extensions_Selenium2TestCase } parent::setUp(); - $this->setBrowserUrl(TESTSUITE_PHPMYADMIN_HOST . TESTSUITE_PHPMYADMIN_URL); + $this->setBrowserUrl(TESTSUITE_URL); $this->_mysqli = new mysqli( "localhost", TESTSUITE_USER, From 86df238aec85357046d343f4d7445dcafb0c6f1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Tue, 18 Feb 2014 08:53:41 +0100 Subject: [PATCH 3/8] Honor configured database server MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Čihař --- test/selenium/TestBase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/selenium/TestBase.php b/test/selenium/TestBase.php index ce3ba91188..5a15166969 100644 --- a/test/selenium/TestBase.php +++ b/test/selenium/TestBase.php @@ -132,7 +132,7 @@ abstract class PMA_SeleniumBase extends PHPUnit_Extensions_Selenium2TestCase parent::setUp(); $this->setBrowserUrl(TESTSUITE_URL); $this->_mysqli = new mysqli( - "localhost", + TESTSUITE_SERVER, TESTSUITE_USER, TESTSUITE_PASSWORD ); From a9ec7def447f69687a10b0057c045c788dea1334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Tue, 18 Feb 2014 08:54:15 +0100 Subject: [PATCH 4/8] Remove unused code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Čihař --- test/bootstrap-dist.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/test/bootstrap-dist.php b/test/bootstrap-dist.php index 3a9a95d48c..59c3481661 100644 --- a/test/bootstrap-dist.php +++ b/test/bootstrap-dist.php @@ -19,16 +19,6 @@ 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', From 11812af0d5ac279c1d2bc107f7672ae0a63044fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Tue, 18 Feb 2014 08:59:14 +0100 Subject: [PATCH 5/8] Allow to configure Selenium server manually MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Čihař --- test/bootstrap-dist.php | 3 + test/selenium/TestBase.php | 145 ++++++++++++++++++++----------------- 2 files changed, 82 insertions(+), 66 deletions(-) diff --git a/test/bootstrap-dist.php b/test/bootstrap-dist.php index 59c3481661..5fb8adcffc 100644 --- a/test/bootstrap-dist.php +++ b/test/bootstrap-dist.php @@ -26,6 +26,9 @@ $test_defaults = array( 'TESTSUITE_PASSWORD' => '', 'TESTSUITE_DATABASE' => 'test', 'TESTSUITE_URL' => 'http://localhost/phpmyadmin/', + 'TESTSUITE_SELENIUM_HOST' => '', + 'TESTSUITE_SELENIUM_PORT' => '4444', + 'TESTSUITE_SELENIUM_BROWSER' => 'firefox', ); foreach ($test_defaults as $varname => $defvalue) { $envvar = getenv($varname); diff --git a/test/selenium/TestBase.php b/test/selenium/TestBase.php index 5a15166969..23781d5034 100644 --- a/test/selenium/TestBase.php +++ b/test/selenium/TestBase.php @@ -48,74 +48,87 @@ abstract class PMA_SeleniumBase extends PHPUnit_Extensions_Selenium2TestCase { $username = getenv('BS_UNAME'); $key = getenv('BS_KEY'); - if (! $username || ! $key) { + $selenium_host = getenv('TESTSUITE_SELENIUM_HOST'); + + if ($username && $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' => 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; + } elseif ($selenium_host) { + self::$_selenium_enabled = True; + return array( + array( + 'browserName' => getenv('TESTSUITE_SELENIUM_BROWSER'), + 'host' => $selenium_host, + 'port' => getenv('TESTSUITE_SELENIUM_PORT'), + ) + ); + } else { return array(); } - 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' => 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; } /** From d336553bcbcfe8c08cb20f5ce89a0074b9fc5d97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Tue, 18 Feb 2014 09:08:27 +0100 Subject: [PATCH 6/8] Unify handling of environment configuration of testsuite MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Čihař --- test/README | 36 ++++++++++++++++++++++++++++++++++++ test/bootstrap-dist.php | 3 +++ test/selenium/TestBase.php | 34 ++++++++++++++++------------------ 3 files changed, 55 insertions(+), 18 deletions(-) diff --git a/test/README b/test/README index a7e287ad42..3d250453a4 100644 --- a/test/README +++ b/test/README @@ -9,3 +9,39 @@ 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 5fb8adcffc..7ac14f0521 100644 --- a/test/bootstrap-dist.php +++ b/test/bootstrap-dist.php @@ -29,6 +29,9 @@ $test_defaults = array( '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/TestBase.php b/test/selenium/TestBase.php index 23781d5034..a10edd2fcd 100644 --- a/test/selenium/TestBase.php +++ b/test/selenium/TestBase.php @@ -46,11 +46,9 @@ abstract class PMA_SeleniumBase extends PHPUnit_Extensions_Selenium2TestCase */ public static function browsers() { - $username = getenv('BS_UNAME'); - $key = getenv('BS_KEY'); - $selenium_host = getenv('TESTSUITE_SELENIUM_HOST'); - - if ($username && $key) { + if (! empty(TESTSUITE_BROWSERSTACK_USER) + && ! empty(TESTSUITE_BROWSERSTACK_KEY) + ) { /* BrowserStack integration */ self::$_selenium_enabled = True; @@ -68,21 +66,21 @@ abstract class PMA_SeleniumBase extends PHPUnit_Extensions_Selenium2TestCase 'port' => 80, 'timeout' => 30000, 'desiredCapabilities' => array( - 'browserstack.user' => BS_UNAME, - 'browserstack.key' => BS_KEY, + 'browserstack.user' => TESTSUITE_BROWSERSTACK_USER, + 'browserstack.key' => TESTSUITE_BROWSERSTACK_KEY, 'project' => 'phpMyAdmin', 'build' => $build_id, ) ); - if (getenv('TESTSUITE_FULL')) { + if (!empty(TESTSUITE_FULL)) { $result[] = array( 'browserName' => 'firefox', 'host' => 'hub.browserstack.com', 'port' => 80, 'timeout' => 30000, 'desiredCapabilities' => array( - 'browserstack.user' => BS_UNAME, - 'browserstack.key' => BS_KEY, + 'browserstack.user' => TESTSUITE_BROWSERSTACK_USER, + 'browserstack.key' => TESTSUITE_BROWSERSTACK_KEY, 'project' => 'phpMyAdmin', 'build' => $build_id, ) @@ -93,8 +91,8 @@ abstract class PMA_SeleniumBase extends PHPUnit_Extensions_Selenium2TestCase 'port' => 80, 'timeout' => 30000, 'desiredCapabilities' => array( - 'browserstack.user' => BS_UNAME, - 'browserstack.key' => BS_KEY, + 'browserstack.user' => TESTSUITE_BROWSERSTACK_USER, + 'browserstack.key' => TESTSUITE_BROWSERSTACK_KEY, 'project' => 'phpMyAdmin', 'build' => $build_id, 'os' => 'windows', @@ -107,8 +105,8 @@ abstract class PMA_SeleniumBase extends PHPUnit_Extensions_Selenium2TestCase 'port' => 80, 'timeout' => 30000, 'desiredCapabilities' => array( - 'browserstack.user' => BS_UNAME, - 'browserstack.key' => BS_KEY, + 'browserstack.user' => TESTSUITE_BROWSERSTACK_USER, + 'browserstack.key' => TESTSUITE_BROWSERSTACK_KEY, 'project' => 'phpMyAdmin', 'build' => $build_id, 'os' => 'OS X', @@ -117,13 +115,13 @@ abstract class PMA_SeleniumBase extends PHPUnit_Extensions_Selenium2TestCase ); } return $result; - } elseif ($selenium_host) { + } elseif (! empty(TESTSUITE_SELENIUM_HOST)) { self::$_selenium_enabled = True; return array( array( - 'browserName' => getenv('TESTSUITE_SELENIUM_BROWSER'), - 'host' => $selenium_host, - 'port' => getenv('TESTSUITE_SELENIUM_PORT'), + 'browserName' => TESTSUITE_SELENIUM_BROWSER, + 'host' => TESTSUITE_SELENIUM_HOST, + 'port' => TESTSUITE_SELENIUM_PORT, ) ); } else { From be34350ec51ce9e09e4d4ba7fc72434a6436c9d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Tue, 18 Feb 2014 09:08:48 +0100 Subject: [PATCH 7/8] Make readme show in rst on github MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Čihař --- test/{README => README.rst} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/{README => README.rst} (100%) diff --git a/test/README b/test/README.rst similarity index 100% rename from test/README rename to test/README.rst From 528fba02242b300126d78784a167998b809cdff0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Tue, 18 Feb 2014 09:08:58 +0100 Subject: [PATCH 8/8] Remove obsolete readme MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Čihař --- test/selenium/README | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 test/selenium/README 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.