Permalink
Browse files

Make TestSessions use the return value of create wall

  • Loading branch information...
1 parent e6f6469 commit 97698e53f1b7cd6a1e89bd1b67d9afdc1073b8f8 @birtles birtles committed Mar 19, 2013
Showing with 57 additions and 53 deletions.
  1. +16 −4 wall/lib/walls.inc
  2. +3 −3 wall/public/api/doWalls.php
  3. +38 −46 wall/tests/api/TestSessions.php
View
@@ -235,6 +235,9 @@ function getWallDetails($wallId, $email) {
"$email is not the owner of this wall");
}
+ // Wall ID
+ $result["wallId"] = $wallId;
+
// Event information
$result["name"] = $row['eventname'];
$result["eventDescr"] = $row['eventdescr'];
@@ -584,7 +587,8 @@ class Wall {
'editorUrl', 'editorShortUrl',
'duration', 'defaultDuration',
'ownerEmail', 'passcodeLen',
- 'designId', 'latestSession');
+ 'designId',
+ 'status', 'latestSession');
$result = array();
foreach ($keys as $localKey => $keyToExport) {
@@ -629,9 +633,15 @@ class Wall {
error_log($res->getMessage() . ', ' . $res->getDebugInfo());
throw new KeyedException('db-error');
}
- $conn->disconnect();
- // XXX Update latest session
+ // Update latest session
+ $this->metadata['latestSession']['id']
+ = $conn->lastInsertId('sessions', 'sessionId');
+ $this->metadata['latestSession']['start'] = $datetime;
+ $this->metadata['latestSession']['end'] = null;
+ $this->metadata['status'] = 'running';
+
+ $conn->disconnect();
return true;
}
@@ -664,7 +674,9 @@ class Wall {
}
$conn->disconnect();
- // XXX Update latest session
+ // Update latest session
+ $this->metadata['latestSession']['end'] = $datetime;
+ $this->metadata['status'] = 'finished';
// Return true since we made a change
return true;
@@ -33,12 +33,12 @@
$email = @$_SESSION['email'];
$wall = Walls::create($name, $designId, $email);
- // Prepare result
- $result = $wall->asArray();
-
// Start session
$currentdatetime = gmdate("Y-m-d H:i:s");
$wall->startSession(null, $currentdatetime);
+
+ // Prepare result
+ $result = $wall->asArray();
break;
case 'GET':
@@ -20,117 +20,110 @@ function testCreateWall() {
$this->login();
// Create wall
- $wallId = $this->createWall('Test wall', $this->testDesignId);
-
- // Check wall is running
- $wall = $this->getWall($wallId);
- $this->assertTrue($wall['status'] == 'running');
+ $wall = $this->_createWall('Test wall', $this->testDesignId);
+ $this->assertEqual(@$wall['status'], 'running');
// Check there is a session ID, start time and null end time
- $this->assertTrue(array_key_exists('session', $wall) &&
- $wall['session'], "No session information found");
- if (@$wall['session']) {
- $this->assertTrue($this->isOpenSession($wall['session']),
+ $this->assertTrue(!empty($wall['latestSession']),
+ "No session information found");
+ if (@$wall['latestSession']) {
+ $this->assertTrue($this->isOpenSession($wall['latestSession']),
"After creating a wall we should have an open session");
}
// Tidy up by removing the wall
- $this->removeWall($wallId);
+ $this->removeWall($wall['wallId']);
}
function testCloseSession() {
// Login
$this->login();
// Create wall
- $wallId = $this->createWall('Test wall', $this->testDesignId);
+ $wall = $this->_createWall('Test wall', $this->testDesignId);
// Get current session ID
- $wall = $this->getWall($wallId);
- $sessionId = $wall['session']['id'];
+ $sessionId = $wall['latestSession']['id'];
// Close session
- $response = $this->closeSession($wallId, $sessionId);
+ $response = $this->endSession($wall['wallId'], $sessionId);
// Check we got the times and status
$this->assertTrue(!array_key_exists('error_key', $response),
- "Failed to close session: " . @$response['error_key']);
+ "Failed to end session: " . @$response['error_key']);
$this->assertTrue($this->isClosedSession($response),
- "Session does not appear to be closed.");
+ "Session does not appear to be ended.");
// Check the ID is the same
$this->assertEqual(@$response['id'], $sessionId,
"Got different session IDs: %s");
// Re-fetch wall
- $wall = $this->getWall($wallId);
+ $wall = $this->getWall($wall['wallId']);
$this->assertTrue($wall['status'] == 'finished');
$this->assertTrue($this->isClosedSession($wall['session']),
- "Refetched wall session does not appear to be closed.");
+ "Refetched wall session does not appear to be ended.");
// Logout and check it fails
$this->logout();
- $response = $this->closeSession($wallId, $sessionId);
+ $response = $this->endSession($wall['wallId'], $sessionId);
$this->assertTrue(array_key_exists('error_key', $response) &&
$response['error_key'] == 'logged-out',
"Closed session whilst logged out.");
- // XXX Check we can't close the session of someone else's wall
+ // XXX Check we can't end the session of someone else's wall
// XXX Test we get a bad-request error if either wallId or sessionId is
// missing or bad
// Tidy up by removing the wall
- $this->removeWall($wallId);
+ $this->removeWall($wall['wallId']);
}
function testCloseClosedSession() {
// Login
$this->login();
// Create wall
- $wallId = $this->createWall('Test wall', $this->testDesignId);
- $wall = $this->getWall($wallId); // In PHP < 5.4 we have to do this in two
- // steps
- $sessionId = $wall['session']['id'];
+ $wall = $this->_createWall('Test wall', $this->testDesignId);
+ $sessionId = $wall['latestSession']['id'];
// Close session
- $response = $this->closeSession($wallId, $sessionId);
+ $response = $this->endSession($wall['wallId'], $sessionId);
$this->assertTrue($this->isClosedSession($response),
- "Session does not appear to be closed");
+ "Session does not appear to be ended");
// Close again
- $response = $this->closeSession($wallId, $sessionId);
+ $response = $this->endSession($wall['wallId'], $sessionId);
$this->assertTrue(array_key_exists('error_key', $response) &&
$response['error_key'] == 'parallel-change',
"No error about parallel change when closing twice");
$this->assertTrue($this->isClosedSession(@$response['error_detail']),
- "Doubly-closed session does not appear to be closed");
+ "Doubly-ended session does not appear to be ended");
// Check ID hasn't changed
$this->assertEqual(@$response['error_detail']['id'], $sessionId,
"Got different session IDs: %s");
// Re-fetch wall (to check we're in a consistent state)
- $wall = $this->getWall($wallId);
+ $wall = $this->getWall($wall['wallId']);
$this->assertTrue($wall['status'] == 'finished');
$this->assertTrue($this->isClosedSession($wall['session']),
- "Refetched wall session does not appear to be closed.");
+ "Refetched wall session does not appear to be ended.");
// Tidy up by removing the wall
- $this->removeWall($wallId);
+ $this->removeWall($wall['wallId']);
}
function testStartNew() {
// Login
$this->login();
// Create wall
- $wallId = $this->createWall('Test wall', $this->testDesignId);
- $wall = $this->getWall($wallId);
- $sessionId = $wall['session']['id'];
+ $wall = $this->_createWall('Test wall', $this->testDesignId);
+ $sessionId = $wall['latestSession']['id'];
// Start new session
- $response = $this->startNewSession($wallId, $sessionId);
+ $response = $this->startNewSession($wall['wallId'], $sessionId);
// Check we got the times and status
$this->assertTrue(!array_key_exists('error_key', $response),
@@ -144,38 +137,37 @@ function testStartNew() {
"Got unexpected session ID: %s");
// Re-fetch wall
- $wall = $this->getWall($wallId);
+ $wall = $this->getWall($wall['wallId']);
$this->assertTrue($wall['status'] == 'running');
$this->assertTrue($this->isOpenSession($wall['session']),
"Refetched wall session does not appear to be open");
// Logout and check it fails
$this->logout();
- $response = $this->startNewSession($wallId, $sessionId);
+ $response = $this->startNewSession($wall['wallId'], $sessionId);
$this->assertTrue(array_key_exists('error_key', $response) &&
$response['error_key'] == 'logged-out',
"Started new session whilst logged out.");
// XXX Check we can't start a new session on someone else's wall
// Tidy up by removing the wall
- $this->removeWall($wallId);
+ $this->removeWall($wall['wallId']);
}
function testParallelStartNew() {
// Login
$this->login();
// Create wall
- $wallId = $this->createWall('Test wall', $this->testDesignId);
- $wall = $this->getWall($wallId);
- $sessionId = $wall['session']['id'];
+ $wall = $this->_createWall('Test wall', $this->testDesignId);
+ $sessionId = $wall['latestSession']['id'];
// Start new session
- $responseA = $this->startNewSession($wallId, $sessionId);
+ $responseA = $this->startNewSession($wall['wallId'], $sessionId);
// And do it again but with the OLD sessionId
- $responseB = $this->startNewSession($wallId, $sessionId);
+ $responseB = $this->startNewSession($wall['wallId'], $sessionId);
$this->assertTrue(array_key_exists('error_key', $responseB) &&
$responseB['error_key'] == 'parallel-change',
"No error about parallel change when starting with old "
@@ -190,7 +182,7 @@ function testParallelStartNew() {
"Got unexpected session ID: %s");
// Tidy up by removing the wall
- $this->removeWall($wallId);
+ $this->removeWall($wall['wallId']);
}
function isOpenSession($session) {
@@ -244,7 +236,7 @@ function getWall($wallId) {
return $wall;
}
- function closeSession($wallId, $sessionId) {
+ function endSession($wallId, $sessionId) {
// Prepare payload
$payload['wallId'] = $wallId;
$payload['sessionId'] = $sessionId;

0 comments on commit 97698e5

Please sign in to comment.