]> git.mjollnir.org Git - s9y.git/commitdiff
Reorganize test suite.
authors_bergmann <s_bergmann>
Thu, 13 Dec 2007 14:14:56 +0000 (14:14 +0000)
committers_bergmann <s_bergmann>
Thu, 13 Dec 2007 14:14:56 +0000 (14:14 +0000)
- 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.

tests/FrontendTest.php [moved from tests/gui/SerendipityTestSuite.php with 82% similarity]
tests/README [new file with mode: 0644]
tests/config.xml.dist [new file with mode: 0644]
tests/coverage/append.php [new file with mode: 0644]
tests/coverage/phpunit_coverage.php [new file with mode: 0644]
tests/coverage/prepend.php [new file with mode: 0644]
tests/gui/README [deleted file]
tests/gui/TestConfiguration.php.dist [deleted file]

similarity index 82%
rename from tests/gui/SerendipityTestSuite.php
rename to tests/FrontendTest.php
index bca839dabc6e6667c555001d99f00058877b6ba7..b40c63312eb8e61c9a27508fdba418ecb59166d4 100644 (file)
@@ -1,59 +1,56 @@
 <?php
-# Copyright (c) 2006, Sebastian Nohn (on behalf the Serendipity Developer Team)
+# Copyright (c) 2006-2007, Sebastian Nohn and Sebastian Bergmann
+# (on behalf the Serendipity Developer Team)
 # All rights reserved.  See LICENSE file for licensing details
 
 ini_set('display_errors', 1);
+define('IN_serendipity', TRUE);
 
-require_once 'PHPUnit/Framework/TestCase.php';
 require_once 'PHPUnit/Extensions/SeleniumTestCase.php';
 
-require_once 'TestConfiguration.php';
-
-require_once '../../lang/serendipity_lang_'.S9Y_LANG.'.inc.php';
-require_once '../../plugins/serendipity_event_spamblock/lang_'.S9Y_LANG.'.inc.php';
-
-class SerendipityTestSuite extends PHPUnit_Extensions_SeleniumTestCase
+class FrontendTest extends PHPUnit_Extensions_SeleniumTestCase
 {
     public function setUp()
     {
-        if (!SELENIUM_ENABLED) {
+        if (!isset($GLOBALS['S9Y_SELENIUM_ENABLED']) || !$GLOBALS['S9Y_SELENIUM_ENABLED']) {
             $this->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', '&nbsp;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', '&nbsp;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 (file)
index 0000000..0d7496e
--- /dev/null
@@ -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 (file)
index 0000000..3b09121
--- /dev/null
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<phpunit>
+  <filter>
+    <whitelist addUncoveredFilesFromWhitelist="false">
+      <directory>../include</directory>
+      <directory>../plugins</directory>
+        <exclude>
+          <file>../include/db/mysql.inc.php</file>
+          <file>../include/db/mysqli.inc.php</file>
+          <file>../include/db/pdo-postgres.inc.php</file>
+          <file>../include/db/postgres.inc.php</file>
+          <file>../include/db/mysql.inc.php</file>
+          <file>../include/db/sqlite.inc.php</file>
+          <file>../include/db/sqlrelay.inc.php</file>
+        </exclude>
+    </whitelist>
+  </filter>
+  <php>
+    <var name="S9Y_INSTALLDIR" value="http://localhost/s9y"/>
+    <var name="S9Y_LANG" value="en"/>
+    <var name="S9Y_SELENIUM_ENABLED" value="true"/>
+    <var name="S9Y_SELENIUM_HOST" value="127.0.0.1"/>
+    <var name="S9Y_SELENIUM_PORT" value="4444"/>
+    <var name="S9Y_SELENIUM_BROWSER" value="*firefox /usr/lib/firefox/firefox-bin"/>
+  </php>
+</phpunit>
diff --git a/tests/coverage/append.php b/tests/coverage/append.php
new file mode 100644 (file)
index 0000000..cf05a53
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+if ( isset($_COOKIE['PHPUNIT_SELENIUM_TEST_ID']) &&
+    !isset($_GET['PHPUNIT_SELENIUM_TEST_ID']) &&
+    extension_loaded('xdebug')) {
+    $GLOBALS['PHPUNIT_FILTERED_FILES'][] = __FILE__;
+
+    $data = xdebug_get_code_coverage();
+    xdebug_stop_code_coverage();
+
+    foreach ($GLOBALS['PHPUNIT_FILTERED_FILES'] as $file) {
+        unset($data[$file]);
+    }
+
+    file_put_contents(
+      $_SERVER['SCRIPT_FILENAME'] . '.phpunit_' .
+      $_COOKIE['PHPUNIT_SELENIUM_TEST_ID'],
+      var_export($data, TRUE)
+    );
+}
+?>
diff --git a/tests/coverage/phpunit_coverage.php b/tests/coverage/phpunit_coverage.php
new file mode 100644 (file)
index 0000000..857c533
--- /dev/null
@@ -0,0 +1,36 @@
+<?php
+require_once 'PHPUnit/Util/FilterIterator.php';
+
+if (isset($_GET['PHPUNIT_SELENIUM_TEST_ID'])) {
+    $files = new PHPUnit_Util_FilterIterator(
+      new RecursiveIteratorIterator(
+        new RecursiveDirectoryIterator(dirname(__FILE__))
+      ),
+      '.phpunit_' . $_GET['PHPUNIT_SELENIUM_TEST_ID']
+    );
+
+    $coverage = array();
+
+    foreach ($files as $file) {
+        $filename = $file->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 (file)
index 0000000..453e68f
--- /dev/null
@@ -0,0 +1,9 @@
+<?php
+if ( isset($_COOKIE['PHPUNIT_SELENIUM_TEST_ID']) &&
+    !isset($_GET['PHPUNIT_SELENIUM_TEST_ID']) &&
+    extension_loaded('xdebug')) {
+    $GLOBALS['PHPUNIT_FILTERED_FILES'] = array(__FILE__);
+
+    xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
+}
+?>
diff --git a/tests/gui/README b/tests/gui/README
deleted file mode 100644 (file)
index 6fad8cb..0000000
+++ /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 (file)
index d735732..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-<?php
-# Copyright (c) 2006, Sebastian Nohn (on behalf the Serendipity Developer Team)
-# All rights reserved.  See LICENSE file for licensing details
-
-define('SELENIUM_ENABLED', TRUE);
-define('SELENIUM_HOST',    '172.16.177.130');
-define('SELENIUM_PORT',    4444);
-define('SELENIUM_BROWSER', '*firefox');
-define('S9Y_INSTALLDIR',   'http://example.com/serendipity/');
-define('S9Y_LANG',         'en');
-?>