diff options
author | Christian Weiske <cweiske@cweiske.de> | 2010-08-12 20:49:35 +0200 |
---|---|---|
committer | Christian Weiske <cweiske@cweiske.de> | 2010-08-12 20:49:35 +0200 |
commit | 0a8dadf87e660e9bf205581f12f7af87bfabf6ca (patch) | |
tree | a1218f869401a1ffff764a58c28a0be674ba5362 /tests/TestBaseApi.php | |
parent | b25290cef48251a31cb0f693a53677b566c1b1a4 (diff) | |
parent | 31570df64ce6543de407e7b9d751ba9033d930de (diff) | |
download | semanticscuttle-0a8dadf87e660e9bf205581f12f7af87bfabf6ca.tar.gz semanticscuttle-0a8dadf87e660e9bf205581f12f7af87bfabf6ca.tar.bz2 |
Merge branch 'master' into pearpkg
Diffstat (limited to 'tests/TestBaseApi.php')
-rw-r--r-- | tests/TestBaseApi.php | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/tests/TestBaseApi.php b/tests/TestBaseApi.php new file mode 100644 index 0000000..645ead9 --- /dev/null +++ b/tests/TestBaseApi.php @@ -0,0 +1,100 @@ +<?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'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__); + +/** + * Base unittest class for web API tests. + * + * @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 TestBaseApi extends TestBase +{ + protected $url; + protected $urlPart = null; + + + + protected function setUp() + { + if ($GLOBALS['unittestUrl'] === null) { + $this->assertTrue(false, 'Unittest URL not set in config'); + } + if ($this->urlPart === null) { + $this->assertTrue(false, 'Set the urlPart variable'); + } + $this->url = $GLOBALS['unittestUrl'] . $this->urlPart; + + $this->us = SemanticScuttle_Service_Factory::get('User'); + $this->us->deleteAll(); + $this->bs = SemanticScuttle_Service_Factory::get('Bookmark'); + $this->bs->deleteAll(); + $this->b2t = SemanticScuttle_Service_Factory::get('Bookmark2Tag'); + $this->b2t->deleteAll(); + } + + + + /** + * Gets a HTTP request object + * + * @param string $urlSuffix Suffix for the URL + * + * @return HTTP_Request2 HTTP request object + */ + protected function getRequest($urlSuffix = null) + { + $req = new HTTP_Request2( + $this->url . $urlSuffix, + HTTP_Request2::METHOD_GET + ); + + return $req; + } + + + + /** + * Gets a HTTP request object + * + * @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 + */ + protected function getAuthRequest($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); + $req->setAuth( + $username, $password, + HTTP_Request2::AUTH_BASIC + ); + return array($req, $uid); + } + +} +?>
\ No newline at end of file |