Some selenium tests and improvement
authorGuillaume (ioguix) de Rorthais <ioguix@free.fr>
Tue, 28 Oct 2008 04:29:51 +0000 (00:29 -0400)
committerGuillaume (ioguix) de Rorthais <ioguix@free.fr>
Tue, 28 Oct 2008 16:47:19 +0000 (12:47 -0400)
- 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
tests/selenium/src/01-roles.php [moved from tests/selenium/src/roles.php with 100% similarity]
tests/selenium/src/02-database.php [new file with mode: 0644]
tests/selenium/src/03-cleantests.php [moved from tests/selenium/src/cleantests.php with 73% similarity]
tests/selenium/testBuilder.class.php

index bd5464b05a16f1f5c145c3c2aa7dc04a48067695..fec744489e61e882c87bd28deac07e1556d44a87 100755 (executable)
                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/02-database.php b/tests/selenium/src/02-database.php
new file mode 100644 (file)
index 0000000..4731396
--- /dev/null
@@ -0,0 +1,67 @@
+<?php
+       global $testsuite_file, $test_static_dir;
+
+       /*
+        * 1/ create test database with altered name and owner
+        * 2/ alter its owner
+        * 3/ alter its name, owner and comment back to normal
+        * NB: droping database is in the cleantests.php tests
+        */
+       $t = new TestBuilder("{$test_static_dir}/{$server['desc']}/database.html", $server['desc'],
+               'Database tests',
+               'Create and Alter database.'
+       );
+
+       $t->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);
+?>
similarity index 73%
rename from tests/selenium/src/cleantests.php
rename to tests/selenium/src/03-cleantests.php
index 8cfffa4e122f0ebd32bab083de6031c06a016d50..15d61934c7ca3be2496a8ec87a18d75890bedc61 100644 (file)
@@ -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}");
                $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']}");
index 47b93ce8a7edd16308eedca92be0a403732fa7ad..7a695e5cabbed3403c14546bfdd8e7f4fa16a68c 100644 (file)
                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)
                        );
                        $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)