From 6b03ca3443a89ebf42a815898c8feca61bf803bd Mon Sep 17 00:00:00 2001 From: "Guillaume (ioguix) de Rorthais" Date: Tue, 28 Oct 2008 00:29:51 -0400 Subject: [PATCH] Some selenium tests and improvement - add Database level tests - build_tests.php now run every script it finds in ./tests/selenium/src, in alphanum order. No more needs to edit build_tests.php to add new test builder --- build_tests.php | 10 ++- .../selenium/src/{roles.php => 01-roles.php} | 0 tests/selenium/src/02-database.php | 67 +++++++++++++++++++ .../src/{cleantests.php => 03-cleantests.php} | 31 ++++++--- tests/selenium/testBuilder.class.php | 14 +++- 5 files changed, 109 insertions(+), 13 deletions(-) rename tests/selenium/src/{roles.php => 01-roles.php} (100%) create mode 100644 tests/selenium/src/02-database.php rename tests/selenium/src/{cleantests.php => 03-cleantests.php} (73%) diff --git a/build_tests.php b/build_tests.php index bd5464b0..fec74448 100755 --- a/build_tests.php +++ b/build_tests.php @@ -77,12 +77,18 @@ if (!is_dir("{$test_static_dir}/{$server['desc']}")) mkdir("{$test_static_dir}/{$server['desc']}"); + $fd = opendir($test_src_dir); + $files = array(); + while ($file = readdir($fd)) + if (($file != '.') && ($file != '..')) + $files[] = $file; + sort($files); /* include the tests creator scripts here * in the order you want them executed. * Each script append itself to the TestSuite.html file. **/ - require("{$test_src_dir}/roles.php"); - require("{$test_src_dir}/cleantests.php"); + foreach ($files as $testgroupfile) + require("{$test_src_dir}/{$testgroupfile}"); } /* close the TestSuite.html file */ diff --git a/tests/selenium/src/roles.php b/tests/selenium/src/01-roles.php similarity index 100% rename from tests/selenium/src/roles.php rename to tests/selenium/src/01-roles.php diff --git a/tests/selenium/src/02-database.php b/tests/selenium/src/02-database.php new file mode 100644 index 00000000..47313961 --- /dev/null +++ b/tests/selenium/src/02-database.php @@ -0,0 +1,67 @@ +login($admin_user, $admin_user_pass); + +/** 1 **/ + $t->clickAndWait("link={$lang['strdatabases']}"); + $t->clickAndWait("link={$lang['strcreatedatabase']}"); + + /* db name */ + if ($data->hasAlterDatabaseRename()) + $t->type('formName', "{$testdb}toalter"); + else $t->type('formName', $testdb); + /* encoding*/ + $t->select('formEncoding', 'SQL_ASCII'); + /* comment*/ + if ($data->hasSharedComments()) + $t->type('formComment', "database comment to alter"); + /* create */ + $t->clickAndWait("//input[@value='{$lang['strcreate']}']"); + $t->assertText("//p[@class='message']", $lang['strdatabasecreated']); + +/** 2 **/ + if ($data->hasAlterDatabaseOwner()) { + $t->clickAndWait("link={$lang['strdatabases']}"); + /* we don't need to check if hasAlterDatabaseRename here because + * hasAlterDatabase is actually calling it */ + $t->clickAndWait("//tr/td/a[text()='{$testdb}toalter']/../../td/a[text()='{$lang['stralter']}']"); + if ($data->hasAlterDatabaseOwner()) + $t->select('owner', $super_user[$server['desc']]); + $t->clickAndWait('alter'); + $t->assertText("//p[@class='message']", $lang['strdatabasealtered']); + } + +/** 3 **/ + if ($data->hasAlterDatabase()) { + $t->clickAndWait("link={$lang['strdatabases']}"); + /* we don't need to check if hasAlterDatabaseRename here because + * hasAlterDatabase is actually calling it */ + $t->clickAndWait("//tr/td/a[text()='{$testdb}toalter']/../../td/a[text()='{$lang['stralter']}']"); + $t->type('newname', $testdb); + /* owner */ + if ($data->hasAlterDatabaseOwner()) + $t->select('owner', $admin_user); + /* comment */ + if ($data->hasSharedComments()) + $t->type('dbcomment', "database comment"); + /* alter */ + $t->clickAndWait('alter'); + $t->assertText("//p[@class='message']", $lang['strdatabasealtered']); + } + + $t->logout(); + $t->writeTests($testsuite_file); + unset($t); +?> diff --git a/tests/selenium/src/cleantests.php b/tests/selenium/src/03-cleantests.php similarity index 73% rename from tests/selenium/src/cleantests.php rename to tests/selenium/src/03-cleantests.php index 8cfffa4e..15d61934 100644 --- a/tests/selenium/src/cleantests.php +++ b/tests/selenium/src/03-cleantests.php @@ -2,21 +2,27 @@ global $testsuite_file, $test_static_dir; /* - * 1/ login as admin_user - * 2/ drop user role/user + * 1/ login as user and try to drop database -> fail + * 2/ logout / login as admin_user and drop user role/user * 3/ try to drop himself -> fail - * 4/ logout & login as superuser - * 5/ drop admin_user + * 4/ drop test database + * 5/ logout & login as superuser and drop admin_user */ $t = new TestBuilder("{$test_static_dir}/{$server['desc']}/cleantests.html", $server['desc'], 'Cleaner tests', 'Clean every created stuff for test.' ); - /* 1 */ - $t->login($admin_user, $admin_pass); +/** 1 **/ + $t->login($user, $user_pass); + $t->clickAndWait("link={$lang['strdatabases']}"); + $t->clickAndWait("//tr/td/a[text()='{$testdb}']/../../td/a[text()='{$lang['strdrop']}']"); + $t->clickAndWait('drop'); + $t->assertText('//p[@class=\'message\']', $lang['strdatabasedroppedbad']); - /* 2 */ +/** 2 **/ + $t->logout(); + $t->login($admin_user, $admin_pass); if ($data->hasRoles()) { $t->clickAndWait("link={$lang['strroles']}"); $t->clickAndWait("//tr/td/a[text()='{$user}']/../../td/a[text()='{$lang['strdrop']}']"); @@ -29,7 +35,7 @@ $t->assertText('//p[@class=\'message\']', $lang['struserdropped']); } - /* 3 */ +/** 3 **/ if ($data->hasRoles()) { $t->clickAndWait("link={$lang['strroles']}"); $t->clickAndWait("link={$admin_user}"); @@ -44,11 +50,16 @@ $t->assertText('//p[@class=\'message\']', $lang['struserdroppedbad']); } - /* 4 */ +/** 4 **/ + $t->clickAndWait("link={$lang['strdatabases']}"); + $t->clickAndWait("//tr/td/a[text()='{$testdb}']/../../td/a[text()='{$lang['strdrop']}']"); + $t->clickAndWait('drop'); + $t->assertText('//p[@class=\'message\']', $lang['strdatabasedropped']); + +/** 5 **/ $t->logout(); $t->login($super_user[$server['desc']], $super_pass[$server['desc']]); - /* 5 */ if ($data->hasRoles()) { /* drop adminuser */ $t->clickAndWait("link={$lang['strroles']}"); diff --git a/tests/selenium/testBuilder.class.php b/tests/selenium/testBuilder.class.php index 47b93ce8..7a695e5c 100644 --- a/tests/selenium/testBuilder.class.php +++ b/tests/selenium/testBuilder.class.php @@ -53,7 +53,10 @@ public function logout() { global $lang; - $this->test('clickAndWait', "link={$lang['strlogout']}"); + $this->test('clickAndWait', "//div[@class='trail']/descendant::tr/td[1]/a/span[@class='label' and text()='phpPgAdmin']"); + $this->test('clickAndWait', "link={$lang['strservers']}"); + $this->test('clickAndWait', "//tr/td/a[text()='{$this->servDesc}']/../../td/a[text()='{$lang['strlogout']}']"); + $this->test('assertText', "//p[@class='message']", sprintf($lang['strlogoutmsg'], $this->servDesc) ); @@ -93,6 +96,15 @@ $this->test('type', $selector, $value); } + /** + * Add a selenium select test to the file + * @param $selector the selector to select the object to work on (second column) + * @param $value (optional) the expected (or not) value (third column) + */ + public function select($selector, $value) { + $this->test('select', $selector, $value); + } + /** * Add a selenium click test to the file * @param $selector the selector to select the object to work on (second column) -- 2.39.5