Skip to content

Commit a0afa22

Browse files
committed
added rest saving from post test
1 parent acb96cb commit a0afa22

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

tests/RestTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public function setUp() {
88
$this->useOb = true; // for debug use
99

1010
$this->tip->config('tests/config.ini');
11+
$this->setupDb($this->tip);
1112
}
1213

1314
public function testFormPost() {
@@ -180,4 +181,29 @@ public function testJsonGeneric() {
180181
$check = $this->ob(false);
181182
$this->assertEquals(json_encode(['test' => 'hi', 'data' => 'blah']), $check);
182183
}
184+
185+
public function testPostSave() {
186+
$_REQUEST['__url'] = 'drink/1';
187+
$_SERVER['REQUEST_METHOD'] = 'POST';
188+
$_SERVER['CONTENT_TYPE'] = 'application/x-www-form-urlencoded';
189+
$_POST['name'] = 'maitai';
190+
191+
$this->tip->service('Tipsy\Resource/Drink', [
192+
_id => 'id',
193+
_table => 'test_user'
194+
]);
195+
196+
$this->tip->post('drink/:id',function($Drink, $Request, $Params) {
197+
$Drink
198+
->load($Params->id)
199+
->serialize($Request->request())
200+
->save();
201+
echo $Drink->json();
202+
});
203+
204+
$this->ob();
205+
$this->tip->run();
206+
$check = $this->ob(false);
207+
$this->assertEquals(json_encode(['id' => 1, 'name' => 'maitai', 'username' => null, 'active' => false]), $check);
208+
}
183209
}

0 commit comments

Comments
 (0)