Permalink
Browse files

Add further tests to wall setting

  • Loading branch information...
1 parent 7ede9bf commit d7b26a5c260230253397d2bfacac2f518b2e55d4 @birtles birtles committed Mar 27, 2013
Showing with 70 additions and 4 deletions.
  1. +5 −2 wall/lib/walls.inc
  2. +0 −1 wall/public/api/doWalls.php
  3. +65 −1 wall/tests/api/TestSetWall.php
View
@@ -231,13 +231,13 @@ class Wall {
// (XXX We'll have to change this in future to allow setting hidden fields
// even if you can't *get* them)
if (!isset($this->$name))
- throw new KeyedException('bad-key');
+ throw new KeyedException('unknown-field');
// Reject read-only/virtual fields
// (XXX Might be better to handle each acceptable field below when we
// sanitize and if it's not recognized, throw there)
if (in_array($name, array('id', 'passcodeLen', 'wallUrl', 'editorUrl')))
- throw new KeyedException('bad-key');
+ throw new KeyedException('unknown-field');
// Sanitize values
switch($name) {
@@ -327,6 +327,9 @@ class Wall {
}
$conn->disconnect();
+ // Reset dirty fields
+ $this->dirtyFields = array();
+
return $changedFields;
}
@@ -79,7 +79,6 @@
bailWithError('not-found');
// Update fields
- // XXX Catch bad-key exceptions here
foreach ($json as $key => $value) {
$wall->$key = $value;
}
@@ -65,17 +65,81 @@ function testSetName() {
}
function testNotFound() {
+ $this->login();
+ $result = $this->updateWall(500, array('name' => 'ABCD'));
+ $this->assertTrue(@$result['error_key'] == 'not-found',
+ "Found non-existent wall");
}
function testSetSomeoneElsesWall() {
+ // Create wall
+ $this->login();
+ $wall = $this->createWall('Test wall', $this->testDesignId);
+ $wallId = $wall['wallId'];
+ $this->logout();
+
+ // Login as someone else
+ $this->login('abc@abc.org');
+ $result = $this->updateWall($wallId, array('name' => 'ABCD'));
+ $this->assertEqual(@$result['error_key'], 'no-auth');
+ $this->logout();
+
+ // Tidy up
+ $this->removeWall($wallId);
}
- function testUnrecognizedParams() {
+ function testUnrecognizedParam() {
+ // Create wall
+ $this->login();
+ $wall = $this->createWall('ABC', $this->testDesignId);
+ $wallId = $wall['wallId'];
+
+ // Update mispelled param
+ $result = $this->updateWall($wallId, array('nam' => 'ABCD'));
+ $this->assertEqual(@$result['error_key'], 'unknown-field');
+
+ // Tidy up
+ $this->removeWall($wallId);
}
function testNoChange() {
+ // Create wall
+ $this->login();
+ $wall = $this->createWall('ABC', $this->testDesignId);
+ $wallId = $wall['wallId'];
+
+ // Change nothing
+ $result = $this->updateWall($wallId, array());
+ $this->assertTrue(!array_key_exists('error_key', $result),
+ "Failed to do nothing " . @$result['error_key']);
+ $this->assertEqual(count(@$result), 0);
+
+ // Tidy up
+ $this->removeWall($wallId);
}
function testSetMultiple() {
+ // Create wall
+ $this->login();
+ $wall = $this->createWall('ABC', $this->testDesignId);
+ $wallId = $wall['wallId'];
+
+ // Update title and event description
+ $result = $this->updateWall($wallId, array('name' => 'ABCD',
+ 'eventDescr' => 'A good event'));
+ $this->assertTrue(!array_key_exists('error_key', $result),
+ "Failed to set wall name and description"
+ . @$result['error_key']);
+ $this->assertEqual(@count($result), 2);
+ $this->assertEqual(@$result['name'], 'ABCD');
+ $this->assertEqual(@$result['eventDescr'], 'A good event');
+
+ // Check it actually updated the wall
+ $wall = $this->getWall($wallId);
+ $this->assertEqual(@$wall['name'], 'ABCD');
+ $this->assertEqual(@$wall['eventDescr'], 'A good event');
+
+ // Tidy up
+ $this->removeWall($wallId);
}
}

0 comments on commit d7b26a5

Please sign in to comment.