begin with ajax unittests - but they do not work yet
This commit is contained in:
parent
d6e99db40d
commit
db71e63467
2 changed files with 109 additions and 0 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
73
tests/ajax/GetContactTagsTest.php
Normal file
73
tests/ajax/GetContactTagsTest.php
Normal file
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
/**
|
||||
* SemanticScuttle - your social bookmark manager.
|
||||
*
|
||||
* PHP version 5.
|
||||
*
|
||||
* @category Bookmarking
|
||||
* @package SemanticScuttle
|
||||
* @author Benjamin Huynh-Kim-Bang <mensonge@users.sourceforge.net>
|
||||
* @author Christian Weiske <cweiske@cweiske.de>
|
||||
* @author Eric Dane <ericdane@users.sourceforge.net>
|
||||
* @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 <cweiske@cweiske.de>
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
Loading…
Reference in a new issue