Add first Selenium tests
This commit is contained in:
39
test/AllSeleniumTests.php
Normal file
39
test/AllSeleniumTests.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* runs all defined Selenium tests
|
||||
*
|
||||
* @version $Id$
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
require_once 'PHPUnit/Framework.php';
|
||||
require_once 'PHPUnit/TextUI/TestRunner.php';
|
||||
require_once './PmaSeleniumTestCase.php';
|
||||
require_once './PmaSeleniumLoginTest.php';
|
||||
require_once './PmaSeleniumXssTest.php';
|
||||
require_once './PmaSeleniumPrivilegesTest.php';
|
||||
|
||||
class AllSeleniumTests
|
||||
{
|
||||
public static function main()
|
||||
{
|
||||
$parameters = array();
|
||||
PHPUnit_TextUI_TestRunner::run(self::suite(), $parameters);
|
||||
}
|
||||
|
||||
public static function suite()
|
||||
{
|
||||
$suite = new PHPUnit_Framework_TestSuite('phpMyAdmin');
|
||||
|
||||
$suite->addTestSuite('PmaSeleniumLoginTest');
|
||||
$suite->addTestSuite('PmaSeleniumXssTest');
|
||||
$suite->addTestSuite('PmaSeleniumPrivilegesTest');
|
||||
return $suite;
|
||||
}
|
||||
}
|
||||
?>
|
21
test/PmaSeleniumLoginTest.php
Normal file
21
test/PmaSeleniumLoginTest.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Selenium TestCase for login related tests
|
||||
*
|
||||
* @version $Id$
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
|
||||
require_once('PmaSeleniumTestCase.php');
|
||||
|
||||
|
||||
class PmaSeleniumLoginTest extends PmaSeleniumTestCase
|
||||
{
|
||||
public function testLogin()
|
||||
{
|
||||
$this->doLogin();
|
||||
$this->assertRegExp("/phpMyAdmin .*-dev/", $this->getTitle());
|
||||
}
|
||||
}
|
||||
?>
|
48
test/PmaSeleniumPrivilegesTest.php
Normal file
48
test/PmaSeleniumPrivilegesTest.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Selenium TestCase for privilege related tests
|
||||
*
|
||||
* @version $Id$
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
|
||||
require_once('PmaSeleniumTestCase.php');
|
||||
|
||||
|
||||
class PmaSeleniumPrivilegesTest extends PmaSeleniumTestCase
|
||||
{
|
||||
public function testChangePassword()
|
||||
{
|
||||
$this->doLogin();
|
||||
$this->selectFrame("frame_content");
|
||||
$this->click("link=Change password");
|
||||
$this->waitForPageToLoad("30000");
|
||||
try {
|
||||
$this->assertEquals("", $this->getValue("text_pma_pw"));
|
||||
} catch (PHPUnit_Framework_AssertionFailedError $e) {
|
||||
array_push($this->verificationErrors, $e->toString());
|
||||
}
|
||||
try {
|
||||
$this->assertEquals("", $this->getValue("text_pma_pw2"));
|
||||
} catch (PHPUnit_Framework_AssertionFailedError $e) {
|
||||
array_push($this->verificationErrors, $e->toString());
|
||||
}
|
||||
try {
|
||||
$this->assertEquals("", $this->getValue("generated_pw"));
|
||||
} catch (PHPUnit_Framework_AssertionFailedError $e) {
|
||||
array_push($this->verificationErrors, $e->toString());
|
||||
}
|
||||
$this->click("button_generate_password");
|
||||
$this->assertNotEquals("", $this->getValue("text_pma_pw"));
|
||||
$this->assertNotEquals("", $this->getValue("text_pma_pw2"));
|
||||
$this->assertNotEquals("", $this->getValue("generated_pw"));
|
||||
$this->type("text_pma_pw", $this->cfg['Test']['testuser']['password']);
|
||||
$this->type("text_pma_pw2", $this->cfg['Test']['testuser']['password']);
|
||||
$this->click("change_pw");
|
||||
$this->waitForPageToLoad("30000");
|
||||
$this->assertTrue($this->isTextPresent(""));
|
||||
$this->assertTrue($this->isTextPresent(""));
|
||||
}
|
||||
}
|
||||
?>
|
101
test/PmaSeleniumTestCase.php
Normal file
101
test/PmaSeleniumTestCase.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Selenium parent class for TestCases
|
||||
*
|
||||
* @version $Id$
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
|
||||
// Optionally add the php-client-driver to your include path
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '/opt/selenium-remote-control-1.0.1/selenium-php-client-driver-1.0.1/PEAR/');
|
||||
|
||||
require_once 'PHPUnit/Framework/TestCase.php';
|
||||
require_once 'PHPUnit/Extensions/SeleniumTestCase.php';
|
||||
require_once 'Testing/Selenium.php';
|
||||
|
||||
// Include the main phpMyAdmin user config
|
||||
// currently only $cfg['Test'] is used
|
||||
require_once '../config.inc.php';
|
||||
|
||||
|
||||
|
||||
class PmaSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase
|
||||
{
|
||||
protected $selenium;
|
||||
protected $cfg;
|
||||
|
||||
// TODO: find a way to get this from config.inc.php???
|
||||
// PHPUnit also has a way to use XML configuration... maybe we should use that
|
||||
public static $browsers = array(
|
||||
array(
|
||||
|
||||
'name' => 'Firefox on Windows XP',
|
||||
'browser' => '*firefox',
|
||||
'host' => 'my.windowsxp.box',
|
||||
'port' => 4444,
|
||||
'timeout' => 30000,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'Internet Explorer on Windows XP',
|
||||
'browser' => '*iexplore',
|
||||
'host' => 'my.windowsxp.box',
|
||||
'port' => 4444,
|
||||
'timeout' => 30000,
|
||||
),
|
||||
|
||||
);
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
global $cfg;
|
||||
$this->cfg =& $cfg;
|
||||
//PHPUnit_Extensions_SeleniumTestCase::$browsers = $this->cfg['Test']['broswers'];
|
||||
|
||||
// Check if the test configuration is available
|
||||
if ( empty($cfg['Test']['pma_host'])
|
||||
|| empty($cfg['Test']['pma_url'])
|
||||
//|| empty($cfg['Test']['browsers'])
|
||||
) {
|
||||
$this->fail("Missing Selenium configuration in config.inc.php"); // TODO add doc ref?
|
||||
}
|
||||
|
||||
$this->setBrowserUrl($cfg['Test']['pma_host'] . $cfg['Test']['pma_url']);
|
||||
|
||||
$this->start();
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
$this->stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* perform a login
|
||||
*/
|
||||
public function doLogin()
|
||||
{
|
||||
$this->open($this->cfg['Test']['pma_url']);
|
||||
// Somehow selenium does not like the language selection on the cookie login page, forced English in the config for now.
|
||||
//$this->select("lang", "label=English");
|
||||
|
||||
$this->waitForPageToLoad("30000");
|
||||
$this->type("input_username", $this->cfg['Test']['testuser']['username']);
|
||||
$this->type("input_password", $this->cfg['Test']['testuser']['password']);
|
||||
$this->click("input_go");
|
||||
$this->waitForPageToLoad("30001");
|
||||
}
|
||||
|
||||
/*
|
||||
* Just a dummy to show some example statements
|
||||
*
|
||||
public function mockTest()
|
||||
{
|
||||
// Slow down the testing speed, ideal for debugging
|
||||
//$this->setSpeed(4000);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
?>
|
25
test/PmaSeleniumXssTest.php
Normal file
25
test/PmaSeleniumXssTest.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Selenium TestCase for XSS related tests
|
||||
*
|
||||
* @version $Id$
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
|
||||
require_once('PmaSeleniumTestCase.php');
|
||||
|
||||
class PmaSeleniumXSSTest extends PmaSeleniumTestCase
|
||||
{
|
||||
public function testXssQueryTab()
|
||||
{
|
||||
$this->doLogin();
|
||||
$this->selectFrame("frame_content");
|
||||
$this->click("link=SQL");
|
||||
$this->waitForPageToLoad("30000");
|
||||
$this->type("sqlquery", "'\"><script>alert(123);</script>");
|
||||
$this->click("SQL");
|
||||
// If an alert pops up the test fails, since we don't handle an alert.
|
||||
}
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user