Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add further tests to wall setting

  • Loading branch information...
commit d7b26a5c260230253397d2bfacac2f518b2e55d4 1 parent 7ede9bf
Brian Birtles authored March 27, 2013
7  wall/lib/walls.inc
@@ -231,13 +231,13 @@ class Wall {
231 231
     // (XXX We'll have to change this in future to allow setting hidden fields 
232 232
     //  even if you can't *get* them)
233 233
     if (!isset($this->$name))
234  
-      throw new KeyedException('bad-key');
  234
+      throw new KeyedException('unknown-field');
235 235
 
236 236
     // Reject read-only/virtual fields
237 237
     // (XXX Might be better to handle each acceptable field below when we 
238 238
     //  sanitize and if it's not recognized, throw there)
239 239
     if (in_array($name, array('id', 'passcodeLen', 'wallUrl', 'editorUrl')))
240  
-      throw new KeyedException('bad-key');
  240
+      throw new KeyedException('unknown-field');
241 241
 
242 242
     // Sanitize values
243 243
     switch($name) {
@@ -327,6 +327,9 @@ class Wall {
327 327
     }
328 328
     $conn->disconnect();
329 329
 
  330
+    // Reset dirty fields
  331
+    $this->dirtyFields = array();
  332
+
330 333
     return $changedFields;
331 334
   }
332 335
 
1  wall/public/api/doWalls.php
@@ -79,7 +79,6 @@
79 79
       bailWithError('not-found');
80 80
 
81 81
     // Update fields
82  
-    // XXX Catch bad-key exceptions here
83 82
     foreach ($json as $key => $value) {
84 83
       $wall->$key = $value;
85 84
     }
66  wall/tests/api/TestSetWall.php
@@ -65,17 +65,81 @@ function testSetName() {
65 65
   }
66 66
 
67 67
   function testNotFound() {
  68
+    $this->login();
  69
+    $result = $this->updateWall(500, array('name' => 'ABCD'));
  70
+    $this->assertTrue(@$result['error_key'] == 'not-found',
  71
+                      "Found non-existent wall");
68 72
   }
69 73
 
70 74
   function testSetSomeoneElsesWall() {
  75
+    // Create wall
  76
+    $this->login();
  77
+    $wall = $this->createWall('Test wall', $this->testDesignId);
  78
+    $wallId = $wall['wallId'];
  79
+    $this->logout();
  80
+
  81
+    // Login as someone else
  82
+    $this->login('abc@abc.org');
  83
+    $result = $this->updateWall($wallId, array('name' => 'ABCD'));
  84
+    $this->assertEqual(@$result['error_key'], 'no-auth');
  85
+    $this->logout();
  86
+
  87
+    // Tidy up
  88
+    $this->removeWall($wallId);
71 89
   }
72 90
 
73  
-  function testUnrecognizedParams() {
  91
+  function testUnrecognizedParam() {
  92
+    // Create wall
  93
+    $this->login();
  94
+    $wall = $this->createWall('ABC', $this->testDesignId);
  95
+    $wallId = $wall['wallId'];
  96
+
  97
+    // Update mispelled param
  98
+    $result = $this->updateWall($wallId, array('nam' => 'ABCD'));
  99
+    $this->assertEqual(@$result['error_key'], 'unknown-field');
  100
+
  101
+    // Tidy up
  102
+    $this->removeWall($wallId);
74 103
   }
75 104
 
76 105
   function testNoChange() {
  106
+    // Create wall
  107
+    $this->login();
  108
+    $wall = $this->createWall('ABC', $this->testDesignId);
  109
+    $wallId = $wall['wallId'];
  110
+
  111
+    // Change nothing
  112
+    $result = $this->updateWall($wallId, array());
  113
+    $this->assertTrue(!array_key_exists('error_key', $result),
  114
+                      "Failed to do nothing " . @$result['error_key']);
  115
+    $this->assertEqual(count(@$result), 0);
  116
+
  117
+    // Tidy up
  118
+    $this->removeWall($wallId);
77 119
   }
78 120
 
79 121
   function testSetMultiple() {
  122
+    // Create wall
  123
+    $this->login();
  124
+    $wall = $this->createWall('ABC', $this->testDesignId);
  125
+    $wallId = $wall['wallId'];
  126
+
  127
+    // Update title and event description
  128
+    $result = $this->updateWall($wallId, array('name' => 'ABCD',
  129
+                                               'eventDescr' => 'A good event'));
  130
+    $this->assertTrue(!array_key_exists('error_key', $result),
  131
+                      "Failed to set wall name and description"
  132
+                      . @$result['error_key']);
  133
+    $this->assertEqual(@count($result), 2);
  134
+    $this->assertEqual(@$result['name'], 'ABCD');
  135
+    $this->assertEqual(@$result['eventDescr'], 'A good event');
  136
+
  137
+    // Check it actually updated the wall
  138
+    $wall = $this->getWall($wallId);
  139
+    $this->assertEqual(@$wall['name'], 'ABCD');
  140
+    $this->assertEqual(@$wall['eventDescr'], 'A good event');
  141
+
  142
+    // Tidy up
  143
+    $this->removeWall($wallId);
80 144
   }
81 145
 }

0 notes on commit d7b26a5

Please sign in to comment.
Something went wrong with that request. Please try again.