[schoorbs commit] r704 - in trunk: schoorbs-includes schoorbs-includes/database schoorbs-includes/rest-plugins scho...

0 views
Skip to first unread message

codesite...@google.com

unread,
Oct 26, 2008, 6:06:16 AM10/26/08
to schoor...@googlegroups.com
Author: xhochy
Date: Sun Oct 26 03:05:05 2008
New Revision: 704

Modified:
trunk/schoorbs-includes/database/entry.class.php
trunk/schoorbs-includes/database/room.class.php
trunk/schoorbs-includes/database/schoorbsdb.class.php
trunk/schoorbs-includes/rest-plugins/getroomid.rest.php
trunk/schoorbs-includes/rest.functions.php
trunk/schoorbs-tests/rest-tests/getroomid.test.php

Log:
Updated some unit tests

Modified: trunk/schoorbs-includes/database/entry.class.php
==============================================================================
--- trunk/schoorbs-includes/database/entry.class.php (original)
+++ trunk/schoorbs-includes/database/entry.class.php Sun Oct 26 03:05:05
2008
@@ -127,6 +127,7 @@

$aEntries = array();
$oResult = $oStatement->executeQuery();
+ var_dump($oStatement);
while ($oResult->next()) {
$aEntries[] = self::fetchEntry($oResult);
}

Modified: trunk/schoorbs-includes/database/room.class.php
==============================================================================
--- trunk/schoorbs-includes/database/room.class.php (original)
+++ trunk/schoorbs-includes/database/room.class.php Sun Oct 26 03:05:05 2008
@@ -33,7 +33,7 @@
* @return Room
*/
public static function create($oArea, $sName, $sDescription, $nCapacity) {
- if (self::getByName($oArea, $sName) !== null) {
+ if (self::getByName($sName, $oArea) !== null) {
throw new Exception('Room with name "'.$sName
.'" already exists in this area.');
}
@@ -76,14 +76,16 @@
* @return Room
* @author Uwe L. Korn <uw...@xhochy.org>
*/
- public static function getByName($oArea, $sName) {
+ public static function getByName($sName, $oArea = null) {
$oDB = SchoorbsDB::getInstance();
// Example Query
// SELECT * FROM schoorbs_rootm WHERE area_id = 1 AND room_name = 'Hi'
- $oStatement = $oDB->getConnection()->prepareStatement('SELECT * FROM '
- .$oDB->getTableName('room').' WHERE area_id = ? AND room_name = ?');
- $oStatement->setInt(1, $oArea->getId());
- $oStatement->setString(2, $sName);
+ $sQuery = 'SELECT * FROM '.$oDB->getTableName('room')
+ .' WHERE room_name = ?';
+ if ($oArea != null) $sQuery.= ' AND area_id = ?';
+ $oStatement = $oDB->getConnection()->prepareStatement($sQuery);
+ $oStatement->setString(1, $sName);
+ if ($oArea != null) $oStatement->setInt(2, $oArea->getId());
$oResult = $oStatement->executeQuery();
if ($oResult->next()) {
return self::fetchRoom($oResult);

Modified: trunk/schoorbs-includes/database/schoorbsdb.class.php
==============================================================================
--- trunk/schoorbs-includes/database/schoorbsdb.class.php (original)
+++ trunk/schoorbs-includes/database/schoorbsdb.class.php Sun Oct 26
03:05:05 2008
@@ -71,8 +71,8 @@
}

return self::$db;
- }
-
+ }
+
/// instance variables ///

/**
@@ -101,6 +101,15 @@
private function __construct($aDSN, $sPrefix = '') {
$this->oConnection = Creole::getConnection($aDSN,
Creole::COMPAT_ASSOC_LOWER);
$this->sPrefix = $sPrefix;
+ }
+
+ /**
+ * Close the database connection when cleaning up
+ *
+ * @author Uwe L. Korn <uw...@xhochy.org>
+ */
+ function __destruct() {
+ $this->oConnection->close();
}

/**
@@ -124,5 +133,17 @@
*/
public function getTableName($sTable) {
return $this->sPrefix.$sTable;
+ }
+
+ /**
+ * Change the prefix for the tables in the database
+ *
+ * This is only used for the unit tests
+ *
+ * @param $sPrefix string
+ * @author Uwe L. Korn <uw...@xhochy.org>
+ */
+ public function setPrefix($sPrefix) {
+ $this->sPrefix = $sPrefix;
}
}

Modified: trunk/schoorbs-includes/rest-plugins/getroomid.rest.php
==============================================================================
--- trunk/schoorbs-includes/rest-plugins/getroomid.rest.php (original)
+++ trunk/schoorbs-includes/rest-plugins/getroomid.rest.php Sun Oct 26
03:05:05 2008
@@ -22,19 +22,16 @@
// Get the parameter 'name' from the HTTP-Request
$sName = unslashes($_REQUEST['name']);
// Search for a fitting room in the database
- $nRoomID = sql_query1(sprintf(
- 'SELECT id FROM %s WHERE room_name = \'%s\'',
- $tbl_room, sql_escape_arg($sName)
- ));
+ $oRoom = Room::getByName($sName);

// If we haven't found a fitting room, return an error. This case is
either
// identified by an unset $nRoomID or an $nRoomID with the value of
int(-1).
- if (!isset($nRoomID) || ($nRoomID == -1)) {
+ if ($oRoom == null) {
return SchoorbsREST::sendError('Couldn\'t find a fitting room.', 5);
}

// Return the room id
$oXML = new SimpleXMLElement('<rsp stat="ok" />');
- $oXML->addChild('room_id', $nRoomID);
+ $oXML->addChild('room_id', $oRoom->getId());
echo $oXML->asXML();
}

Modified: trunk/schoorbs-includes/rest.functions.php
==============================================================================
--- trunk/schoorbs-includes/rest.functions.php (original)
+++ trunk/schoorbs-includes/rest.functions.php Sun Oct 26 03:05:05 2008
@@ -12,6 +12,8 @@

/** The Configuration file */
require_once dirname(__FILE__).'/../config.inc.php';
+/** The modern ORM databse layer */
+require_once
dirname(__FILE__).'/../schoorbs-includes/database/schoorbsdb.class.php';
/** The database wrapper */
require_once dirname(__FILE__)."/../schoorbs-includes/database/$dbsys.php";
/** The input checking/validation functions */

Modified: trunk/schoorbs-tests/rest-tests/getroomid.test.php
==============================================================================
--- trunk/schoorbs-tests/rest-tests/getroomid.test.php (original)
+++ trunk/schoorbs-tests/rest-tests/getroomid.test.php Sun Oct 26 03:05:05
2008
@@ -38,6 +38,7 @@
DatabaseHelper::removeTestTables();
DatabaseHelper::createTestTables();
DatabaseHelper::flavourTblGlobals();
+
SchoorbsDB::getInstance()->setPrefix(TestConfiguration::$sDatabaseTablePrefix);
$this->nArea = DatabaseHelper::addArea('test1');
$this->sRoom = 'Test1';
$this->sNonRoom = 'Test0';
@@ -49,27 +50,26 @@
*
* @author Uwe L. Korn <uw...@xhochy.org>
*/
- public function testRoomExist()
- {
+ public function testRoomExist()
+ {
unset($_GET['name']);
unset($_POST['name']);
unset($_REQUEST['name']);

$_REQUEST['name'] = $this->sRoom;
-
$this->expectOutputRegex('/<room_id>'.$this->nRoom.'<\/room_id>/');

$_REQUEST['call'] = 'getRoomID';
SchoorbsREST::handleRequest();
- }
+ }

- /**
+ /*
* Test with an non-existing room
*
* @author Uwe L. Korn <uw...@xhochy.org>
*/
- public function testRoomNonExist()
- {
+ public function testRoomNonExist()
+ {
unset($_GET['name']);
unset($_POST['name']);
unset($_REQUEST['name']);
@@ -81,5 +81,5 @@

$_REQUEST['call'] = 'getRoomID';
SchoorbsREST::handleRequest();
- }
+ }
}

Reply all
Reply to author
Forward
0 new messages