From 05defe72d8739c0642c506175c0ad4de2293fb99 Mon Sep 17 00:00:00 2001 From: cweiske Date: Sun, 25 Oct 2009 15:31:31 +0000 Subject: 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 --- tests/AllTests.php | 6 +- tests/BookmarkTest.php | 120 ++++++++++++++++++++++++++++++++++++++++ tests/BookmarksTest.php | 76 ------------------------- tests/CommonDescriptionTest.php | 79 +++++++++++++++++++------- tests/SearchHistoryTest.php | 119 +++++++++++++++++++++++++++++++++++++++ tests/SearchTest.php | 80 --------------------------- tests/Tag2TagTest.php | 57 +++++++++++++++---- tests/TagTest.php | 114 ++++++++++++++++++++++++++++++++++++++ tests/TagsCacheTest.php | 51 +++++++++++++++-- tests/TagsTest.php | 76 ------------------------- tests/TestBase.php | 49 ++++++++++++++++ tests/VoteTest.php | 27 +-------- tests/prepare.php | 3 +- 13 files changed, 559 insertions(+), 298 deletions(-) create mode 100644 tests/BookmarkTest.php delete mode 100644 tests/BookmarksTest.php create mode 100644 tests/SearchHistoryTest.php delete mode 100644 tests/SearchTest.php create mode 100644 tests/TagTest.php delete mode 100644 tests/TagsTest.php create mode 100644 tests/TestBase.php (limited to 'tests') diff --git a/tests/AllTests.php b/tests/AllTests.php index b1e13b4..4507a5a 100644 --- a/tests/AllTests.php +++ b/tests/AllTests.php @@ -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; } diff --git a/tests/BookmarkTest.php b/tests/BookmarkTest.php new file mode 100644 index 0000000..f42880a --- /dev/null +++ b/tests/BookmarkTest.php @@ -0,0 +1,120 @@ + + * @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', 'BookmarkTest::main'); +} + +/** + * Unit tests for the SemanticScuttle bookmark service. + * + * @category Bookmarking + * @package SemanticScuttle + * @author Christian Weiske + * @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() + { + $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(); + } + + public function testHardCharactersInBookmarks() + { + $bs = $this->bs; + $title = "title&é\"'(-è_çà)="; + $desc = "description#{[|`\^@]}³<> ¹¡÷׿&é\"'(-è\\_çà)="; + $tag1 = "#{|`^@]³¹¡¿<&é\"'(-è\\_çà)"; + $tag2 = "&é\"'(-è.[?./§!_çà)"; + + $bs->addBookmark("http://site1.com", $title, $desc, "status", array($tag1, $tag2), null, false, false, 1); + + $bookmarks =& $bs->getBookmarks(0, 1, NULL, NULL, NULL, getSortOrder(), NULL, 0); + + $b0 = $bookmarks['bookmarks'][0]; + $this->assertEquals($title, $b0['bTitle']); + $this->assertEquals($desc, $b0['bDescription']); + $this->assertEquals(str_replace(array('"', '\'', '/'), "_", $tag1), $b0['tags'][0]); + $this->assertEquals(str_replace(array('"', '\'', '/'), "_", $tag2), $b0['tags'][1]); + } + + public function testUnificationOfBookmarks() + { + $bs = $this->bs; + + $bs->addBookmark("http://site1.com", "title", "description", "status", array('tag1'), null, false, false, 1); + $bs->addBookmark("http://site1.com", "title2", "description2", "status", array('tag2'), null, false, false, 2); + + $bookmarks =& $bs->getBookmarks(0, 1, NULL, NULL, NULL, getSortOrder(), NULL, 0); + $this->assertEquals(1, $bookmarks['total']); + } + + /*public function testSearchingBookmarksAccentsInsensible() + { + $bs = $this->bs; + + $bs->addBookmark("http://site1.com", "title", "éèüaàê", "status", array('tag1'), null, false, false, 1); + $bookmarks =& $bs->getBookmarks(0, NULL, NULL, NULL, $terms = "eeaae"); //void + $this->assertEquals(0, $bookmarks['total']); + $bookmarks =& $bs->getBookmarks(0, NULL, NULL, NULL, $terms = "eeuaae"); + $this->assertEquals(1, $bookmarks['total']); + }*/ + + + + public function testDeleteBookmark() + { + //FIXME + } + +} + + +if (PHPUnit_MAIN_METHOD == 'BookmarkTest::main') { + BookmarkTest::main(); +} +?> diff --git a/tests/BookmarksTest.php b/tests/BookmarksTest.php deleted file mode 100644 index 7520058..0000000 --- a/tests/BookmarksTest.php +++ /dev/null @@ -1,76 +0,0 @@ -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(); - } - - public function testHardCharactersInBookmarks() - { - $bs = $this->bs; - $title = "title&é\"'(-è_çà)="; - $desc = "description#{[|`\^@]}³<> ¹¡÷׿&é\"'(-è\\_çà)="; - $tag1 = "#{|`^@]³¹¡¿<&é\"'(-è\\_çà)"; - $tag2 = "&é\"'(-è.[?./§!_çà)"; - - $bs->addBookmark("http://site1.com", $title, $desc, "status", array($tag1, $tag2), null, false, false, 1); - - $bookmarks =& $bs->getBookmarks(0, 1, NULL, NULL, NULL, getSortOrder(), NULL, 0); - - $b0 = $bookmarks['bookmarks'][0]; - $this->assertEquals($title, $b0['bTitle']); - $this->assertEquals($desc, $b0['bDescription']); - $this->assertEquals(str_replace(array('"', '\'', '/'), "_", $tag1), $b0['tags'][0]); - $this->assertEquals(str_replace(array('"', '\'', '/'), "_", $tag2), $b0['tags'][1]); - } - - public function testUnificationOfBookmarks() - { - $bs = $this->bs; - - $bs->addBookmark("http://site1.com", "title", "description", "status", array('tag1'), null, false, false, 1); - $bs->addBookmark("http://site1.com", "title2", "description2", "status", array('tag2'), null, false, false, 2); - - $bookmarks =& $bs->getBookmarks(0, 1, NULL, NULL, NULL, getSortOrder(), NULL, 0); - $this->assertEquals(1, $bookmarks['total']); - } - - /*public function testSearchingBookmarksAccentsInsensible() - { - $bs = $this->bs; - - $bs->addBookmark("http://site1.com", "title", "éèüaàê", "status", array('tag1'), null, false, false, 1); - $bookmarks =& $bs->getBookmarks(0, NULL, NULL, NULL, $terms = "eeaae"); //void - $this->assertEquals(0, $bookmarks['total']); - $bookmarks =& $bs->getBookmarks(0, NULL, NULL, NULL, $terms = "eeuaae"); - $this->assertEquals(1, $bookmarks['total']); - }*/ - -} -?> diff --git a/tests/CommonDescriptionTest.php b/tests/CommonDescriptionTest.php index 3f6917e..93fcc53 100644 --- a/tests/CommonDescriptionTest.php +++ b/tests/CommonDescriptionTest.php @@ -1,13 +1,32 @@ + * @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 + * @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(); +} ?> diff --git a/tests/SearchHistoryTest.php b/tests/SearchHistoryTest.php new file mode 100644 index 0000000..2421a20 --- /dev/null +++ b/tests/SearchHistoryTest.php @@ -0,0 +1,119 @@ + + * @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', 'SearchHistoryTest::main'); +} + +/** + * Unit tests for the SemanticScuttle search history service. + * + * @category Bookmarking + * @package SemanticScuttle + * @author Christian Weiske + * @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() + { + $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->shs =SemanticScuttle_Service_Factory::get('SearchHistory'); + $this->shs->deleteAll(); + } + + public function testSearchHistory() + { + $shs = $this->shs; + + $terms = 'bbqsdkbb;,:,:q;,qddds&é"\'\\\\\(-è_çà)'; + $terms2 = '~#{|`]'; + $range = 'all'; + $nbResults = 10908; + $uId = 10; + + $shs->addSearch($terms, $range, $nbResults, $uId); + $shs->addSearch($terms2, $range, $nbResults, $uId); + $shs->addSearch('', $range, $nbResults, $uId); // A void search must not be saved + + $searches = $shs->getAllSearches(); + $this->assertSame(2, count($searches)); + $searches = $shs->getAllSearches($range, $uId); + $this->assertEquals(2, count($searches)); + $searches = $shs->getAllSearches($range, 20); // fake userid + $this->assertEquals(0, count($searches)); + $searches = $shs->getAllSearches($range, $uId, 1); + $this->assertEquals(1, count($searches)); + $searches = $shs->getAllSearches($range, null, 1, 1); + $this->assertEquals(1, count($searches)); + + //test content of results + $searches = $shs->getAllSearches(); + $this->assertSame($terms2, $searches[0]['shTerms']); + $this->assertSame($range, $searches[0]['shRange']); + $this->assertEquals($nbResults, $searches[0]['shNbResults']); + $this->assertEquals($uId, $searches[0]['uId']); + $this->assertSame($terms, $searches[1]['shTerms']); + $this->assertSame($range, $searches[1]['shRange']); + $this->assertEquals($nbResults, $searches[1]['shNbResults']); + $this->assertEquals($uId, $searches[1]['uId']); + + //test distinct parameter + $shs->addSearch($terms, $range, $nbResults, 30); // we repeat a search (same terms) + $searches = $shs->getAllSearches(); + $this->assertSame(3, count($searches)); + $searches = $shs->getAllSearches(NULL, NULL, NULL, NULL, true); + $this->assertSame(2, count($searches)); + } +} + + +if (PHPUnit_MAIN_METHOD == 'SearchHistoryTest::main') { + SearchHistoryTest::main(); +} + +?> diff --git a/tests/SearchTest.php b/tests/SearchTest.php deleted file mode 100644 index 3aa49de..0000000 --- a/tests/SearchTest.php +++ /dev/null @@ -1,80 +0,0 @@ -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->shs =SemanticScuttle_Service_Factory::get('SearchHistory'); - $this->shs->deleteAll(); - } - - public function testSearchHistory() - { - $shs = $this->shs; - - $terms = 'bbqsdkbb;,:,:q;,qddds&é"\'\\\\\(-è_çà)'; - $terms2 = '~#{|`]'; - $range = 'all'; - $nbResults = 10908; - $uId = 10; - - $shs->addSearch($terms, $range, $nbResults, $uId); - $shs->addSearch($terms2, $range, $nbResults, $uId); - $shs->addSearch('', $range, $nbResults, $uId); // A void search must not be saved - - $searches = $shs->getAllSearches(); - $this->assertSame(2, count($searches)); - $searches = $shs->getAllSearches($range, $uId); - $this->assertEquals(2, count($searches)); - $searches = $shs->getAllSearches($range, 20); // fake userid - $this->assertEquals(0, count($searches)); - $searches = $shs->getAllSearches($range, $uId, 1); - $this->assertEquals(1, count($searches)); - $searches = $shs->getAllSearches($range, null, 1, 1); - $this->assertEquals(1, count($searches)); - - //test content of results - $searches = $shs->getAllSearches(); - $this->assertSame($terms2, $searches[0]['shTerms']); - $this->assertSame($range, $searches[0]['shRange']); - $this->assertEquals($nbResults, $searches[0]['shNbResults']); - $this->assertEquals($uId, $searches[0]['uId']); - $this->assertSame($terms, $searches[1]['shTerms']); - $this->assertSame($range, $searches[1]['shRange']); - $this->assertEquals($nbResults, $searches[1]['shNbResults']); - $this->assertEquals($uId, $searches[1]['uId']); - - //test distinct parameter - $shs->addSearch($terms, $range, $nbResults, 30); // we repeat a search (same terms) - $searches = $shs->getAllSearches(); - $this->assertSame(3, count($searches)); - $searches = $shs->getAllSearches(NULL, NULL, NULL, NULL, true); - $this->assertSame(2, count($searches)); - } -} -?> diff --git a/tests/Tag2TagTest.php b/tests/Tag2TagTest.php index 8b23040..8a19823 100644 --- a/tests/Tag2TagTest.php +++ b/tests/Tag2TagTest.php @@ -1,24 +1,57 @@ + * @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 + * @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(); +} ?> diff --git a/tests/TagTest.php b/tests/TagTest.php new file mode 100644 index 0000000..2cc6d44 --- /dev/null +++ b/tests/TagTest.php @@ -0,0 +1,114 @@ + + * @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', 'TagTest::main'); +} + +/** + * Unit tests for the SemanticScuttle tag service. + * + * @category Bookmarking + * @package SemanticScuttle + * @author Christian Weiske + * @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() + { + $this->ts =SemanticScuttle_Service_Factory::get('Tag'); + $this->ts->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(); + } + + public function testTagDescriptions() + { + $ts = $this->ts; + + $desc = $ts->getAllDescriptions('tag1'); + $this->assertSame(array(), $desc); + + $desc = $ts->getDescription('tag1', 1); // user 1 + $this->assertSame(array('tDescription'=>''), $desc); + + $desc1 = "test description"; + $ts->updateDescription('tag1', 1, $desc1); // first desc + $desc = $ts->getDescription('tag1', 1); + $this->assertEquals(array('tag'=>'tag1', 'uId'=>1, 'tDescription'=>$desc1), $desc); + + $desc1 = "&é\"'(-è_çà)=´~#'#{{[\\\\[||`\^\^@^@}¹²¡×¿ ?./§µ%"; + $ts->updateDescription('tag1', 1, $desc1); // update desc + $desc = $ts->getDescription('tag1', 1); + $this->assertEquals(array('tag'=>'tag1', 'uId'=>1, 'tDescription'=>$desc1), $desc); + + $desc2 = "æâ€êþÿûîîôôöŀï'üð’‘ßä«≤»©»  ↓¿×÷¡¹²³"; + $ts->updateDescription('tag1', 2, $desc2); // user 2 + $desc = $ts->getDescription('tag1', 2); + $this->assertEquals(array('tag'=>'tag1', 'uId'=>2, 'tDescription'=>$desc2), $desc); + + $desc = $ts->getAllDescriptions('tag1'); + $this->assertEquals($desc, array(array('tag'=>'tag1', 'uId'=>1, 'tDescription'=>$desc1), array('tag'=>'tag1', 'uId'=>2, 'tDescription'=>$desc2))); + + } + + public function testRenameFunction() + { + $ts = $this->ts; + + $ts->updateDescription('tag1', 10, 'xxx'); + $ts->renameTag(10, 'tag1', 'tag2'); + $desc = $ts->getDescription('tag1', 10); + $this->assertSame(array('tDescription'=>''), $desc); + $desc = $ts->getDescription('tag2', 10); + $this->assertEquals(array('tag'=>'tag2', 'uId'=>10, 'tDescription'=>'xxx'), $desc); + + } + +} + + +if (PHPUnit_MAIN_METHOD == 'TagTest::main') { + TagTest::main(); +} +?> diff --git a/tests/TagsCacheTest.php b/tests/TagsCacheTest.php index 8e15f2d..9230f1c 100644 --- a/tests/TagsCacheTest.php +++ b/tests/TagsCacheTest.php @@ -1,12 +1,31 @@ + * @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 + * @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/TagsTest.php b/tests/TagsTest.php deleted file mode 100644 index f07e04f..0000000 --- a/tests/TagsTest.php +++ /dev/null @@ -1,76 +0,0 @@ -ts =SemanticScuttle_Service_Factory::get('Tag'); - $this->ts->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(); - } - - public function testTagDescriptions() - { - $ts = $this->ts; - - $desc = $ts->getAllDescriptions('tag1'); - $this->assertSame(array(), $desc); - - $desc = $ts->getDescription('tag1', 1); // user 1 - $this->assertSame(array('tDescription'=>''), $desc); - - $desc1 = "test description"; - $ts->updateDescription('tag1', 1, $desc1); // first desc - $desc = $ts->getDescription('tag1', 1); - $this->assertEquals(array('tag'=>'tag1', 'uId'=>1, 'tDescription'=>$desc1), $desc); - - $desc1 = "&é\"'(-è_çà)=´~#'#{{[\\\\[||`\^\^@^@}¹²¡×¿ ?./§µ%"; - $ts->updateDescription('tag1', 1, $desc1); // update desc - $desc = $ts->getDescription('tag1', 1); - $this->assertEquals(array('tag'=>'tag1', 'uId'=>1, 'tDescription'=>$desc1), $desc); - - $desc2 = "æâ€êþÿûîîôôöŀï'üð’‘ßä«≤»©»  ↓¿×÷¡¹²³"; - $ts->updateDescription('tag1', 2, $desc2); // user 2 - $desc = $ts->getDescription('tag1', 2); - $this->assertEquals(array('tag'=>'tag1', 'uId'=>2, 'tDescription'=>$desc2), $desc); - - $desc = $ts->getAllDescriptions('tag1'); - $this->assertEquals($desc, array(array('tag'=>'tag1', 'uId'=>1, 'tDescription'=>$desc1), array('tag'=>'tag1', 'uId'=>2, 'tDescription'=>$desc2))); - - } - - public function testRenameFunction() - { - $ts = $this->ts; - - $ts->updateDescription('tag1', 10, 'xxx'); - $ts->renameTag(10, 'tag1', 'tag2'); - $desc = $ts->getDescription('tag1', 10); - $this->assertSame(array('tDescription'=>''), $desc); - $desc = $ts->getDescription('tag2', 10); - $this->assertEquals(array('tag'=>'tag2', 'uId'=>10, 'tDescription'=>'xxx'), $desc); - - } - -} -?> diff --git a/tests/TestBase.php b/tests/TestBase.php new file mode 100644 index 0000000..dc5643f --- /dev/null +++ b/tests/TestBase.php @@ -0,0 +1,49 @@ + + * @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 + * @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 diff --git a/tests/VoteTest.php b/tests/VoteTest.php index 0196071..90611d1 100644 --- a/tests/VoteTest.php +++ b/tests/VoteTest.php @@ -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') { diff --git a/tests/prepare.php b/tests/prepare.php index 73d804d..095cf36 100644 --- a/tests/prepare.php +++ b/tests/prepare.php @@ -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 -- cgit v1.2.3