]> gitweb.fluxo.info Git - semanticscuttle.git/commitdiff
introduce testbase class and make all tests runnable standalone
authorcweiske <cweiske@b3834d28-1941-0410-a4f8-b48e95affb8f>
Sun, 25 Oct 2009 15:31:31 +0000 (15:31 +0000)
committercweiske <cweiske@b3834d28-1941-0410-a4f8-b48e95affb8f>
Sun, 25 Oct 2009 15:31:31 +0000 (15:31 +0000)
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@410 b3834d28-1941-0410-a4f8-b48e95affb8f

tests/AllTests.php
tests/BookmarkTest.php [moved from tests/BookmarksTest.php with 64% similarity]
tests/CommonDescriptionTest.php
tests/SearchHistoryTest.php [moved from tests/SearchTest.php with 66% similarity]
tests/Tag2TagTest.php
tests/TagTest.php [moved from tests/TagsTest.php with 66% similarity]
tests/TagsCacheTest.php
tests/TestBase.php [new file with mode: 0644]
tests/VoteTest.php
tests/prepare.php

index b1e13b497af65d85b7dd7b8e0f32ccdb7631d58a..4507a5a90210ea35141e54d307d4cd53d3382f22 100644 (file)
@@ -32,12 +32,12 @@ class AllTests extends PHPUnit_Framework_TestSuite
     {
        $suite = new AllTests();
         $tdir = dirname(__FILE__);
-       $suite->addTestFile($tdir . '/BookmarksTest.php');
+       $suite->addTestFile($tdir . '/BookmarkTest.php');
        $suite->addTestFile($tdir . '/Tag2TagTest.php'); 
        $suite->addTestFile($tdir . '/TagsCacheTest.php');
        $suite->addTestFile($tdir . '/CommonDescriptionTest.php');      
-       $suite->addTestFile($tdir . '/SearchTest.php'); 
-       $suite->addTestFile($tdir . '/TagsTest.php');
+       $suite->addTestFile($tdir . '/SearchHistoryTest.php'); 
+       $suite->addTestFile($tdir . '/TagTest.php');
        $suite->addTestFile($tdir . '/VoteTest.php');
         return $suite;
     }
similarity index 64%
rename from tests/BookmarksTest.php
rename to tests/BookmarkTest.php
index 75200582c3fbb855171912b0361072444ae1114e..f42880ab4b732ff0ffd3b812aa1f680fb5ca98c5 100644 (file)
@@ -1,25 +1,57 @@
 <?php
-require_once 'PHPUnit/Framework.php';
-
-/*
- To launch this test, type the following line into a shell
- into the tests/ directory :
-     phpunit BookmarksTest tests/boomarksTest.php
+/**
+ * SemanticScuttle - your social bookmark manager.
+ *
+ * PHP version 5.
+ *
+ * @category Bookmarking
+ * @package  SemanticScuttle
+ * @author   Christian Weiske <cweiske@cweiske.de>
+ * @license  GPL http://www.gnu.org/licenses/gpl.html
+ * @link     http://sourceforge.net/projects/semanticscuttle
  */
 
-class BookmarksTest extends PHPUnit_Framework_TestCase
+require_once 'prepare.php';
+
+if (!defined('PHPUnit_MAIN_METHOD')) {
+    define('PHPUnit_MAIN_METHOD', 'BookmarkTest::main');
+}
+
+/**
+ * Unit tests for the SemanticScuttle bookmark service.
+ *
+ * @category Bookmarking
+ * @package  SemanticScuttle
+ * @author Christian Weiske <cweiske@cweiske.de>
+ * @license  GPL http://www.gnu.org/licenses/gpl.html
+ * @link     http://sourceforge.net/projects/semanticscuttle
+ */
+class BookmarkTest extends TestBase
 {
        protected $us;
        protected $bs;
        protected $ts;
        protected $tts;
 
+
+
+    /**
+     * Used to run this test class standalone
+     *
+     * @return void
+     */
+    public static function main()
+    {
+        require_once 'PHPUnit/TextUI/TestRunner.php';
+        PHPUnit_TextUI_TestRunner::run(
+            new PHPUnit_Framework_TestSuite(__CLASS__)
+        );
+    }
+
+
+
        protected function setUp()
        {
-               global $dbhost, $dbuser, $dbpass, $dbname, $dbport, $dbpersist, $dbtype,
-            $tableprefix, $TEMPLATES_DIR, $filetypes, $debugMode;
-               require_once dirname(__FILE__) . '/../src/SemanticScuttle/header.php';
-
                $this->us =SemanticScuttle_Service_Factory::get('User');
                $this->bs =SemanticScuttle_Service_Factory::get('Bookmark');
                $this->bs->deleteAll();
@@ -72,5 +104,17 @@ class BookmarksTest extends PHPUnit_Framework_TestCase
         $this->assertEquals(1, $bookmarks['total']);
         }*/
 
+
+
+    public function testDeleteBookmark()
+    {
+        //FIXME
+    }
+
+}
+
+
+if (PHPUnit_MAIN_METHOD == 'BookmarkTest::main') {
+    BookmarkTest::main();
 }
 ?>
index 3f6917e05b9cc953c97d19362293b187e6873b44..93fcc534aec65309a5978c2b8a985ab1dfabfb3f 100644 (file)
@@ -1,13 +1,32 @@
 <?php
-require_once 'PHPUnit/Framework.php';
+/**
+ * SemanticScuttle - your social bookmark manager.
+ *
+ * PHP version 5.
+ *
+ * @category Bookmarking
+ * @package  SemanticScuttle
+ * @author   Christian Weiske <cweiske@cweiske.de>
+ * @license  GPL http://www.gnu.org/licenses/gpl.html
+ * @link     http://sourceforge.net/projects/semanticscuttle
+ */
 
-/*
-To launch this test, type the following line into a shell
-at the root of the scuttlePlus directory :
-     phpunit CommonDescriptionTest tests/commonDescriptionTest.php
-*/
+require_once 'prepare.php';
 
-class CommonDescriptionTest extends PHPUnit_Framework_TestCase
+if (!defined('PHPUnit_MAIN_METHOD')) {
+    define('PHPUnit_MAIN_METHOD', 'CommonDescriptionTest::main');
+}
+
+/**
+ * Unit tests for the SemanticScuttle common description service.
+ *
+ * @category Bookmarking
+ * @package  SemanticScuttle
+ * @author Christian Weiske <cweiske@cweiske.de>
+ * @license  GPL http://www.gnu.org/licenses/gpl.html
+ * @link     http://sourceforge.net/projects/semanticscuttle
+ */
+class CommonDescriptionTest extends TestBase
 {
     protected $us;
     protected $bs;
@@ -15,23 +34,36 @@ class CommonDescriptionTest extends PHPUnit_Framework_TestCase
     protected $tts;
     protected $tsts;
     protected $cds;
+
+
+
+    /**
+     * Used to run this test class standalone
+     *
+     * @return void
+     */
+    public static function main()
+    {
+        require_once 'PHPUnit/TextUI/TestRunner.php';
+        PHPUnit_TextUI_TestRunner::run(
+            new PHPUnit_Framework_TestSuite(__CLASS__)
+        );
+    }
+
  
     protected function setUp()
     {
-        global $dbhost, $dbuser, $dbpass, $dbname, $dbport, $dbpersist, $dbtype, $tableprefix;
-               require_once dirname(__FILE__) . '/../src/SemanticScuttle/header.php';
-
-       $this->us =SemanticScuttle_Service_Factory::get('User');
-       $this->bs =SemanticScuttle_Service_Factory::get('Bookmark');
-       $this->bs->deleteAll();
-       $this->b2ts =SemanticScuttle_Service_Factory::get('Bookmark2Tag');
-       $this->b2ts->deleteAll();
-       $this->tts =SemanticScuttle_Service_Factory::get('Tag2Tag');
-       $this->tts->deleteAll(); 
-       $this->tsts =SemanticScuttle_Service_Factory::get('TagStat');
-       $this->tsts->deleteAll();
-       $this->cds =SemanticScuttle_Service_Factory::get('CommonDescription');
-       $this->cds->deleteAll();
+        $this->us =SemanticScuttle_Service_Factory::get('User');
+        $this->bs =SemanticScuttle_Service_Factory::get('Bookmark');
+        $this->bs->deleteAll();
+        $this->b2ts =SemanticScuttle_Service_Factory::get('Bookmark2Tag');
+        $this->b2ts->deleteAll();
+        $this->tts =SemanticScuttle_Service_Factory::get('Tag2Tag');
+        $this->tts->deleteAll(); 
+        $this->tsts =SemanticScuttle_Service_Factory::get('TagStat');
+        $this->tsts->deleteAll();
+        $this->cds =SemanticScuttle_Service_Factory::get('CommonDescription');
+        $this->cds->deleteAll();
     }
  
     public function testModifyDescription()
@@ -93,4 +125,9 @@ class CommonDescriptionTest extends PHPUnit_Framework_TestCase
     }
 
 }
+
+
+if (PHPUnit_MAIN_METHOD == 'CommonDescriptionTest::main') {
+    CommonDescriptionTest::main();
+}
 ?>
similarity index 66%
rename from tests/SearchTest.php
rename to tests/SearchHistoryTest.php
index 3aa49de1b1c0c5bb94eed9da0f668e9fc8aa830c..2421a205dd1957b5f583b3a87bcde867f807e832 100644 (file)
@@ -1,25 +1,58 @@
 <?php
-require_once 'PHPUnit/Framework.php';
+/**
+ * SemanticScuttle - your social bookmark manager.
+ *
+ * PHP version 5.
+ *
+ * @category Bookmarking
+ * @package  SemanticScuttle
+ * @author   Christian Weiske <cweiske@cweiske.de>
+ * @license  GPL http://www.gnu.org/licenses/gpl.html
+ * @link     http://sourceforge.net/projects/semanticscuttle
+ */
 
-/*
-To launch this test, type the following line into a shell
-at the root of the scuttlePlus directory :
-     phpunit SearchTest tests/searchTest.php
-*/
+require_once 'prepare.php';
 
-class SearchTest extends PHPUnit_Framework_TestCase
+if (!defined('PHPUnit_MAIN_METHOD')) {
+    define('PHPUnit_MAIN_METHOD', 'SearchHistoryTest::main');
+}
+
+/**
+ * Unit tests for the SemanticScuttle search history service.
+ *
+ * @category Bookmarking
+ * @package  SemanticScuttle
+ * @author Christian Weiske <cweiske@cweiske.de>
+ * @license  GPL http://www.gnu.org/licenses/gpl.html
+ * @link     http://sourceforge.net/projects/semanticscuttle
+ */
+class SearchHistoryTest extends TestBase
 {
     protected $us;
     protected $bs;
     protected $b2ts;
     protected $tts;
     protected $shs;
+
+
+
+    /**
+     * Used to run this test class standalone
+     *
+     * @return void
+     */
+    public static function main()
+    {
+        require_once 'PHPUnit/TextUI/TestRunner.php';
+        PHPUnit_TextUI_TestRunner::run(
+            new PHPUnit_Framework_TestSuite(__CLASS__)
+        );
+    }
+
+
  
     protected function setUp()
     {
-        global $dbhost, $dbuser, $dbpass, $dbname, $dbport, $dbpersist, $dbtype, $tableprefix;
-               require_once dirname(__FILE__) . '/../src/SemanticScuttle/header.php';
-
        $this->us =SemanticScuttle_Service_Factory::get('User');
        $this->bs =SemanticScuttle_Service_Factory::get('Bookmark');
        $this->bs->deleteAll();
@@ -77,4 +110,10 @@ class SearchTest extends PHPUnit_Framework_TestCase
        $this->assertSame(2, count($searches));
     }
 }
+
+
+if (PHPUnit_MAIN_METHOD == 'SearchHistoryTest::main') {
+    SearchHistoryTest::main();
+}
+
 ?>
index 8b230400676a151586421dab78dd32d448358e27..8a198239a944b3495ed8764cdde624a483f464fd 100644 (file)
@@ -1,24 +1,57 @@
 <?php
-require_once 'PHPUnit/Framework.php';
-
-/*
- To launch this test, type the following line into a shell
- at the root of the scuttlePlus directory :
- phpunit Tag2TagTest tests/tag2TagTest.php
+/**
+ * SemanticScuttle - your social bookmark manager.
+ *
+ * PHP version 5.
+ *
+ * @category Bookmarking
+ * @package  SemanticScuttle
+ * @author   Christian Weiske <cweiske@cweiske.de>
+ * @license  GPL http://www.gnu.org/licenses/gpl.html
+ * @link     http://sourceforge.net/projects/semanticscuttle
  */
 
-class Tag2TagTest extends PHPUnit_Framework_TestCase
+require_once 'prepare.php';
+
+if (!defined('PHPUnit_MAIN_METHOD')) {
+    define('PHPUnit_MAIN_METHOD', 'Tag2TagTest::main');
+}
+
+/**
+ * Unit tests for the SemanticScuttle tag2tag service.
+ *
+ * @category Bookmarking
+ * @package  SemanticScuttle
+ * @author Christian Weiske <cweiske@cweiske.de>
+ * @license  GPL http://www.gnu.org/licenses/gpl.html
+ * @link     http://sourceforge.net/projects/semanticscuttle
+ */
+class Tag2TagTest extends TestBase
 {
        protected $us;
        protected $bs;
        protected $b2ts;
        protected $tts;
 
+
+
+    /**
+     * Used to run this test class standalone
+     *
+     * @return void
+     */
+    public static function main()
+    {
+        require_once 'PHPUnit/TextUI/TestRunner.php';
+        PHPUnit_TextUI_TestRunner::run(
+            new PHPUnit_Framework_TestSuite(__CLASS__)
+        );
+    }
+
+
+
        protected function setUp()
        {
-               global $dbhost, $dbuser, $dbpass, $dbname, $dbport, $dbpersist, $dbtype, $tableprefix;
-               require_once dirname(__FILE__) . '/../src/SemanticScuttle/header.php';
-
                $this->us =SemanticScuttle_Service_Factory::get('User');
                $this->bs =SemanticScuttle_Service_Factory::get('Bookmark');
                $this->bs->deleteAll();
@@ -482,4 +515,8 @@ class Tag2TagTest extends PHPUnit_Framework_TestCase
 
         }*/
 }
+
+if (PHPUnit_MAIN_METHOD == 'Tag2TagTest::main') {
+    Tag2TagTest::main();
+}
 ?>
similarity index 66%
rename from tests/TagsTest.php
rename to tests/TagTest.php
index f07e04f68b0944d6d970b2db71aa678e45444870..2cc6d44ddfe68f519789f24646428dacd6c11202 100644 (file)
@@ -1,21 +1,54 @@
 <?php
-require_once 'PHPUnit/Framework.php';
-
-/*
- To launch this test, type the following line into a shell
- at the root of the scuttlePlus directory :
- phpunit TagsTest tests/tagsTest.php
+/**
+ * SemanticScuttle - your social bookmark manager.
+ *
+ * PHP version 5.
+ *
+ * @category Bookmarking
+ * @package  SemanticScuttle
+ * @author   Christian Weiske <cweiske@cweiske.de>
+ * @license  GPL http://www.gnu.org/licenses/gpl.html
+ * @link     http://sourceforge.net/projects/semanticscuttle
  */
 
-class TagsTest extends PHPUnit_Framework_TestCase
+require_once 'prepare.php';
+
+if (!defined('PHPUnit_MAIN_METHOD')) {
+    define('PHPUnit_MAIN_METHOD', 'TagTest::main');
+}
+
+/**
+ * Unit tests for the SemanticScuttle tag service.
+ *
+ * @category Bookmarking
+ * @package  SemanticScuttle
+ * @author Christian Weiske <cweiske@cweiske.de>
+ * @license  GPL http://www.gnu.org/licenses/gpl.html
+ * @link     http://sourceforge.net/projects/semanticscuttle
+ */
+class TagTest extends TestBase
 {
        protected $ts;
 
+
+
+    /**
+     * Used to run this test class standalone
+     *
+     * @return void
+     */
+    public static function main()
+    {
+        require_once 'PHPUnit/TextUI/TestRunner.php';
+        PHPUnit_TextUI_TestRunner::run(
+            new PHPUnit_Framework_TestSuite(__CLASS__)
+        );
+    }
+
+
+
        protected function setUp()
        {
-               global $dbhost, $dbuser, $dbpass, $dbname, $dbport, $dbpersist, $dbtype, $tableprefix;
-               require_once dirname(__FILE__) . '/../src/SemanticScuttle/header.php';
-
                $this->ts =SemanticScuttle_Service_Factory::get('Tag');
                $this->ts->deleteAll();
                $this->us =SemanticScuttle_Service_Factory::get('User');
@@ -73,4 +106,9 @@ class TagsTest extends PHPUnit_Framework_TestCase
        }
 
 }
+
+
+if (PHPUnit_MAIN_METHOD == 'TagTest::main') {
+    TagTest::main();
+}
 ?>
index 8e15f2d5a61273464d96f570c0e112ed7219a2e1..9230f1caad303f5fe5a0a141426005876f255ba6 100644 (file)
@@ -1,12 +1,31 @@
 <?php
-require_once 'PHPUnit/Framework.php';
-
-/*
- To launch this test, type the following line into a shell
- at the root of the scuttlePlus directory :
- phpunit TagsCacheTest tests/tagsCacheTest.php
+/**
+ * SemanticScuttle - your social bookmark manager.
+ *
+ * PHP version 5.
+ *
+ * @category Bookmarking
+ * @package  SemanticScuttle
+ * @author   Christian Weiske <cweiske@cweiske.de>
+ * @license  GPL http://www.gnu.org/licenses/gpl.html
+ * @link     http://sourceforge.net/projects/semanticscuttle
  */
 
+require_once 'prepare.php';
+
+if (!defined('PHPUnit_MAIN_METHOD')) {
+    define('PHPUnit_MAIN_METHOD', 'TagsCacheTest::main');
+}
+
+/**
+ * Unit tests for the SemanticScuttle tags cache service.
+ *
+ * @category Bookmarking
+ * @package  SemanticScuttle
+ * @author Christian Weiske <cweiske@cweiske.de>
+ * @license  GPL http://www.gnu.org/licenses/gpl.html
+ * @link     http://sourceforge.net/projects/semanticscuttle
+ */
 class TagsCacheTest extends PHPUnit_Framework_TestCase
 {
        protected $us;
@@ -14,6 +33,21 @@ class TagsCacheTest extends PHPUnit_Framework_TestCase
        protected $b2ts;
        protected $tts;
 
+
+
+    /**
+     * Used to run this test class standalone
+     *
+     * @return void
+     */
+    public static function main()
+    {
+        require_once 'PHPUnit/TextUI/TestRunner.php';
+        PHPUnit_TextUI_TestRunner::run(
+            new PHPUnit_Framework_TestSuite(__CLASS__)
+        );
+    }
+
        protected function setUp()
        {
                global $dbhost, $dbuser, $dbpass, $dbname, $dbport, $dbpersist, $dbtype, $tableprefix, $TEMPLATES_DIR, $debugMode;
@@ -173,4 +207,9 @@ class TagsCacheTest extends PHPUnit_Framework_TestCase
                $this->assertEquals(array(), $tcs->getSynonyms('d', 1));
        }
 }
+
+if (PHPUnit_MAIN_METHOD == 'TagsCacheTest::main') {
+    TagsCacheTest::main();
+}
+
 ?>
diff --git a/tests/TestBase.php b/tests/TestBase.php
new file mode 100644 (file)
index 0000000..dc5643f
--- /dev/null
@@ -0,0 +1,49 @@
+<?php
+/**
+ * SemanticScuttle - your social bookmark manager.
+ *
+ * PHP version 5.
+ *
+ * @category Bookmarking
+ * @package  SemanticScuttle
+ * @author   Christian Weiske <cweiske@cweiske.de>
+ * @license  GPL http://www.gnu.org/licenses/gpl.html
+ * @link     http://sourceforge.net/projects/semanticscuttle
+ */
+
+require_once 'PHPUnit/Framework.php';
+
+/**
+ * Base unittest class that provides several helper methods.
+ *
+ * @category Bookmarking
+ * @package  SemanticScuttle
+ * @author Christian Weiske <cweiske@cweiske.de>
+ * @license  GPL http://www.gnu.org/licenses/gpl.html
+ * @link     http://sourceforge.net/projects/semanticscuttle
+ */
+class TestBase extends PHPUnit_Framework_TestCase
+{
+    /**
+     * Create a new bookmark.
+     *
+     * @return integer ID of bookmark
+     */
+    protected function addBookmark()
+    {
+        $bs = SemanticScuttle_Service_Factory::get('Bookmark');
+        $rand = rand();
+        $bid = $bs->addBookmark(
+            'http://example.org/' . $rand,
+            'unittest bookmark #' . $rand,
+            'description',
+            null,
+            0,
+            array('unittest')
+        );
+        return $bid;
+    }
+
+}
+
+?>
\ No newline at end of file
index 01960713ed235f728691718e15ccc7cf4e673198..90611d1f0cf1442a442f7f46c7bd54f10fe6f835 100644 (file)
@@ -12,7 +12,6 @@
  */
 
 require_once 'prepare.php';
-require_once 'PHPUnit/Framework.php';
 
 if (!defined('PHPUnit_MAIN_METHOD')) {
     define('PHPUnit_MAIN_METHOD', 'VoteTest::main');
@@ -27,7 +26,7 @@ if (!defined('PHPUnit_MAIN_METHOD')) {
  * @license  GPL http://www.gnu.org/licenses/gpl.html
  * @link     http://sourceforge.net/projects/semanticscuttle
  */
-class VoteTest extends PHPUnit_Framework_TestCase
+class VoteTest extends TestBase
 {
     /**
      * Vote service instance to test.
@@ -62,28 +61,6 @@ class VoteTest extends PHPUnit_Framework_TestCase
 
 
 
-    /**
-     * Create a new bookmark.
-     *
-     * @return integer ID of bookmark
-     */
-    protected function addBookmark()
-    {
-        $bs = SemanticScuttle_Service_Factory::get('Bookmark');
-        $rand = rand();
-        $bid = $bs->addBookmark(
-            'http://example.org/' . $rand,
-            'unittest bookmark #' . $rand,
-            'description',
-            null,
-            0,
-            array('unittest')
-        );
-        return $bid;
-    }
-
-
-
     /**
      * Test getVoting() when no votes have been cast.
      *
@@ -345,7 +322,7 @@ class VoteTest extends PHPUnit_Framework_TestCase
         $this->assertEquals(-1, $this->vs->getVote($bid, $uid));
     }
 
-}//class VoteTest extends PHPUnit_Framework_TestCase
+}//class VoteTest extends TestBase
 
 
 if (PHPUnit_MAIN_METHOD == 'VoteTest::main') {
index 73d804d078d44c1677d1e43c668cd022f84e90ed..095cf36e7188ba1e95b8ed05fc4ba7bda37a083c 100644 (file)
@@ -5,5 +5,6 @@
 $_SERVER['HTTP_HOST'] = 'http://localhost/';
 define('UNIT_TEST_MODE', true);
 
-require_once dirname(__FILE__) . '/../src/SemanticScuttle/header.php'
+require_once dirname(__FILE__) . '/../src/SemanticScuttle/header.php';
+require_once dirname(__FILE__) . '/TestBase.php';
 ?>
\ No newline at end of file