introduce testbase class and make all tests runnable standalone

git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@410 b3834d28-1941-0410-a4f8-b48e95affb8f
This commit is contained in:
cweiske 2009-10-25 15:31:31 +00:00
parent 9a0aefc28b
commit 05defe72d8
10 changed files with 358 additions and 97 deletions

View file

@ -32,12 +32,12 @@ class AllTests extends PHPUnit_Framework_TestSuite
{ {
$suite = new AllTests(); $suite = new AllTests();
$tdir = dirname(__FILE__); $tdir = dirname(__FILE__);
$suite->addTestFile($tdir . '/BookmarksTest.php'); $suite->addTestFile($tdir . '/BookmarkTest.php');
$suite->addTestFile($tdir . '/Tag2TagTest.php'); $suite->addTestFile($tdir . '/Tag2TagTest.php');
$suite->addTestFile($tdir . '/TagsCacheTest.php'); $suite->addTestFile($tdir . '/TagsCacheTest.php');
$suite->addTestFile($tdir . '/CommonDescriptionTest.php'); $suite->addTestFile($tdir . '/CommonDescriptionTest.php');
$suite->addTestFile($tdir . '/SearchTest.php'); $suite->addTestFile($tdir . '/SearchHistoryTest.php');
$suite->addTestFile($tdir . '/TagsTest.php'); $suite->addTestFile($tdir . '/TagTest.php');
$suite->addTestFile($tdir . '/VoteTest.php'); $suite->addTestFile($tdir . '/VoteTest.php');
return $suite; return $suite;
} }

View file

@ -1,25 +1,57 @@
<?php <?php
require_once 'PHPUnit/Framework.php'; /**
* SemanticScuttle - your social bookmark manager.
/* *
To launch this test, type the following line into a shell * PHP version 5.
into the tests/ directory : *
phpunit BookmarksTest tests/boomarksTest.php * @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 $us;
protected $bs; protected $bs;
protected $ts; protected $ts;
protected $tts; 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() 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->us =SemanticScuttle_Service_Factory::get('User');
$this->bs =SemanticScuttle_Service_Factory::get('Bookmark'); $this->bs =SemanticScuttle_Service_Factory::get('Bookmark');
$this->bs->deleteAll(); $this->bs->deleteAll();
@ -72,5 +104,17 @@ class BookmarksTest extends PHPUnit_Framework_TestCase
$this->assertEquals(1, $bookmarks['total']); $this->assertEquals(1, $bookmarks['total']);
}*/ }*/
public function testDeleteBookmark()
{
//FIXME
}
}
if (PHPUnit_MAIN_METHOD == 'BookmarkTest::main') {
BookmarkTest::main();
} }
?> ?>

View file

@ -1,13 +1,32 @@
<?php <?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
*/
/* require_once 'prepare.php';
To launch this test, type the following line into a shell
at the root of the scuttlePlus directory :
phpunit CommonDescriptionTest tests/commonDescriptionTest.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 $us;
protected $bs; protected $bs;
@ -16,22 +35,35 @@ class CommonDescriptionTest extends PHPUnit_Framework_TestCase
protected $tsts; protected $tsts;
protected $cds; 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() protected function setUp()
{ {
global $dbhost, $dbuser, $dbpass, $dbname, $dbport, $dbpersist, $dbtype, $tableprefix; $this->us =SemanticScuttle_Service_Factory::get('User');
require_once dirname(__FILE__) . '/../src/SemanticScuttle/header.php'; $this->bs =SemanticScuttle_Service_Factory::get('Bookmark');
$this->bs->deleteAll();
$this->us =SemanticScuttle_Service_Factory::get('User'); $this->b2ts =SemanticScuttle_Service_Factory::get('Bookmark2Tag');
$this->bs =SemanticScuttle_Service_Factory::get('Bookmark'); $this->b2ts->deleteAll();
$this->bs->deleteAll(); $this->tts =SemanticScuttle_Service_Factory::get('Tag2Tag');
$this->b2ts =SemanticScuttle_Service_Factory::get('Bookmark2Tag'); $this->tts->deleteAll();
$this->b2ts->deleteAll(); $this->tsts =SemanticScuttle_Service_Factory::get('TagStat');
$this->tts =SemanticScuttle_Service_Factory::get('Tag2Tag'); $this->tsts->deleteAll();
$this->tts->deleteAll(); $this->cds =SemanticScuttle_Service_Factory::get('CommonDescription');
$this->tsts =SemanticScuttle_Service_Factory::get('TagStat'); $this->cds->deleteAll();
$this->tsts->deleteAll();
$this->cds =SemanticScuttle_Service_Factory::get('CommonDescription');
$this->cds->deleteAll();
} }
public function testModifyDescription() public function testModifyDescription()
@ -93,4 +125,9 @@ class CommonDescriptionTest extends PHPUnit_Framework_TestCase
} }
} }
if (PHPUnit_MAIN_METHOD == 'CommonDescriptionTest::main') {
CommonDescriptionTest::main();
}
?> ?>

View file

@ -1,13 +1,32 @@
<?php <?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
*/
/* require_once 'prepare.php';
To launch this test, type the following line into a shell
at the root of the scuttlePlus directory :
phpunit SearchTest tests/searchTest.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 $us;
protected $bs; protected $bs;
@ -15,11 +34,25 @@ class SearchTest extends PHPUnit_Framework_TestCase
protected $tts; protected $tts;
protected $shs; 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() 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->us =SemanticScuttle_Service_Factory::get('User');
$this->bs =SemanticScuttle_Service_Factory::get('Bookmark'); $this->bs =SemanticScuttle_Service_Factory::get('Bookmark');
$this->bs->deleteAll(); $this->bs->deleteAll();
@ -77,4 +110,10 @@ class SearchTest extends PHPUnit_Framework_TestCase
$this->assertSame(2, count($searches)); $this->assertSame(2, count($searches));
} }
} }
if (PHPUnit_MAIN_METHOD == 'SearchHistoryTest::main') {
SearchHistoryTest::main();
}
?> ?>

View file

@ -1,24 +1,57 @@
<?php <?php
require_once 'PHPUnit/Framework.php'; /**
* SemanticScuttle - your social bookmark manager.
/* *
To launch this test, type the following line into a shell * PHP version 5.
at the root of the scuttlePlus directory : *
phpunit Tag2TagTest tests/tag2TagTest.php * @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 $us;
protected $bs; protected $bs;
protected $b2ts; protected $b2ts;
protected $tts; 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() 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->us =SemanticScuttle_Service_Factory::get('User');
$this->bs =SemanticScuttle_Service_Factory::get('Bookmark'); $this->bs =SemanticScuttle_Service_Factory::get('Bookmark');
$this->bs->deleteAll(); $this->bs->deleteAll();
@ -482,4 +515,8 @@ class Tag2TagTest extends PHPUnit_Framework_TestCase
}*/ }*/
} }
if (PHPUnit_MAIN_METHOD == 'Tag2TagTest::main') {
Tag2TagTest::main();
}
?> ?>

View file

@ -1,21 +1,54 @@
<?php <?php
require_once 'PHPUnit/Framework.php'; /**
* SemanticScuttle - your social bookmark manager.
/* *
To launch this test, type the following line into a shell * PHP version 5.
at the root of the scuttlePlus directory : *
phpunit TagsTest tests/tagsTest.php * @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; 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() 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 =SemanticScuttle_Service_Factory::get('Tag');
$this->ts->deleteAll(); $this->ts->deleteAll();
$this->us =SemanticScuttle_Service_Factory::get('User'); $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();
}
?> ?>

View file

@ -1,12 +1,31 @@
<?php <?php
require_once 'PHPUnit/Framework.php'; /**
* SemanticScuttle - your social bookmark manager.
/* *
To launch this test, type the following line into a shell * PHP version 5.
at the root of the scuttlePlus directory : *
phpunit TagsCacheTest tests/tagsCacheTest.php * @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 class TagsCacheTest extends PHPUnit_Framework_TestCase
{ {
protected $us; protected $us;
@ -14,6 +33,21 @@ class TagsCacheTest extends PHPUnit_Framework_TestCase
protected $b2ts; protected $b2ts;
protected $tts; 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() protected function setUp()
{ {
global $dbhost, $dbuser, $dbpass, $dbname, $dbport, $dbpersist, $dbtype, $tableprefix, $TEMPLATES_DIR, $debugMode; 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)); $this->assertEquals(array(), $tcs->getSynonyms('d', 1));
} }
} }
if (PHPUnit_MAIN_METHOD == 'TagsCacheTest::main') {
TagsCacheTest::main();
}
?> ?>

49
tests/TestBase.php Normal file
View file

@ -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;
}
}
?>

View file

@ -12,7 +12,6 @@
*/ */
require_once 'prepare.php'; require_once 'prepare.php';
require_once 'PHPUnit/Framework.php';
if (!defined('PHPUnit_MAIN_METHOD')) { if (!defined('PHPUnit_MAIN_METHOD')) {
define('PHPUnit_MAIN_METHOD', 'VoteTest::main'); define('PHPUnit_MAIN_METHOD', 'VoteTest::main');
@ -27,7 +26,7 @@ if (!defined('PHPUnit_MAIN_METHOD')) {
* @license GPL http://www.gnu.org/licenses/gpl.html * @license GPL http://www.gnu.org/licenses/gpl.html
* @link http://sourceforge.net/projects/semanticscuttle * @link http://sourceforge.net/projects/semanticscuttle
*/ */
class VoteTest extends PHPUnit_Framework_TestCase class VoteTest extends TestBase
{ {
/** /**
* Vote service instance to test. * 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. * 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)); $this->assertEquals(-1, $this->vs->getVote($bid, $uid));
} }
}//class VoteTest extends PHPUnit_Framework_TestCase }//class VoteTest extends TestBase
if (PHPUnit_MAIN_METHOD == 'VoteTest::main') { if (PHPUnit_MAIN_METHOD == 'VoteTest::main') {

View file

@ -5,5 +5,6 @@
$_SERVER['HTTP_HOST'] = 'http://localhost/'; $_SERVER['HTTP_HOST'] = 'http://localhost/';
define('UNIT_TEST_MODE', true); 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';
?> ?>