Reverted changes of date() to gdate(), added tests to confirm existence of private RSS feed, and finalized changes to the user session usage with rss.php

This commit is contained in:
Mark Pemberton 2011-06-04 00:29:04 -04:00
parent 342d1c3205
commit 84e603aa91
10 changed files with 68 additions and 45 deletions

View File

@ -486,7 +486,7 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
} else {
$time = strtotime($date);
}
$datetime = date('Y-m-d H:i:s', $time);
$datetime = gmdate('Y-m-d H:i:s', $time);
if ($short === '') {
$short = null;

View File

@ -584,7 +584,7 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService
if (is_int($days)) {
$query .= ' AND B.bDatetime > "'
. date('Y-m-d H:i:s', time() - (86400 * $days))
. gmdate('Y-m-d H:i:s', time() - (86400 * $days))
. '"';
}

View File

@ -571,8 +571,6 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
$this->db->sql_freeresult($dbresult);
if ($row) {
$id = $_SESSION[$this->getSessionKey()]
= $row[$this->getFieldName('primary')];
return true;
} else {
return false;

View File

@ -111,7 +111,7 @@ TXT;
$this->assertEquals($bmDescription, stripslashes($bm['bDescription']));
$this->assertEquals($bmTags, $bm['tags']);
$this->assertEquals(
date('Y-m-d H:i:s', strtotime($bmDatetime)),
gmdate('Y-m-d H:i:s', strtotime($bmDatetime)),
$bm['bDatetime']
);
}
@ -173,7 +173,7 @@ TXT;
$this->assertEquals($bmDescription, stripslashes($bm['bDescription']));
$this->assertEquals($bmTags, $bm['tags']);
$this->assertEquals(
date('Y-m-d H:i:s', strtotime($bmDatetime)),
gmdate('Y-m-d H:i:s', strtotime($bmDatetime)),
$bm['bDatetime']
);
}

View File

@ -164,15 +164,16 @@ class TestBaseApi extends TestBase
*
* 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
* @param string $urlSuffix Suffix for the URL
* @param mixed $auth If user authentication is needed (true/false)
* or array with username and password
* @param boolean $privateKey True if to add user with private key
*
* @return array(HTTP_Request2, integer) HTTP request object and user id
*
* @uses getRequest()
*/
protected function getLoggedInRequest($urlSuffix = null, $auth = true)
protected function getLoggedInRequest($urlSuffix = null, $auth = true, $privateKey = false)
{
if (is_array($auth)) {
list($username, $password) = $auth;
@ -180,7 +181,13 @@ class TestBaseApi extends TestBase
$username = 'testuser';
$password = 'testpassword';
}
$uid = $this->addUser($username, $password);
//include privatekey if requested
if ($privateKey) {
$pKey = $this->us->getNewPrivateKey();
} else {
$pKey = null;
}
$uid = $this->addUser($username, $password, $pKey);
$req = new HTTP_Request2(
$GLOBALS['unittestUrl'] . '/login.php?unittestMode=1',
@ -234,7 +241,7 @@ class TestBaseApi extends TestBase
*/
protected function setUnittestConfig($arConfig)
{
$str = '<' . "?php\r\n";
$str = '<' . "?php\n";
foreach ($arConfig as $name => $value) {
$str .= '$' . $name . ' = '
. var_export($value, true) . ";\n";
@ -253,4 +260,4 @@ class TestBaseApi extends TestBase
);
}
}
?>
?>

View File

@ -76,5 +76,32 @@ class www_bookmarksTest extends TestBaseApi
$this->assertEquals(1, (string)$elements[0]['value']);
}//end testDefaultPrivacyBookmarksAdd
/**
* Test that the private RSS link exists when a user
* has a private key and is enabled
*/
public function testVerifyPrivateRSSLinkExists()
{
list($req, $uId) = $this->getLoggedInRequest('?unittestMode=1', true, true);
$user = $this->us->getUser($uId);
$reqUrl = $GLOBALS['unittestUrl'] . 'bookmarks.php/'
. $user['username'];
$req->setUrl($reqUrl);
$req->setMethod(HTTP_Request2::METHOD_GET);
$response = $req->send();
$response_body = $response->getBody();
$this->assertNotEquals('', $response_body, 'Response is empty');
$x = simplexml_load_string($response_body);
$ns = $x->getDocNamespaces();
$x->registerXPathNamespace('ns', reset($ns));
$elements = $x->xpath('//ns:link');
$this->assertEquals(5, count($elements), 'Number of Links in Head not correct');
$this->assertContains('privatekey=', (string)$elements[4]['href']);
}//end testVerifyPrivateRSSLinkExists
}//end class www_bookmarksTest
?>

View File

@ -1,23 +1,16 @@
<?php
/***************************************************************************
Copyright (C) 2005 - 2006 Scuttle project
http://sourceforge.net/projects/scuttle/
http://scuttle.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
***************************************************************************/
/**
* Ajax script to retrieve new Private Key
*
* PHP version 5.
*
* @category Bookmarking
* @package SemanticScuttle
* @author Christian Weiske <cweiske@cweiske.de>
* @author Mark Pemberton <mpemberton5@gmail.com>
* @license AGPL http://www.gnu.org/licenses/agpl.html
* @link http://sourceforge.net/projects/semanticscuttle
*/
header("Last-Modified: ". gmdate("D, d M Y H:i:s") ." GMT");
header("Cache-Control: no-cache, must-revalidate");

View File

@ -51,7 +51,7 @@ if ($userservice->isLoggedOn()) {
array_push(
$tplVars['rsschannels'],
array(
filter($sitename . sprintf(T_(': (private) ')) . $currentUsername),
filter($sitename . sprintf(T_(': Recent bookmarks (private)')) . $currentUsername),
createURL('rss', filter($currentUsername, 'url') . '?sort='.getSortOrder().'&amp;privatekey='.$currentUser->getPrivateKey())
)
);

View File

@ -89,6 +89,14 @@ function useAddress(ele) {
}
}
/**
* Makes an ajax call to PHP script to generate an new Private Key
*
* @param input Calling object
* @param response Response object that returned value is placed
*
* @return boolean Returns false to halt execution after call
*/
function getNewPrivateKey(input, response){
var pk = document.getElementById('pPrivateKey');
if (response != null) {

View File

@ -71,7 +71,6 @@ if (isset($_GET['privatekey'])) {
$watchlist = null;
$pagetitle = '';
$isTempLogin = false;
if ($user && $user != 'all') {
if ($user == 'watchlist') {
$user = $cat;
@ -86,9 +85,7 @@ if ($user && $user != 'all') {
/* if user is not logged in and has valid privatekey */
if (!$userservice->isLoggedOn()) {
if ($privatekey != null) {
if ($userservice->loginPrivateKey($privatekey)) {
$isTempLogin = true;
} else {
if (!$userservice->loginPrivateKey($privatekey)) {
$tplVars['error'] = sprintf(T_('Failed to Autenticate User with username %s using private key'), $user);
header('Content-type: text/html; charset=utf-8');
$templateservice->loadTemplate('error.404.tpl', $tplVars);
@ -109,9 +106,7 @@ if ($user && $user != 'all') {
$pagetitle .= ": ". $user;
} else {
if ($privatekey != null) {
if ($userservice->loginPrivateKey($privatekey)) {
$isTempLogin = true;
} else {
if (!$userservice->loginPrivateKey($privatekey)) {
$tplVars['error'] = sprintf(T_('Failed to Autenticate User with username %s using private key'), $user);
header('Content-type: text/html; charset=utf-8');
$templateservice->loadTemplate('error.404.tpl', $tplVars);
@ -168,11 +163,6 @@ $tplVars['feedlastupdate'] = date('r', strtotime($latestdate));
$templateservice->loadTemplate('rss.tpl', $tplVars);
/* If temporary login, please log out */
if ($isTempLogin) {
$userservice->logout();
}
if ($usecache) {
// Cache output if existing copy has expired
$cacheservice->End($hash);