2009-10-25 16:31:31 +01:00
|
|
|
<?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';
|
|
|
|
|
2009-11-20 18:39:17 +01:00
|
|
|
PHPUnit_Util_Filter::addFileToFilter(__FILE__);
|
|
|
|
|
2009-10-25 16:31:31 +01:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
2010-02-16 22:54:31 +01:00
|
|
|
* @param integer $user User ID the bookmark shall belong
|
|
|
|
* @param string $address Bookmark address to use
|
2010-02-16 22:57:03 +01:00
|
|
|
* @param integer $status Bookmark visibility
|
2010-02-20 12:08:52 +01:00
|
|
|
* @param array $tags Array of tags to attach. If "null" is given,
|
|
|
|
* it will automatically be "unittest"
|
2010-03-28 20:07:18 +02:00
|
|
|
* @param string $title Bookmark title
|
2009-10-25 20:32:48 +01:00
|
|
|
*
|
2009-10-25 16:31:31 +01:00
|
|
|
* @return integer ID of bookmark
|
2010-02-16 22:57:03 +01:00
|
|
|
*
|
|
|
|
* @see SemanticScuttle_Service_Bookmark::addBookmark()
|
2009-10-25 16:31:31 +01:00
|
|
|
*/
|
2010-02-16 22:57:03 +01:00
|
|
|
protected function addBookmark(
|
2010-02-20 12:08:52 +01:00
|
|
|
$user = null, $address = null, $status = 0,
|
2010-03-28 20:07:18 +02:00
|
|
|
$tags = null, $title = null
|
2010-02-16 22:57:03 +01:00
|
|
|
) {
|
2009-10-25 20:32:48 +01:00
|
|
|
if ($user === null) {
|
|
|
|
$user = $this->addUser();
|
|
|
|
}
|
2010-02-20 12:08:52 +01:00
|
|
|
if ($tags === null) {
|
|
|
|
$tags = array('unittest');
|
|
|
|
}
|
2009-10-25 20:32:48 +01:00
|
|
|
|
|
|
|
$bs = SemanticScuttle_Service_Factory::get('Bookmark');
|
2009-10-25 16:31:31 +01:00
|
|
|
$rand = rand();
|
2010-02-16 22:54:31 +01:00
|
|
|
|
|
|
|
if ($address === null) {
|
|
|
|
$address = 'http://example.org/' . $rand;
|
|
|
|
}
|
2010-03-28 20:07:18 +02:00
|
|
|
if ($title === null) {
|
|
|
|
$title = 'unittest bookmark #' . $rand;
|
|
|
|
}
|
2010-02-16 22:54:31 +01:00
|
|
|
|
2009-10-25 20:32:48 +01:00
|
|
|
$bid = $bs->addBookmark(
|
2010-02-16 22:54:31 +01:00
|
|
|
$address,
|
2010-03-28 20:07:18 +02:00
|
|
|
$title,
|
2009-10-25 16:31:31 +01:00
|
|
|
'description',
|
|
|
|
null,
|
2010-02-16 22:57:03 +01:00
|
|
|
$status,
|
2010-02-20 12:08:52 +01:00
|
|
|
$tags,
|
2009-11-23 20:11:33 +01:00
|
|
|
null, null, false, false,
|
2009-10-25 20:32:48 +01:00
|
|
|
$user
|
2009-10-25 16:31:31 +01:00
|
|
|
);
|
|
|
|
return $bid;
|
|
|
|
}
|
|
|
|
|
2009-10-25 20:32:48 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new user in the database.
|
|
|
|
*
|
2010-03-28 20:04:53 +02:00
|
|
|
* @param string $username Username
|
|
|
|
* @param string $password Password
|
|
|
|
*
|
2009-10-25 20:32:48 +01:00
|
|
|
* @return integer ID of user
|
|
|
|
*/
|
2010-03-28 20:04:53 +02:00
|
|
|
protected function addUser($username = null, $password = null)
|
2009-10-25 20:32:48 +01:00
|
|
|
{
|
|
|
|
$us = SemanticScuttle_Service_Factory::get('User');
|
|
|
|
$rand = rand();
|
2010-03-28 20:04:53 +02:00
|
|
|
|
|
|
|
if ($username === null) {
|
|
|
|
$username = 'unittestuser-' . $rand;
|
|
|
|
}
|
|
|
|
if ($password === null) {
|
|
|
|
$password = $rand;
|
|
|
|
}
|
|
|
|
|
2009-10-25 20:32:48 +01:00
|
|
|
$uid = $us->addUser(
|
2010-03-28 20:04:53 +02:00
|
|
|
$username,
|
|
|
|
$password,
|
2009-10-25 20:32:48 +01:00
|
|
|
'unittest-' . $rand . '@example.org'
|
|
|
|
);
|
|
|
|
return $uid;
|
|
|
|
}
|
|
|
|
|
2010-10-08 17:43:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves the UID of an admin user.
|
|
|
|
* If that user does not exist in the database, it is created.
|
|
|
|
*
|
|
|
|
* @return integer UID of admin user
|
|
|
|
*/
|
|
|
|
protected function getAdminUser()
|
|
|
|
{
|
|
|
|
if (count($GLOBALS['admin_users']) == 0) {
|
|
|
|
$this->fail('No admin users configured');
|
|
|
|
}
|
|
|
|
$adminUserName = reset($GLOBALS['admin_users']);
|
|
|
|
|
|
|
|
$us = SemanticScuttle_Service_Factory::get('User');
|
|
|
|
$uid = $us->getIdFromUser($adminUserName);
|
|
|
|
if ($uid === null) {
|
|
|
|
//that user does not exist in the database; create it
|
|
|
|
$uid = $us->addUser(
|
|
|
|
$adminUserName,
|
|
|
|
rand(),
|
|
|
|
'unittest-admin-' . $adminUserName . '@example.org'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $uid;
|
|
|
|
}
|
2009-10-25 16:31:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|