Exemplo n.º 1
0
 /**
  * Basic CRUD Test 
  */
 public function testBasicCRUDOperations()
 {
     $author = new Author();
     $a2 = new Author();
     $ret = $a2->find(array('name' => 'A record does not exist.'));
     $this->assertResultFail($ret);
     ok(!$a2->id);
     $ret = $a2->create(array('xxx' => true, 'name' => 'long string \'` long string', 'email' => 'email2', 'identity' => 'id2'));
     $this->assertResultSuccess($ret);
     ok($a2->id);
     $ret = $author->create(array());
     $this->assertResultFail($ret);
     ok($ret->message);
     like('/Empty arguments/', $ret->message);
     $ret = $author->create(array('name' => 'Foo', 'email' => '*****@*****.**', 'identity' => 'foo'));
     $this->assertResultSuccess($ret);
     ok($id = $ret->id);
     is('Foo', $author->name);
     is('*****@*****.**', $author->email);
     $ret = $author->load($id);
     $this->assertResultSuccess($ret);
     is($id, $author->id);
     is('Foo', $author->name);
     is('*****@*****.**', $author->email);
     is(false, $author->confirmed);
     $ret = $author->find(array('name' => 'Foo'));
     $this->assertResultSuccess($ret);
     is($id, $author->id);
     is('Foo', $author->name);
     is('*****@*****.**', $author->email);
     is(false, $author->confirmed);
     $ret = $author->update(array('name' => 'Bar'));
     $this->assertResultSuccess($ret);
     is('Bar', $author->name);
     $ret = $author->delete();
     $this->assertResultSuccess($ret);
     $data = $author->toArray();
     $this->assertEmpty($data);
 }
Exemplo n.º 2
0
 /**
  * Basic CRUD Test 
  */
 public function testModel()
 {
     $author = new Author();
     ok($author);
     $a2 = new Author();
     $ret = $a2->find(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());
     ok($ret);
     ok(!$ret->success);
     ok($ret->message);
     is('Empty arguments', $ret->message);
     $ret = $author->create(array('name' => 'Foo', 'email' => '*****@*****.**', 'identity' => 'foo'));
     ok($ret);
     ok($id = $ret->id);
     ok($ret->success);
     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->find(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'));
     ok($ret->success);
     is('Bar', $author->name);
     $ret = $author->delete();
     ok($ret->success);
     $data = $author->toArray();
     ok(empty($data), 'should be empty');
 }