From 12d42f291818a3fe72c412b549a9b53241efda3e Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Thu, 13 Dec 2007 14:14:56 +0000 Subject: [PATCH] Reorganize test suite. - Split testLoginLogout() into testBadLogin() and testLoginLogout(). - Mark testCreateSimpleArticle() as incomplete until the popup window opened by clicking on VIEW is handled correctly. - Disable mod_rewrite so that the test suite does not depend on it. - Remove superfluous check for Testing_Selenium class. - Migrate TestConfiguration.php.dist to config.xml.dist. - Configure whitelist for code coverage information. - Be conservative for now and only add include/ and plugins/ directories for now. - Set addUncoveredFilesFromWhitelist="false" because not all files are loadable (yet). - Add documentation for code coverage reporting. --- ...endipityTestSuite.php => FrontendTest.php} | 91 +++++++++++-------- tests/README | 40 ++++++++ tests/config.xml.dist | 27 ++++++ tests/coverage/append.php | 20 ++++ tests/coverage/phpunit_coverage.php | 36 ++++++++ tests/coverage/prepend.php | 9 ++ tests/gui/README | 23 ----- tests/gui/TestConfiguration.php.dist | 11 --- 8 files changed, 184 insertions(+), 73 deletions(-) rename tests/{gui/SerendipityTestSuite.php => FrontendTest.php} (82%) create mode 100644 tests/README create mode 100644 tests/config.xml.dist create mode 100644 tests/coverage/append.php create mode 100644 tests/coverage/phpunit_coverage.php create mode 100644 tests/coverage/prepend.php delete mode 100644 tests/gui/README delete mode 100644 tests/gui/TestConfiguration.php.dist diff --git a/tests/gui/SerendipityTestSuite.php b/tests/FrontendTest.php similarity index 82% rename from tests/gui/SerendipityTestSuite.php rename to tests/FrontendTest.php index bca839da..b40c6331 100644 --- a/tests/gui/SerendipityTestSuite.php +++ b/tests/FrontendTest.php @@ -1,59 +1,56 @@ markTestSkipped( 'The Selenium tests are disabled.' ); } - if (!class_exists('Testing_Selenium')) { - $this->markTestSkipped( - 'The PHP bindings for Selenium RC are not installed.' - ); - } - - $this->setHost(SELENIUM_HOST); - $this->setPort(SELENIUM_PORT); - $this->setBrowser(SELENIUM_BROWSER); - $this->setBrowserUrl(S9Y_INSTALLDIR); + $this->setHost($GLOBALS['S9Y_SELENIUM_HOST']); + $this->setPort((int)$GLOBALS['S9Y_SELENIUM_PORT']); + $this->setBrowser($GLOBALS['S9Y_SELENIUM_BROWSER']); + $this->setBrowserUrl($GLOBALS['S9Y_INSTALLDIR']); $this->setTimeout(10000); + + $this->coverageScriptUrl = $GLOBALS['S9Y_INSTALLDIR'] . + '/phpunit_coverage.php'; + + require_once '../lang/serendipity_lang_' . + $GLOBALS['S9Y_LANG'] . '.inc.php'; + require_once '../plugins/serendipity_event_spamblock/lang_' . + $GLOBALS['S9Y_LANG'] . '.inc.php'; } public function testExpertInstallation() { - $this->open(S9Y_INSTALLDIR); + $this->open($GLOBALS['S9Y_INSTALLDIR']); $this->assertTextNotPresent(NOT_WRITABLE); $this->clickAndWait('link='.EXPERT_INSTALLATION); $this->select('dbType', 'SQLite'); $this->type('user', 'Test User'); $this->type('pass', 'Test Password'); $this->check('radio_cfg_want_mail_no'); - $this->select('rewrite', 'Use Apache mod_rewrite'); $this->type('blogTitle', 's9y Testsuite Testblog'); $this->type('blogDescription', 'The lalaforce is coming to get you!'); $this->clickAndWait("//input[@value='".COMPLETE_INSTALLATION."']"); $this->assertTextPresent(SERENDIPITY_INSTALLED); } - public function testLoginLogout() + public function testBadLogin() { - $this->open(S9Y_INSTALLDIR); + $this->open($GLOBALS['S9Y_INSTALLDIR']); $this->assertTitleEquals('s9y Testsuite Testblog'); $this->assertTextPresent(SUPERUSER); @@ -66,6 +63,17 @@ class SerendipityTestSuite extends PHPUnit_Extensions_SeleniumTestCase $this->assertTextPresent(PLEASE_ENTER_CREDENTIALS); $this->assertTextPresent(WRONG_USERNAME_OR_PASSWORD); + } + + public function testLoginLogout() + { + $this->open($GLOBALS['S9Y_INSTALLDIR']); + + $this->assertTitleEquals('s9y Testsuite Testblog'); + $this->assertTextPresent(SUPERUSER); + $this->clickAndWait('link='.SUPERUSER_OPEN_LOGIN); + + $this->assertTextPresent(PLEASE_ENTER_CREDENTIALS); $this->type('serendipity[user]', 'Test User'); $this->type('serendipity[pass]', 'Test Password'); $this->clickAndWait('submit'); @@ -93,7 +101,7 @@ class SerendipityTestSuite extends PHPUnit_Extensions_SeleniumTestCase } public function testCreateContentCategory() { - $this->open(S9Y_INSTALLDIR); + $this->open($GLOBALS['S9Y_INSTALLDIR']); $this->assertTitleEquals('s9y Testsuite Testblog'); $this->assertTextPresent(SUPERUSER); @@ -134,21 +142,21 @@ class SerendipityTestSuite extends PHPUnit_Extensions_SeleniumTestCase $this->assertTextPresent('Test Category 001-1'); -# The Sub-Sub-Category-Test is blocked by http://pear.php.net/bugs/bug.php?id=9189 -# -# $this->clickAndWait('link='.CREATE_NEW_CAT); -# -# $this->assertTextPresent(CREATE_NEW_CAT); -# $this->select('parent_cat', ' Test Category 001-1'); -# $this->type('serendipity[cat][name]', 'Test Category 001-1-1'); -# $this->type('serendipity[cat][description]', 'This is the description for Test Category 001-1-1'); -# $this->clickAndWait('SAVE'); -# -# $this->assertTextPresent('Test Category 001-1-1'); + $this->markTestIncomplete('Blocked by blocked by http://pear.php.net/bugs/bug.php?id=9189.'); + + $this->clickAndWait('link='.CREATE_NEW_CAT); + + $this->assertTextPresent(CREATE_NEW_CAT); + $this->select('parent_cat', ' Test Category 001-1'); + $this->type('serendipity[cat][name]', 'Test Category 001-1-1'); + $this->type('serendipity[cat][description]', 'This is the description for Test Category 001-1-1'); + $this->clickAndWait('SAVE'); + + $this->assertTextPresent('Test Category 001-1-1'); } public function testCreateSimpleArticle() { - $this->open(S9Y_INSTALLDIR); + $this->open($GLOBALS['S9Y_INSTALLDIR']); $this->assertTitleEquals('s9y Testsuite Testblog'); $this->assertTextPresent(SUPERUSER); @@ -169,10 +177,14 @@ class SerendipityTestSuite extends PHPUnit_Extensions_SeleniumTestCase $this->clickAndWait("//input[@value='- ".SAVE." -']"); $this->assertTextPresent(IFRAME_SAVE); + + $this->markTestIncomplete('Popup needs to be taken care of.'); + $this->clickAndWait('link='.VIEW); $this->assertTitleEquals('Test Entry 001 - s9y Testsuite Testblog'); $this->assertTextPresent('Test Body'); + $this->clickAndWait('link='.EDIT_ENTRY); $this->assertTextPresent(ENTRY_BODY); @@ -187,14 +199,15 @@ class SerendipityTestSuite extends PHPUnit_Extensions_SeleniumTestCase } public function testComment() { - $this->open(S9Y_INSTALLDIR); + $this->open($GLOBALS['S9Y_INSTALLDIR']); $this->assertTitleEquals('s9y Testsuite Testblog'); $this->assertTextPresent('Test Entry 001'); $this->clickAndWait('link=Test Entry 001'); $this->assertTitleEquals('Test Entry 001 - s9y Testsuite Testblog'); - $this->assertTextPresent('New Test Body'); + // Change to "New Test Body" when testCreateSimpleArticle() is fixed. + $this->assertTextPresent('Test Body'); $this->assertTextPresent(ADD_COMMENT); $this->clickAndWait("//input[@value='".SUBMIT_COMMENT."']"); @@ -221,7 +234,7 @@ class SerendipityTestSuite extends PHPUnit_Extensions_SeleniumTestCase } public function testCreateUser() { - $this->open(S9Y_INSTALLDIR); + $this->open($GLOBALS['S9Y_INSTALLDIR']); $this->assertTitleEquals('s9y Testsuite Testblog'); $this->assertTextPresent(SUPERUSER); diff --git a/tests/README b/tests/README new file mode 100644 index 00000000..0d7496ee --- /dev/null +++ b/tests/README @@ -0,0 +1,40 @@ +PHPUnit and Selenium RC +======================= + + 1. Install PHPUnit + + $ pear channel-discover pear.phpunit.de + + $ pear install phpunit/phpunit + + 2. Download Selenium RC and copy selenium-server.jar to + /usr/local/bin/selenium-server.jar, for instance. + + +Running the Tests +================= + + 1. Start the Selenium RC server + + $ java -jar /usr/local/bin/selenium-server.jar + + 2. $ cd /path/to/s9y/tests + + $ phpunit --configuration config.xml FrontendTest + + +Code Coverage +============= + + 1. Copy *.php to the S9Y installation directory on your webserver. + + 2. In your php.ini, add the following settings + + auto_prepend_file = /path/to/prepend.php + auto_append_file = /path/to/append.php + + 3. Use + + $ phpunit --configuration config.xml --coverage-html report FrontendTest + + instead of the command above. diff --git a/tests/config.xml.dist b/tests/config.xml.dist new file mode 100644 index 00000000..3b09121b --- /dev/null +++ b/tests/config.xml.dist @@ -0,0 +1,27 @@ + + + + + + ../include + ../plugins + + ../include/db/mysql.inc.php + ../include/db/mysqli.inc.php + ../include/db/pdo-postgres.inc.php + ../include/db/postgres.inc.php + ../include/db/mysql.inc.php + ../include/db/sqlite.inc.php + ../include/db/sqlrelay.inc.php + + + + + + + + + + + + diff --git a/tests/coverage/append.php b/tests/coverage/append.php new file mode 100644 index 00000000..cf05a534 --- /dev/null +++ b/tests/coverage/append.php @@ -0,0 +1,20 @@ + diff --git a/tests/coverage/phpunit_coverage.php b/tests/coverage/phpunit_coverage.php new file mode 100644 index 00000000..857c5339 --- /dev/null +++ b/tests/coverage/phpunit_coverage.php @@ -0,0 +1,36 @@ +getPathName(); + + $data = eval('return ' . file_get_contents($filename) . ';'); + unset($filename); + + foreach ($data as $filename => $lines) { + if (!isset($coverage[$filename])) { + $coverage[$filename] = $lines; + } else { + foreach ($lines as $line => $flag) { + if (!isset($coverage[$filename][$line]) || + $flag > $coverage[$filename][$line]) { + $coverage[$filename][$line] = $flag; + } + } + } + } + } + + var_export($coverage); +} +?> diff --git a/tests/coverage/prepend.php b/tests/coverage/prepend.php new file mode 100644 index 00000000..453e68f6 --- /dev/null +++ b/tests/coverage/prepend.php @@ -0,0 +1,9 @@ + diff --git a/tests/gui/README b/tests/gui/README deleted file mode 100644 index 6fad8cbd..00000000 --- a/tests/gui/README +++ /dev/null @@ -1,23 +0,0 @@ -Test setup instructions -======================= - -0.) Optionally Install VMWare Server - -1.) Install Java from http://java.sun.com/ - -2.) Get Selenium RC from http://www.openqa.org/selenium-rc/download.action - -3.) Install PHPUnit: - # pear install -f http://pear.phpunit.de/get/PHPUnit-3.0.0beta2.tgz - -4.) Install PHP Selenium Bindings: - # pear install -f Testing_Selenium - -5.) Copy TestConfiguration.php.dist to TestConfiguration.php and - change TestConfiguration.php to reflect your Selenium RC - configuration. - -6.) Run Tests - $ phpunit SeleniumTestSuite.php - --- end of file diff --git a/tests/gui/TestConfiguration.php.dist b/tests/gui/TestConfiguration.php.dist deleted file mode 100644 index d7357329..00000000 --- a/tests/gui/TestConfiguration.php.dist +++ /dev/null @@ -1,11 +0,0 @@ -