/** * Basic CRUD Test */ public function testModel() { $author = new Author(); $a2 = new Author(); $ret = $a2->load(array('name' => 'A record does not exist.')); ok(!$ret->success); ok(!$a2->id); $ret = $a2->create(array('name' => 'long string \'` long string', 'email' => 'email', 'identity' => 'id')); ok($ret->success); ok($a2->id); $ret = $a2->create(array('xxx' => true, 'name' => 'long string \'` long string', 'email' => 'email2', 'identity' => 'id2')); ok($ret->success); ok($a2->id); $ret = $author->create(array('name' => 'Foo', 'email' => '*****@*****.**', 'identity' => 'foo')); $this->resultOK(true, $ret); ok($id = $ret->id); is('Foo', $author->name); is('*****@*****.**', $author->email); $ret = $author->load($id); ok($ret->success); is($id, $author->id); is('Foo', $author->name); is('*****@*****.**', $author->email); is(false, $author->confirmed); $ret = $author->load(array('name' => 'Foo')); ok($ret->success); is($id, $author->id); is('Foo', $author->name); is('*****@*****.**', $author->email); is(false, $author->confirmed); $ret = $author->update(array('name' => 'Bar')); $this->resultOK(true, $ret); is('Bar', $author->name); $ret = $author->delete(); $this->resultOK(true, $ret); $data = $author->toArray(); ok(empty($data), 'should be empty'); }
public function testToArrayWithFields() { $author = new Author(); $ret = $author->create(array('name' => 'testToArray', 'email' => 'zz3@zz3', 'identity' => 'zz3')); $this->assertResultSuccess($ret); $array = $author->toArray(['name', 'email']); $this->assertArrayHasKey('name', $array); $this->assertArrayHasKey('email', $array); $this->assertArrayNotHasKey('identity', $array); }