From be126cc958212ed74fe916eabcb1e6ac928df5e4 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Fri, 8 Oct 2010 17:43:05 +0200 Subject: tests for getadminlinkedtags --- tests/ajax/GetAdminLinkedTagsTest.php | 160 ++++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 tests/ajax/GetAdminLinkedTagsTest.php (limited to 'tests/ajax') diff --git a/tests/ajax/GetAdminLinkedTagsTest.php b/tests/ajax/GetAdminLinkedTagsTest.php new file mode 100644 index 0000000..d8ec447 --- /dev/null +++ b/tests/ajax/GetAdminLinkedTagsTest.php @@ -0,0 +1,160 @@ + + * @author Christian Weiske + * @author Eric Dane + * @license GPL http://www.gnu.org/licenses/gpl.html + * @link http://sourceforge.net/projects/semanticscuttle + */ + +require_once dirname(__FILE__) . '/../prepare.php'; +require_once 'HTTP/Request2.php'; + +if (!defined('PHPUnit_MAIN_METHOD')) { + define('PHPUnit_MAIN_METHOD', 'ajax_GetAdminLinkedTagsTest::main'); +} + +/** + * Unit tests for the ajax linked admin tags script + * + * @category Bookmarking + * @package SemanticScuttle + * @author Christian Weiske + * @license GPL http://www.gnu.org/licenses/gpl.html + * @link http://sourceforge.net/projects/semanticscuttle + */ +class ajax_GetAdminLinkedTagsTest extends TestBaseApi +{ + protected $urlPart = 'ajax/getadminlinkedtags.php'; + + + + /** + * 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__) + ); + } + + + + /** + * Verify that we get the configured root tags if + * we do not pass any parameters + */ + public function testRootTags() + { + $req = $this->getRequest(); + $res = $req->send(); + + $this->assertEquals(200, $res->getStatus()); + $this->assertEquals( + 'application/json; charset=utf-8', + $res->getHeader('content-type') + ); + + $data = json_decode($res->getBody()); + $this->assertType('array', $data); + + //same number of elements as the menu2Tags array + $this->assertEquals( + count($GLOBALS['menu2Tags']), + count($data) + ); + + //and the same contents + foreach ($data as $tagObj) { + $tagName = $tagObj->data->title; + $this->assertContains($tagName, $GLOBALS['menu2Tags']); + } + } + + /** + * Verify that we get subtags of a given tag + */ + public function testSubTags() + { + $t2t = SemanticScuttle_Service_Factory::get('Tag2Tag'); + $t2t->deleteAll(); + + $menu2Tag = reset($GLOBALS['menu2Tags']); + //we have a subtag now + $this->addBookmark( + $this->getAdminUser(), + null, + 0, + $menu2Tag . '>adminsubtag' + ); + + $res = $this->getRequest('?tag=' . $menu2Tag)->send(); + $this->assertEquals(200, $res->getStatus()); + $this->assertEquals( + 'application/json; charset=utf-8', + $res->getHeader('content-type') + ); + + $data = json_decode($res->getBody()); + $this->assertType('array', $data); + + //only one subtag + $this->assertEquals(1, count($data)); + $this->assertEquals('adminsubtag', $data[0]->data->title); + } + + /** + * Verify that we only get admin tags, not tags from + * non-admin people + */ + public function testOnlyAdminTags() + { + $t2t = SemanticScuttle_Service_Factory::get('Tag2Tag'); + $t2t->deleteAll(); + + $menu2Tag = reset($GLOBALS['menu2Tags']); + //we have a subtag now + $this->addBookmark( + $this->getAdminUser(), + null, + 0, + $menu2Tag . '>adminsubtag' + ); + //add another bookmark now, but for a normal user + $this->addBookmark( + null, + null, + 0, + $menu2Tag . '>normalsubtag' + ); + + $res = $this->getRequest('?tag=' . $menu2Tag)->send(); + $this->assertEquals(200, $res->getStatus()); + $this->assertEquals( + 'application/json; charset=utf-8', + $res->getHeader('content-type') + ); + + $data = json_decode($res->getBody()); + $this->assertType('array', $data); + + //we should have only one subtag now, the admin one + $this->assertEquals(1, count($data)); + $this->assertEquals('adminsubtag', $data[0]->data->title); + } +} + +if (PHPUnit_MAIN_METHOD == 'ajax_GetAdminLinkedTagsTest::main') { + ajax_GetAdminLinkedTagsTest::main(); +} +?> \ No newline at end of file -- cgit v1.2.3-54-g00ecf From 3828cfe6d6bb64df763276fa2bc2c4da6ccb06dd Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Thu, 24 Mar 2011 08:41:02 +0100 Subject: replace assertType with assertInternalType to please phpunit --- tests/ajax/GetAdminLinkedTagsTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/ajax') diff --git a/tests/ajax/GetAdminLinkedTagsTest.php b/tests/ajax/GetAdminLinkedTagsTest.php index d8ec447..2552ea0 100644 --- a/tests/ajax/GetAdminLinkedTagsTest.php +++ b/tests/ajax/GetAdminLinkedTagsTest.php @@ -66,7 +66,7 @@ class ajax_GetAdminLinkedTagsTest extends TestBaseApi ); $data = json_decode($res->getBody()); - $this->assertType('array', $data); + $this->assertInternalType('array', $data); //same number of elements as the menu2Tags array $this->assertEquals( @@ -106,7 +106,7 @@ class ajax_GetAdminLinkedTagsTest extends TestBaseApi ); $data = json_decode($res->getBody()); - $this->assertType('array', $data); + $this->assertInternalType('array', $data); //only one subtag $this->assertEquals(1, count($data)); @@ -146,7 +146,7 @@ class ajax_GetAdminLinkedTagsTest extends TestBaseApi ); $data = json_decode($res->getBody()); - $this->assertType('array', $data); + $this->assertInternalType('array', $data); //we should have only one subtag now, the admin one $this->assertEquals(1, count($data)); -- cgit v1.2.3-54-g00ecf From db71e63467a26afb8265979f8c8071935ec349b4 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Fri, 25 Mar 2011 19:26:21 +0100 Subject: begin with ajax unittests - but they do not work yet --- tests/TestBaseApi.php | 36 +++++++++++++++++++ tests/ajax/GetContactTagsTest.php | 73 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 tests/ajax/GetContactTagsTest.php (limited to 'tests/ajax') diff --git a/tests/TestBaseApi.php b/tests/TestBaseApi.php index dacdecd..b7c1921 100644 --- a/tests/TestBaseApi.php +++ b/tests/TestBaseApi.php @@ -84,6 +84,9 @@ class TestBaseApi extends TestBase * the request object with authentication details, so that * the user is logged in. * + * Useful for HTTP API methods only, cannot be used with + * "normal" HTML pages since they do not support HTTP auth. + * * @param string $urlSuffix Suffix for the URL * @param mixed $auth If user authentication is needed (true/false) * or array with username and password @@ -109,5 +112,38 @@ class TestBaseApi extends TestBase return array($req, $uid); } + + + /** + * Creates a user and a HTTP_Request2 object, does a normal login + * and prepares the cookies for the HTTP request object so that + * the user is seen as logged in when requesting any HTML page. + * + * Useful for testing HTML pages or ajax URLs. + * + * @param string $urlSuffix Suffix for the URL + * @param mixed $auth If user authentication is needed (true/false) + * or array with username and password + * + * @return array(HTTP_Request2, integer) HTTP request object and user id + * + * @uses getRequest() + */ + protected function getLoggedInRequest($urlSuffix = null, $auth = true) + { + $req = $this->getRequest($urlSuffix); + if (is_array($auth)) { + list($username, $password) = $auth; + } else { + $username = 'testuser'; + $password = 'testpassword'; + } + $uid = $this->addUser($username, $password); + + //FIXME: login via the login form, check if it worked + //FIXME: prepare new request with cookie + return array($req, $uid); + } + } ?> \ No newline at end of file diff --git a/tests/ajax/GetContactTagsTest.php b/tests/ajax/GetContactTagsTest.php new file mode 100644 index 0000000..7f46888 --- /dev/null +++ b/tests/ajax/GetContactTagsTest.php @@ -0,0 +1,73 @@ + + * @author Christian Weiske + * @author Eric Dane + * @license GPL http://www.gnu.org/licenses/gpl.html + * @link http://sourceforge.net/projects/semanticscuttle + */ + +require_once dirname(__FILE__) . '/../prepare.php'; +require_once 'HTTP/Request2.php'; + +/** + * Unit tests for the ajax getcontacttags.php script + * + * @category Bookmarking + * @package SemanticScuttle + * @author Christian Weiske + * @license GPL http://www.gnu.org/licenses/gpl.html + * @link http://sourceforge.net/projects/semanticscuttle + */ +class ajax_GetContactTagsTest extends TestBaseApi +{ + protected $urlPart = 'ajax/getcontacttags.php'; + + + /** + * If no user is logged in, no data are returned + */ + public function testNoUserLoggedIn() + { + $res = $this->getRequest()->send(); + $this->assertEquals(200, $res->getStatus()); + $this->assertEquals( + 'application/json; charset=utf-8', + $res->getHeader('content-type') + ); + $data = json_decode($res->getBody()); + $this->assertInternalType('array', $data); + $this->assertEquals(0, count($data)); + } + + + public function testUserLoggedIn() + { + list($req, $uId) = $this->getAuthRequest(); + $this->addBookmark($uId, null, 0, array('public')); + $this->addBookmark($uId, null, 1, array('shared')); + $this->addBookmark($uId, null, 2, array('private')); + + $res = $req->send(); + $this->assertEquals(200, $res->getStatus()); + $this->assertEquals( + 'application/json; charset=utf-8', + $res->getHeader('content-type') + ); + $data = json_decode($res->getBody()); + $this->assertInternalType('array', $data); + $this->assertEquals(3, count($data)); + $this->assertContains('public', $data); + $this->assertContains('shared', $data); + $this->assertContains('private', $data); + } +} + + +?> \ No newline at end of file -- cgit v1.2.3-54-g00ecf From 0f9d06c6644f634b436549f0d5e56fc96ebd361c Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Sat, 26 Mar 2011 10:00:18 +0100 Subject: first working unittest for ajax/getcontacttags with login! --- tests/TestBaseApi.php | 19 ++++++++++++++++--- tests/ajax/GetContactTagsTest.php | 20 ++++++++++++-------- 2 files changed, 28 insertions(+), 11 deletions(-) (limited to 'tests/ajax') diff --git a/tests/TestBaseApi.php b/tests/TestBaseApi.php index b7c1921..2af228a 100644 --- a/tests/TestBaseApi.php +++ b/tests/TestBaseApi.php @@ -131,7 +131,6 @@ class TestBaseApi extends TestBase */ protected function getLoggedInRequest($urlSuffix = null, $auth = true) { - $req = $this->getRequest($urlSuffix); if (is_array($auth)) { list($username, $password) = $auth; } else { @@ -140,8 +139,22 @@ class TestBaseApi extends TestBase } $uid = $this->addUser($username, $password); - //FIXME: login via the login form, check if it worked - //FIXME: prepare new request with cookie + $req = new HTTP_Request2( + $GLOBALS['unittestUrl'] . '/login.php', + HTTP_Request2::METHOD_POST + ); + $cookies = $req->setCookieJar()->getCookieJar(); + $req->addPostParameter('username', $username); + $req->addPostParameter('password', $password); + $req->addPostParameter('submitted', 'Log In'); + $res = $req->send(); + + //after login, we normally get redirected + $this->assertEquals(302, $res->getStatus(), 'Login failure'); + + $req = $this->getRequest($urlSuffix); + $req->setCookieJar($cookies); + return array($req, $uid); } diff --git a/tests/ajax/GetContactTagsTest.php b/tests/ajax/GetContactTagsTest.php index 7f46888..757dce9 100644 --- a/tests/ajax/GetContactTagsTest.php +++ b/tests/ajax/GetContactTagsTest.php @@ -47,13 +47,17 @@ class ajax_GetContactTagsTest extends TestBaseApi } - public function testUserLoggedIn() + public function testUserLoggedInWatchlist() { - list($req, $uId) = $this->getAuthRequest(); - $this->addBookmark($uId, null, 0, array('public')); - $this->addBookmark($uId, null, 1, array('shared')); - $this->addBookmark($uId, null, 2, array('private')); - + list($req, $uId) = $this->getLoggedInRequest(); + $this->addBookmark($uId, null, 0, array('public', 'public2')); + + $user2 = $this->addUser(); + $this->us->setCurrentUserId($uId); + $this->us->setWatchStatus($user2); + //uId watches user2 now + $this->addBookmark($user2, null, 0, array('user2tag')); + $res = $req->send(); $this->assertEquals(200, $res->getStatus()); $this->assertEquals( @@ -64,8 +68,8 @@ class ajax_GetContactTagsTest extends TestBaseApi $this->assertInternalType('array', $data); $this->assertEquals(3, count($data)); $this->assertContains('public', $data); - $this->assertContains('shared', $data); - $this->assertContains('private', $data); + $this->assertContains('public2', $data); + $this->assertContains('user2tag', $data); } } -- cgit v1.2.3-54-g00ecf From 78654369e918126c137b5aa4ba709a7bc0a27b43 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Sat, 26 Mar 2011 11:54:47 +0100 Subject: test for beginsWith parameter and a bugfix :) --- tests/ajax/GetContactTagsTest.php | 17 +++++++++++++++++ www/ajax/getcontacttags.php | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) (limited to 'tests/ajax') diff --git a/tests/ajax/GetContactTagsTest.php b/tests/ajax/GetContactTagsTest.php index 757dce9..6e40444 100644 --- a/tests/ajax/GetContactTagsTest.php +++ b/tests/ajax/GetContactTagsTest.php @@ -71,6 +71,23 @@ class ajax_GetContactTagsTest extends TestBaseApi $this->assertContains('public2', $data); $this->assertContains('user2tag', $data); } + + public function testParameterBeginsWith() + { + list($req, $uId) = $this->getLoggedInRequest('?beginsWith=bar'); + $this->addBookmark($uId, null, 0, array('foobar', 'barmann')); + + $res = $req->send(); + $this->assertEquals(200, $res->getStatus()); + $this->assertEquals( + 'application/json; charset=utf-8', + $res->getHeader('content-type') + ); + $data = json_decode($res->getBody()); + $this->assertInternalType('array', $data); + $this->assertEquals(1, count($data)); + $this->assertContains('barmann', $data); + } } diff --git a/www/ajax/getcontacttags.php b/www/ajax/getcontacttags.php index 1377fea..d353226 100644 --- a/www/ajax/getcontacttags.php +++ b/www/ajax/getcontacttags.php @@ -36,7 +36,7 @@ if (isset($_GET['beginsWith']) && strlen(trim($_GET['beginsWith']))) { } $listTags = SemanticScuttle_Service_Factory::get('Bookmark2Tag')->getContactTags( - $currentUserId, $limit, $currentUserId, $beginsWith + $currentUserId, $limit, $currentUserId, null, $beginsWith ); $tags = array(); foreach ($listTags as $t) { -- cgit v1.2.3-54-g00ecf From 0935c984991defbc3b7d8549ffa020371d5688f3 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Sat, 26 Mar 2011 13:55:46 +0100 Subject: test the limit parameter --- tests/ajax/GetContactTagsTest.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'tests/ajax') diff --git a/tests/ajax/GetContactTagsTest.php b/tests/ajax/GetContactTagsTest.php index 6e40444..682173b 100644 --- a/tests/ajax/GetContactTagsTest.php +++ b/tests/ajax/GetContactTagsTest.php @@ -88,6 +88,30 @@ class ajax_GetContactTagsTest extends TestBaseApi $this->assertEquals(1, count($data)); $this->assertContains('barmann', $data); } + + public function testParameterLimit() + { + list($req, $uId) = $this->getLoggedInRequest('?limit=2'); + $this->addBookmark($uId, null, 0, array('foo', 'bar', 'baz', 'omg')); + + $res = $req->send(); + $this->assertEquals(200, $res->getStatus()); + $this->assertEquals( + 'application/json; charset=utf-8', + $res->getHeader('content-type') + ); + $data = json_decode($res->getBody()); + $this->assertInternalType('array', $data); + $this->assertEquals(2, count($data)); + + $req2 = $this->getRequest('?limit=3'); + $req2->setCookieJar($req->getCookieJar()); + $res = $req2->send(); + $this->assertEquals(200, $res->getStatus()); + $data = json_decode($res->getBody()); + $this->assertInternalType('array', $data); + $this->assertEquals(3, count($data)); + } } -- cgit v1.2.3-54-g00ecf From a756799ef4df0449244d41c2ecc7133c3fb8ce70 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Sat, 26 Mar 2011 17:04:00 +0100 Subject: move setUnittestConfig to TestBaseApi since it makes only sense to use it there --- tests/TestBase.php | 44 ---------------------------- tests/TestBaseApi.php | 44 ++++++++++++++++++++++++++++ tests/ajax/GetAdminTagsTest.php | 63 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+), 44 deletions(-) create mode 100644 tests/ajax/GetAdminTagsTest.php (limited to 'tests/ajax') diff --git a/tests/TestBase.php b/tests/TestBase.php index b85c189..095f32d 100644 --- a/tests/TestBase.php +++ b/tests/TestBase.php @@ -22,18 +22,6 @@ */ class TestBase extends PHPUnit_Framework_TestCase { - /** - * Clean up after test - */ - public function tearDown() - { - if (file_exists($GLOBALS['datadir'] . '/config.unittest.php')) { - unlink($GLOBALS['datadir'] . '/config.unittest.php'); - } - } - - - /** * Create a new bookmark. * @@ -158,38 +146,6 @@ class TestBase extends PHPUnit_Framework_TestCase return $uid; } - - - /** - * Writes a special unittest configuration file. - * The unittest config file is read when a GET request with unittestMode=1 - * is sent, and the user allowed unittestmode in config.php. - * - * @param array $arConfig Array with config names as key and their value as - * value - * - * @return void - */ - protected function setUnittestConfig($arConfig) - { - $str = '<' . "?php\r\n"; - foreach ($arConfig as $name => $value) { - $str .= '$' . $name . ' = ' - . var_export($value, true) . ";\n"; - } - - if (!is_dir($GLOBALS['datadir'])) { - $this->fail( - 'datadir not set or not a directory: ' . $GLOBALS['datadir'] - ); - } - - $this->assertInternalType( - 'integer', - file_put_contents($GLOBALS['datadir'] . '/config.unittest.php', $str), - 'Writing config.unittest.php failed' - ); - } } ?> \ No newline at end of file diff --git a/tests/TestBaseApi.php b/tests/TestBaseApi.php index 2af228a..2341ea1 100644 --- a/tests/TestBaseApi.php +++ b/tests/TestBaseApi.php @@ -57,6 +57,18 @@ class TestBaseApi extends TestBase + /** + * Clean up after test + */ + public function tearDown() + { + if (file_exists($GLOBALS['datadir'] . '/config.unittest.php')) { + unlink($GLOBALS['datadir'] . '/config.unittest.php'); + } + } + + + /** * Gets a HTTP request object. * Uses $this->url plus $urlSuffix as request URL. @@ -158,5 +170,37 @@ class TestBaseApi extends TestBase return array($req, $uid); } + + + /** + * Writes a special unittest configuration file. + * The unittest config file is read when a GET request with unittestMode=1 + * is sent, and the user allowed unittestmode in config.php. + * + * @param array $arConfig Array with config names as key and their value as + * value + * + * @return void + */ + protected function setUnittestConfig($arConfig) + { + $str = '<' . "?php\r\n"; + foreach ($arConfig as $name => $value) { + $str .= '$' . $name . ' = ' + . var_export($value, true) . ";\n"; + } + + if (!is_dir($GLOBALS['datadir'])) { + $this->fail( + 'datadir not set or not a directory: ' . $GLOBALS['datadir'] + ); + } + + $this->assertInternalType( + 'integer', + file_put_contents($GLOBALS['datadir'] . '/config.unittest.php', $str), + 'Writing config.unittest.php failed' + ); + } } ?> \ No newline at end of file diff --git a/tests/ajax/GetAdminTagsTest.php b/tests/ajax/GetAdminTagsTest.php new file mode 100644 index 0000000..5c941e8 --- /dev/null +++ b/tests/ajax/GetAdminTagsTest.php @@ -0,0 +1,63 @@ + + * @author Christian Weiske + * @author Eric Dane + * @license GPL http://www.gnu.org/licenses/gpl.html + * @link http://sourceforge.net/projects/semanticscuttle + */ + +require_once dirname(__FILE__) . '/../prepare.php'; +require_once 'HTTP/Request2.php'; + +/** + * Unit tests for the ajax getadmintags.php script + * + * @category Bookmarking + * @package SemanticScuttle + * @author Christian Weiske + * @license GPL http://www.gnu.org/licenses/gpl.html + * @link http://sourceforge.net/projects/semanticscuttle + */ +class ajax_GetAdminTagsTest extends TestBaseApi +{ + protected $urlPart = 'ajax/getadmintags.php'; + + + public function testTags() + { + list($user1, $uname1) = $this->addUserData(); + $user2 = $this->addUser(); + $this->addBookmark($user1, null, 0, array('admintag', 'admintag2')); + $this->addBookmark($user2, null, 0, array('lusertag', 'lusertag2')); + + $this->setUnittestConfig( + array( + 'admin_users' => array($uname1) + ) + ); + + $req = $this->getRequest('?unittestMode=1'); + $res = $req->send(); + $this->assertEquals(200, $res->getStatus()); + $this->assertEquals( + 'application/json; charset=utf-8', + $res->getHeader('content-type') + ); + $data = json_decode($res->getBody()); + $this->assertInternalType('array', $data); + $this->assertEquals(2, count($data)); + $this->assertContains('admintag', $data); + $this->assertContains('admintag2', $data); + } + +} + + +?> \ No newline at end of file -- cgit v1.2.3-54-g00ecf From 1dfff5d3d81fdb67e4c78136168801a488fcf139 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Mon, 28 Mar 2011 08:01:02 +0200 Subject: add tests for getadmintags beginsWith and limit parameters --- tests/ajax/GetAdminTagsTest.php | 79 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) (limited to 'tests/ajax') diff --git a/tests/ajax/GetAdminTagsTest.php b/tests/ajax/GetAdminTagsTest.php index 5c941e8..6afe45c 100644 --- a/tests/ajax/GetAdminTagsTest.php +++ b/tests/ajax/GetAdminTagsTest.php @@ -57,6 +57,85 @@ class ajax_GetAdminTagsTest extends TestBaseApi $this->assertContains('admintag2', $data); } + public function testParameterBeginsWith() + { + list($user1, $uname1) = $this->addUserData(); + $this->addBookmark($user1, null, 0, array('foo', 'foobar', 'bar')); + + $this->setUnittestConfig( + array( + 'admin_users' => array($uname1) + ) + ); + + $req = $this->getRequest('?unittestMode=1&beginsWith=foo'); + $res = $req->send(); + $this->assertEquals(200, $res->getStatus()); + $this->assertEquals( + 'application/json; charset=utf-8', + $res->getHeader('content-type') + ); + $data = json_decode($res->getBody()); + $this->assertInternalType('array', $data); + $this->assertEquals(2, count($data)); + $this->assertContains('foo', $data); + $this->assertContains('foobar', $data); + } + + + + public function testParameterLimit() + { + list($user1, $uname1) = $this->addUserData(); + list($user2, $uname2) = $this->addUserData(); + $this->addBookmark($user1, null, 0, array('foo', 'foobar')); + $this->addBookmark($user2, null, 0, array('foo', 'bar')); + + $this->setUnittestConfig( + array( + 'admin_users' => array($uname1, $uname2) + ) + ); + + $req = $this->getRequest('?unittestMode=1&limit=1'); + $res = $req->send(); + $this->assertEquals(200, $res->getStatus()); + $this->assertEquals( + 'application/json; charset=utf-8', + $res->getHeader('content-type') + ); + $data = json_decode($res->getBody()); + $this->assertInternalType('array', $data); + $this->assertEquals(1, count($data)); + $this->assertContains('foo', $data); + + $req = $this->getRequest('?unittestMode=1&limit=2'); + $res = $req->send(); + $this->assertEquals(200, $res->getStatus()); + $this->assertEquals( + 'application/json; charset=utf-8', + $res->getHeader('content-type') + ); + $data = json_decode($res->getBody()); + $this->assertInternalType('array', $data); + $this->assertEquals(2, count($data)); + $this->assertContains('foo', $data); + + $req = $this->getRequest('?unittestMode=1&limit=3'); + $res = $req->send(); + $this->assertEquals(200, $res->getStatus()); + $this->assertEquals( + 'application/json; charset=utf-8', + $res->getHeader('content-type') + ); + $data = json_decode($res->getBody()); + $this->assertInternalType('array', $data); + $this->assertEquals(3, count($data)); + $this->assertContains('foo', $data); + $this->assertContains('foobar', $data); + $this->assertContains('bar', $data); + } + } -- cgit v1.2.3-54-g00ecf From a5bd7789297378be3fb8dc3814c6649ea82a88d8 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Mon, 28 Mar 2011 08:34:12 +0200 Subject: introduce assertResponseJson200 for API/ajax tests and use it --- tests/TestBaseApi.php | 19 +++++++++++++++++++ tests/ajax/GetAdminLinkedTagsTest.php | 20 +++----------------- tests/ajax/GetAdminTagsTest.php | 30 +++++------------------------- tests/ajax/GetContactTagsTest.php | 26 +++++--------------------- 4 files changed, 32 insertions(+), 63 deletions(-) (limited to 'tests/ajax') diff --git a/tests/TestBaseApi.php b/tests/TestBaseApi.php index 2341ea1..f054973 100644 --- a/tests/TestBaseApi.php +++ b/tests/TestBaseApi.php @@ -172,6 +172,25 @@ class TestBaseApi extends TestBase + /** + * Verifies that the HTTP response has status code 200 and + * content-type application/json; charset=utf-8 + * + * @param HTTP_Request2_Response $res HTTP Response object + * + * @return void + */ + protected function assertResponseJson200(HTTP_Request2_Response $res) + { + $this->assertEquals(200, $res->getStatus()); + $this->assertEquals( + 'application/json; charset=utf-8', + $res->getHeader('content-type') + ); + } + + + /** * Writes a special unittest configuration file. * The unittest config file is read when a GET request with unittestMode=1 diff --git a/tests/ajax/GetAdminLinkedTagsTest.php b/tests/ajax/GetAdminLinkedTagsTest.php index 2552ea0..aded834 100644 --- a/tests/ajax/GetAdminLinkedTagsTest.php +++ b/tests/ajax/GetAdminLinkedTagsTest.php @@ -58,13 +58,7 @@ class ajax_GetAdminLinkedTagsTest extends TestBaseApi { $req = $this->getRequest(); $res = $req->send(); - - $this->assertEquals(200, $res->getStatus()); - $this->assertEquals( - 'application/json; charset=utf-8', - $res->getHeader('content-type') - ); - + $this->assertResponseJson200($res); $data = json_decode($res->getBody()); $this->assertInternalType('array', $data); @@ -99,11 +93,7 @@ class ajax_GetAdminLinkedTagsTest extends TestBaseApi ); $res = $this->getRequest('?tag=' . $menu2Tag)->send(); - $this->assertEquals(200, $res->getStatus()); - $this->assertEquals( - 'application/json; charset=utf-8', - $res->getHeader('content-type') - ); + $this->assertResponseJson200($res); $data = json_decode($res->getBody()); $this->assertInternalType('array', $data); @@ -139,11 +129,7 @@ class ajax_GetAdminLinkedTagsTest extends TestBaseApi ); $res = $this->getRequest('?tag=' . $menu2Tag)->send(); - $this->assertEquals(200, $res->getStatus()); - $this->assertEquals( - 'application/json; charset=utf-8', - $res->getHeader('content-type') - ); + $this->assertResponseJson200($res); $data = json_decode($res->getBody()); $this->assertInternalType('array', $data); diff --git a/tests/ajax/GetAdminTagsTest.php b/tests/ajax/GetAdminTagsTest.php index 6afe45c..80d702f 100644 --- a/tests/ajax/GetAdminTagsTest.php +++ b/tests/ajax/GetAdminTagsTest.php @@ -45,11 +45,7 @@ class ajax_GetAdminTagsTest extends TestBaseApi $req = $this->getRequest('?unittestMode=1'); $res = $req->send(); - $this->assertEquals(200, $res->getStatus()); - $this->assertEquals( - 'application/json; charset=utf-8', - $res->getHeader('content-type') - ); + $this->assertResponseJson200($res); $data = json_decode($res->getBody()); $this->assertInternalType('array', $data); $this->assertEquals(2, count($data)); @@ -70,12 +66,8 @@ class ajax_GetAdminTagsTest extends TestBaseApi $req = $this->getRequest('?unittestMode=1&beginsWith=foo'); $res = $req->send(); - $this->assertEquals(200, $res->getStatus()); - $this->assertEquals( - 'application/json; charset=utf-8', - $res->getHeader('content-type') - ); $data = json_decode($res->getBody()); + $this->assertResponseJson200($res); $this->assertInternalType('array', $data); $this->assertEquals(2, count($data)); $this->assertContains('foo', $data); @@ -99,11 +91,7 @@ class ajax_GetAdminTagsTest extends TestBaseApi $req = $this->getRequest('?unittestMode=1&limit=1'); $res = $req->send(); - $this->assertEquals(200, $res->getStatus()); - $this->assertEquals( - 'application/json; charset=utf-8', - $res->getHeader('content-type') - ); + $this->assertResponseJson200($res); $data = json_decode($res->getBody()); $this->assertInternalType('array', $data); $this->assertEquals(1, count($data)); @@ -111,11 +99,7 @@ class ajax_GetAdminTagsTest extends TestBaseApi $req = $this->getRequest('?unittestMode=1&limit=2'); $res = $req->send(); - $this->assertEquals(200, $res->getStatus()); - $this->assertEquals( - 'application/json; charset=utf-8', - $res->getHeader('content-type') - ); + $this->assertResponseJson200($res); $data = json_decode($res->getBody()); $this->assertInternalType('array', $data); $this->assertEquals(2, count($data)); @@ -123,11 +107,7 @@ class ajax_GetAdminTagsTest extends TestBaseApi $req = $this->getRequest('?unittestMode=1&limit=3'); $res = $req->send(); - $this->assertEquals(200, $res->getStatus()); - $this->assertEquals( - 'application/json; charset=utf-8', - $res->getHeader('content-type') - ); + $this->assertResponseJson200($res); $data = json_decode($res->getBody()); $this->assertInternalType('array', $data); $this->assertEquals(3, count($data)); diff --git a/tests/ajax/GetContactTagsTest.php b/tests/ajax/GetContactTagsTest.php index 682173b..559040f 100644 --- a/tests/ajax/GetContactTagsTest.php +++ b/tests/ajax/GetContactTagsTest.php @@ -36,11 +36,7 @@ class ajax_GetContactTagsTest extends TestBaseApi public function testNoUserLoggedIn() { $res = $this->getRequest()->send(); - $this->assertEquals(200, $res->getStatus()); - $this->assertEquals( - 'application/json; charset=utf-8', - $res->getHeader('content-type') - ); + $this->assertResponseJson200($res); $data = json_decode($res->getBody()); $this->assertInternalType('array', $data); $this->assertEquals(0, count($data)); @@ -59,11 +55,7 @@ class ajax_GetContactTagsTest extends TestBaseApi $this->addBookmark($user2, null, 0, array('user2tag')); $res = $req->send(); - $this->assertEquals(200, $res->getStatus()); - $this->assertEquals( - 'application/json; charset=utf-8', - $res->getHeader('content-type') - ); + $this->assertResponseJson200($res); $data = json_decode($res->getBody()); $this->assertInternalType('array', $data); $this->assertEquals(3, count($data)); @@ -78,11 +70,7 @@ class ajax_GetContactTagsTest extends TestBaseApi $this->addBookmark($uId, null, 0, array('foobar', 'barmann')); $res = $req->send(); - $this->assertEquals(200, $res->getStatus()); - $this->assertEquals( - 'application/json; charset=utf-8', - $res->getHeader('content-type') - ); + $this->assertResponseJson200($res); $data = json_decode($res->getBody()); $this->assertInternalType('array', $data); $this->assertEquals(1, count($data)); @@ -95,11 +83,7 @@ class ajax_GetContactTagsTest extends TestBaseApi $this->addBookmark($uId, null, 0, array('foo', 'bar', 'baz', 'omg')); $res = $req->send(); - $this->assertEquals(200, $res->getStatus()); - $this->assertEquals( - 'application/json; charset=utf-8', - $res->getHeader('content-type') - ); + $this->assertResponseJson200($res); $data = json_decode($res->getBody()); $this->assertInternalType('array', $data); $this->assertEquals(2, count($data)); @@ -107,7 +91,7 @@ class ajax_GetContactTagsTest extends TestBaseApi $req2 = $this->getRequest('?limit=3'); $req2->setCookieJar($req->getCookieJar()); $res = $req2->send(); - $this->assertEquals(200, $res->getStatus()); + $this->assertResponseJson200($res); $data = json_decode($res->getBody()); $this->assertInternalType('array', $data); $this->assertEquals(3, count($data)); -- cgit v1.2.3-54-g00ecf From bdebe6598c52a74f7040e3a11198b3554fa58f54 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Tue, 12 Apr 2011 09:29:59 +0200 Subject: use bootstrap file declared in phpunit.xml and do not include it in every single test file. also get rid of the PHPUnit_MAIN_METHOD declarations since using phpunit directly is preferred --- tests/AllTests.php | 25 ++----------------------- tests/Api/ExportCsvTest.php | 25 ------------------------- tests/Api/PostsAddTest.php | 25 ------------------------- tests/Api/PostsDeleteTest.php | 25 ------------------------- tests/Api/PostsUpdateTest.php | 25 ------------------------- tests/Bookmark2TagTest.php | 24 ------------------------ tests/BookmarkTest.php | 26 -------------------------- tests/CommonDescriptionTest.php | 25 ------------------------- tests/SearchHistoryTest.php | 27 --------------------------- tests/Tag2TagTest.php | 25 ------------------------- tests/TagTest.php | 26 -------------------------- tests/TagsCacheTest.php | 23 ----------------------- tests/UserArrayTest.php | 2 -- tests/UserTest.php | 29 ----------------------------- tests/VoteTest.php | 25 ------------------------- tests/ajax/GetAdminLinkedTagsTest.php | 26 -------------------------- tests/ajax/GetAdminTagsTest.php | 2 -- tests/ajax/GetContactTagsTest.php | 2 -- 18 files changed, 2 insertions(+), 385 deletions(-) (limited to 'tests/ajax') diff --git a/tests/AllTests.php b/tests/AllTests.php index 4afcc6b..9e825e8 100644 --- a/tests/AllTests.php +++ b/tests/AllTests.php @@ -12,23 +12,15 @@ * @license GPL http://www.gnu.org/licenses/gpl.html * @link http://sourceforge.net/projects/semanticscuttle */ -if (!defined('PHPUnit_MAIN_METHOD')) { - define('PHPUnit_MAIN_METHOD', 'AllTests::main'); -} - -require_once 'prepare.php'; /** * SemanticScuttle unit tests. * * To launch this tests, you need PHPUnit 3. * Run them with: - * $ php tests/AllTests.php + * $ cd tests; phpunit . * or single files like: - * $ php tests/BookmarkTest.php - * - * You also may use phpunit directly: - * $ phpunit tests/AllTests.php + * $ cd tests; phpunit BookmarkTest.php * * @category Bookmarking * @package SemanticScuttle @@ -40,14 +32,6 @@ require_once 'prepare.php'; */ class AllTests extends PHPUnit_Framework_TestSuite { - public static function main() - { - require_once 'PHPUnit/TextUI/TestRunner.php'; - PHPUnit_TextUI_TestRunner::run(self::suite()); - } - - - public static function suite() { $suite = new AllTests(); @@ -74,9 +58,4 @@ class AllTests extends PHPUnit_Framework_TestSuite { } } - -if (PHPUnit_MAIN_METHOD == 'AllTests::main') { - AllTests::main(); -} - ?> \ No newline at end of file diff --git a/tests/Api/ExportCsvTest.php b/tests/Api/ExportCsvTest.php index 2bff8a5..681f0de 100644 --- a/tests/Api/ExportCsvTest.php +++ b/tests/Api/ExportCsvTest.php @@ -12,14 +12,8 @@ * @license GPL http://www.gnu.org/licenses/gpl.html * @link http://sourceforge.net/projects/semanticscuttle */ - -require_once dirname(__FILE__) . '/../prepare.php'; require_once 'HTTP/Request2.php'; -if (!defined('PHPUnit_MAIN_METHOD')) { - define('PHPUnit_MAIN_METHOD', 'Api_ExportCsvTest::main'); -} - /** * Unit tests for the SemanticScuttle csv export API * @@ -39,21 +33,6 @@ class Api_ExportCsvTest extends TestBaseApi - /** - * 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__) - ); - } - - - /** * Test if authentication is required when sending no auth data */ @@ -280,8 +259,4 @@ class Api_ExportCsvTest extends TestBaseApi return $ar; } } - -if (PHPUnit_MAIN_METHOD == 'Api_ExportCsvTest::main') { - Api_ExportCsvTest::main(); -} ?> \ No newline at end of file diff --git a/tests/Api/PostsAddTest.php b/tests/Api/PostsAddTest.php index 1f21d04..53aa8e7 100644 --- a/tests/Api/PostsAddTest.php +++ b/tests/Api/PostsAddTest.php @@ -12,14 +12,8 @@ * @license GPL http://www.gnu.org/licenses/gpl.html * @link http://sourceforge.net/projects/semanticscuttle */ - -require_once dirname(__FILE__) . '/../prepare.php'; require_once 'HTTP/Request2.php'; -if (!defined('PHPUnit_MAIN_METHOD')) { - define('PHPUnit_MAIN_METHOD', 'Api_PostsAddTest::main'); -} - /** * Unit tests for the SemanticScuttle post addition API. * @@ -37,21 +31,6 @@ class Api_PostsAddTest extends TestBaseApi - /** - * 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__) - ); - } - - - /** * Test if authentication is required when sending no auth data */ @@ -428,8 +407,4 @@ TXT; $this->assertEquals($title2, $data['bookmarks'][0]['bTitle']); } } - -if (PHPUnit_MAIN_METHOD == 'Api_PostsAddTest::main') { - Api_PostsAddTest::main(); -} ?> \ No newline at end of file diff --git a/tests/Api/PostsDeleteTest.php b/tests/Api/PostsDeleteTest.php index d9fb6cd..7ba1285 100644 --- a/tests/Api/PostsDeleteTest.php +++ b/tests/Api/PostsDeleteTest.php @@ -12,14 +12,8 @@ * @license GPL http://www.gnu.org/licenses/gpl.html * @link http://sourceforge.net/projects/semanticscuttle */ - -require_once dirname(__FILE__) . '/../prepare.php'; require_once 'HTTP/Request2.php'; -if (!defined('PHPUnit_MAIN_METHOD')) { - define('PHPUnit_MAIN_METHOD', 'Api_PostsDeleteTest::main'); -} - /** * Unit tests for the SemanticScuttle post deletion API. * @@ -37,21 +31,6 @@ class Api_PostsDeleteTest extends TestBaseApi - /** - * 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__) - ); - } - - - /** * Test if authentication is required when sending no auth data */ @@ -296,8 +275,4 @@ class Api_PostsDeleteTest extends TestBaseApi } } - -if (PHPUnit_MAIN_METHOD == 'Api_PostsDeleteTest::main') { - Api_PostsDeleteTest::main(); -} ?> \ No newline at end of file diff --git a/tests/Api/PostsUpdateTest.php b/tests/Api/PostsUpdateTest.php index c497a55..51f8be2 100644 --- a/tests/Api/PostsUpdateTest.php +++ b/tests/Api/PostsUpdateTest.php @@ -12,14 +12,8 @@ * @license GPL http://www.gnu.org/licenses/gpl.html * @link http://sourceforge.net/projects/semanticscuttle */ - -require_once dirname(__FILE__) . '/../prepare.php'; require_once 'HTTP/Request2.php'; -if (!defined('PHPUnit_MAIN_METHOD')) { - define('PHPUnit_MAIN_METHOD', 'Api_PostsUpdateTest::main'); -} - /** * Unit tests for the SemanticScuttle last-update time API. * @@ -37,21 +31,6 @@ class Api_PostsUpdateTest extends TestBaseApi - /** - * 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__) - ); - } - - - /** * Test if authentication is required when sending no auth data */ @@ -128,8 +107,4 @@ class Api_PostsUpdateTest extends TestBaseApi } } - -if (PHPUnit_MAIN_METHOD == 'Api_PostsUpdateTest::main') { - Api_PostsUpdateTest::main(); -} ?> \ No newline at end of file diff --git a/tests/Bookmark2TagTest.php b/tests/Bookmark2TagTest.php index fff4222..789540f 100644 --- a/tests/Bookmark2TagTest.php +++ b/tests/Bookmark2TagTest.php @@ -12,11 +12,6 @@ * @license GPL http://www.gnu.org/licenses/gpl.html * @link http://sourceforge.net/projects/semanticscuttle */ -if (!defined('PHPUnit_MAIN_METHOD')) { - define('PHPUnit_MAIN_METHOD', 'Bookmark2TagTest::main'); -} - -require_once 'prepare.php'; /** * Unit tests for the SemanticScuttle bookmark-tag combination service. @@ -58,21 +53,6 @@ class Bookmark2TagTest extends TestBase - /** - * 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'); @@ -628,8 +608,4 @@ class Bookmark2TagTest extends TestBase $this->assertContains(array('tag' => 'usable', 'bCount' => '2'), $arTags); } } - -if (PHPUnit_MAIN_METHOD == 'Bookmark2TagTest::main') { - Bookmark2TagTest::main(); -} ?> \ No newline at end of file diff --git a/tests/BookmarkTest.php b/tests/BookmarkTest.php index f54fe9a..e7ce488 100644 --- a/tests/BookmarkTest.php +++ b/tests/BookmarkTest.php @@ -12,11 +12,6 @@ * @license GPL http://www.gnu.org/licenses/gpl.html * @link http://sourceforge.net/projects/semanticscuttle */ -if (!defined('PHPUnit_MAIN_METHOD')) { - define('PHPUnit_MAIN_METHOD', 'BookmarkTest::main'); -} - -require_once 'prepare.php'; /** * Unit tests for the SemanticScuttle bookmark service. @@ -37,22 +32,6 @@ class BookmarkTest extends TestBase 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'); @@ -1344,10 +1323,5 @@ class BookmarkTest extends TestBase -} - - -if (PHPUnit_MAIN_METHOD == 'BookmarkTest::main') { - BookmarkTest::main(); } ?> diff --git a/tests/CommonDescriptionTest.php b/tests/CommonDescriptionTest.php index 94f431d..7748cb3 100644 --- a/tests/CommonDescriptionTest.php +++ b/tests/CommonDescriptionTest.php @@ -12,11 +12,6 @@ * @license GPL http://www.gnu.org/licenses/gpl.html * @link http://sourceforge.net/projects/semanticscuttle */ -if (!defined('PHPUnit_MAIN_METHOD')) { - define('PHPUnit_MAIN_METHOD', 'CommonDescriptionTest::main'); -} - -require_once 'prepare.php'; /** * Unit tests for the SemanticScuttle common description service. @@ -39,21 +34,6 @@ class CommonDescriptionTest extends TestBase 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() { $this->us =SemanticScuttle_Service_Factory::get('User'); @@ -128,9 +108,4 @@ class CommonDescriptionTest extends TestBase } } - - -if (PHPUnit_MAIN_METHOD == 'CommonDescriptionTest::main') { - CommonDescriptionTest::main(); -} ?> diff --git a/tests/SearchHistoryTest.php b/tests/SearchHistoryTest.php index 69d1efa..f05dd29 100644 --- a/tests/SearchHistoryTest.php +++ b/tests/SearchHistoryTest.php @@ -12,11 +12,6 @@ * @license GPL http://www.gnu.org/licenses/gpl.html * @link http://sourceforge.net/projects/semanticscuttle */ -if (!defined('PHPUnit_MAIN_METHOD')) { - define('PHPUnit_MAIN_METHOD', 'SearchHistoryTest::main'); -} - -require_once 'prepare.php'; /** * Unit tests for the SemanticScuttle search history service. @@ -38,22 +33,6 @@ class SearchHistoryTest extends TestBase 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__) - ); - } - - - /** * Set up all services * @@ -391,10 +370,4 @@ class SearchHistoryTest extends TestBase $this->assertEquals(0, $this->shs->countSearches()); } } - - -if (PHPUnit_MAIN_METHOD == 'SearchHistoryTest::main') { - SearchHistoryTest::main(); -} - ?> diff --git a/tests/Tag2TagTest.php b/tests/Tag2TagTest.php index 033fc91..0b73864 100644 --- a/tests/Tag2TagTest.php +++ b/tests/Tag2TagTest.php @@ -12,11 +12,6 @@ * @license GPL http://www.gnu.org/licenses/gpl.html * @link http://sourceforge.net/projects/semanticscuttle */ -if (!defined('PHPUnit_MAIN_METHOD')) { - define('PHPUnit_MAIN_METHOD', 'Tag2TagTest::main'); -} - -require_once 'prepare.php'; /** * Unit tests for the SemanticScuttle tag2tag service. @@ -37,22 +32,6 @@ class Tag2TagTest extends TestBase 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'); @@ -550,8 +529,4 @@ class Tag2TagTest extends TestBase }*/ } - -if (PHPUnit_MAIN_METHOD == 'Tag2TagTest::main') { - Tag2TagTest::main(); -} ?> diff --git a/tests/TagTest.php b/tests/TagTest.php index 25d1a77..96f3f14 100644 --- a/tests/TagTest.php +++ b/tests/TagTest.php @@ -12,11 +12,6 @@ * @license GPL http://www.gnu.org/licenses/gpl.html * @link http://sourceforge.net/projects/semanticscuttle */ -if (!defined('PHPUnit_MAIN_METHOD')) { - define('PHPUnit_MAIN_METHOD', 'TagTest::main'); -} - -require_once 'prepare.php'; /** * Unit tests for the SemanticScuttle tag service. @@ -34,22 +29,6 @@ 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'); @@ -109,9 +88,4 @@ class TagTest extends TestBase } } - - -if (PHPUnit_MAIN_METHOD == 'TagTest::main') { - TagTest::main(); -} ?> diff --git a/tests/TagsCacheTest.php b/tests/TagsCacheTest.php index 94200dd..1f69b58 100644 --- a/tests/TagsCacheTest.php +++ b/tests/TagsCacheTest.php @@ -12,11 +12,6 @@ * @license GPL http://www.gnu.org/licenses/gpl.html * @link http://sourceforge.net/projects/semanticscuttle */ -if (!defined('PHPUnit_MAIN_METHOD')) { - define('PHPUnit_MAIN_METHOD', 'TagsCacheTest::main'); -} - -require_once 'prepare.php'; /** * Unit tests for the SemanticScuttle tags cache service. @@ -38,19 +33,6 @@ class TagsCacheTest extends PHPUnit_Framework_TestCase - /** - * 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'); @@ -207,9 +189,4 @@ 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/UserArrayTest.php b/tests/UserArrayTest.php index cb53f15..a60e37f 100644 --- a/tests/UserArrayTest.php +++ b/tests/UserArrayTest.php @@ -11,8 +11,6 @@ * @link http://sourceforge.net/projects/semanticscuttle */ -require_once 'prepare.php'; - /** * Unit tests for the SemanticScuttle user array model. * diff --git a/tests/UserTest.php b/tests/UserTest.php index 49f3730..2f57112 100644 --- a/tests/UserTest.php +++ b/tests/UserTest.php @@ -12,11 +12,6 @@ * @license GPL http://www.gnu.org/licenses/gpl.html * @link http://sourceforge.net/projects/semanticscuttle */ -if (!defined('PHPUnit_MAIN_METHOD')) { - define('PHPUnit_MAIN_METHOD', 'UserTest::main'); -} - -require_once 'prepare.php'; /** * Unit tests for the SemanticScuttle user service. @@ -31,24 +26,6 @@ require_once 'prepare.php'; */ class UserTest extends TestBase { - - - - /** - * 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'); @@ -200,10 +177,4 @@ class UserTest extends TestBase } } - - -if (PHPUnit_MAIN_METHOD == 'UserTest::main') { - UserTest::main(); -} - ?> \ No newline at end of file diff --git a/tests/VoteTest.php b/tests/VoteTest.php index 1623826..0073678 100644 --- a/tests/VoteTest.php +++ b/tests/VoteTest.php @@ -10,11 +10,6 @@ * @license GPL http://www.gnu.org/licenses/gpl.html * @link http://sourceforge.net/projects/semanticscuttle */ -if (!defined('PHPUnit_MAIN_METHOD')) { - define('PHPUnit_MAIN_METHOD', 'VoteTest::main'); -} - -require_once 'prepare.php'; /** * Unit tests for the SemanticScuttle voting system. @@ -43,21 +38,6 @@ class VoteTest extends TestBase - /** - * 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('VoteTest') - ); - } - - - public function setUp() { $GLOBALS['enableVoting'] = true; @@ -553,9 +533,4 @@ class VoteTest extends TestBase } }//class VoteTest extends TestBase - - -if (PHPUnit_MAIN_METHOD == 'VoteTest::main') { - VoteTest::main(); -} ?> \ No newline at end of file diff --git a/tests/ajax/GetAdminLinkedTagsTest.php b/tests/ajax/GetAdminLinkedTagsTest.php index aded834..43cb17a 100644 --- a/tests/ajax/GetAdminLinkedTagsTest.php +++ b/tests/ajax/GetAdminLinkedTagsTest.php @@ -12,14 +12,8 @@ * @license GPL http://www.gnu.org/licenses/gpl.html * @link http://sourceforge.net/projects/semanticscuttle */ - -require_once dirname(__FILE__) . '/../prepare.php'; require_once 'HTTP/Request2.php'; -if (!defined('PHPUnit_MAIN_METHOD')) { - define('PHPUnit_MAIN_METHOD', 'ajax_GetAdminLinkedTagsTest::main'); -} - /** * Unit tests for the ajax linked admin tags script * @@ -34,22 +28,6 @@ class ajax_GetAdminLinkedTagsTest extends TestBaseApi protected $urlPart = 'ajax/getadminlinkedtags.php'; - - /** - * 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__) - ); - } - - - /** * Verify that we get the configured root tags if * we do not pass any parameters @@ -139,8 +117,4 @@ class ajax_GetAdminLinkedTagsTest extends TestBaseApi $this->assertEquals('adminsubtag', $data[0]->data->title); } } - -if (PHPUnit_MAIN_METHOD == 'ajax_GetAdminLinkedTagsTest::main') { - ajax_GetAdminLinkedTagsTest::main(); -} ?> \ No newline at end of file diff --git a/tests/ajax/GetAdminTagsTest.php b/tests/ajax/GetAdminTagsTest.php index 80d702f..8bf8a83 100644 --- a/tests/ajax/GetAdminTagsTest.php +++ b/tests/ajax/GetAdminTagsTest.php @@ -12,8 +12,6 @@ * @license GPL http://www.gnu.org/licenses/gpl.html * @link http://sourceforge.net/projects/semanticscuttle */ - -require_once dirname(__FILE__) . '/../prepare.php'; require_once 'HTTP/Request2.php'; /** diff --git a/tests/ajax/GetContactTagsTest.php b/tests/ajax/GetContactTagsTest.php index 559040f..268ed66 100644 --- a/tests/ajax/GetContactTagsTest.php +++ b/tests/ajax/GetContactTagsTest.php @@ -12,8 +12,6 @@ * @license GPL http://www.gnu.org/licenses/gpl.html * @link http://sourceforge.net/projects/semanticscuttle */ - -require_once dirname(__FILE__) . '/../prepare.php'; require_once 'HTTP/Request2.php'; /** -- cgit v1.2.3-54-g00ecf