/**
  * @basedata false
  */
 public function testHasManyRelationCreate()
 {
     $author = new Author();
     $ret = $author->create(array('name' => 'Z', 'email' => 'z@z', 'identity' => 'z'));
     $this->assertResultSuccess($ret);
     ok($author->id);
     $address = $author->addresses->create(array('address' => 'farfaraway'));
     ok($address->id);
     ok($address->author_id);
     $this->assertEquals($author->id, $address->author_id);
     $this->assertEquals('farfaraway', $address->address);
     $this->assertResultSuccess($address->delete());
     $this->assertResultSuccess($author->delete());
 }
Exemplo n.º 2
0
 public function testManyToManyRelationFetch()
 {
     $author = new Author();
     $author->create(array('name' => 'Z', 'email' => 'z@z', 'identity' => 'z'));
     // XXX: in different database engine, it's different.
     // sometimes it's string, sometimes it's integer
     // ok( is_string( $author->getValue('id') ) );
     ok(is_integer($author->get('id')));
     $book = $author->books->create(array('title' => 'Book Test'));
     ok($book);
     ok($book->id, 'book is created');
     $ret = $book->delete();
     ok($ret->success);
     $ab = new \AuthorBooks\Model\AuthorBook();
     $book = new \AuthorBooks\Model\Book();
     // should not include this
     ok($book->create(array('title' => 'Book I Ex'))->success);
     ok($book->create(array('title' => 'Book I'))->success);
     ok($ab->create(array('author_id' => $author->id, 'book_id' => $book->id))->success);
     ok($book->create(array('title' => 'Book II'))->success);
     $ab->create(array('author_id' => $author->id, 'book_id' => $book->id));
     ok($book->create(array('title' => 'Book III'))->success);
     $ab->create(array('author_id' => $author->id, 'book_id' => $book->id));
     // retrieve books from relationshipt
     $author->flushCache();
     $books = $author->books;
     is(3, $books->size(), 'We have 3 books');
     $bookTitles = array();
     foreach ($books->items() as $item) {
         $bookTitles[$item->title] = true;
         $item->delete();
     }
     count_ok(3, array_keys($bookTitles));
     ok($bookTitles['Book I']);
     ok($bookTitles['Book II']);
     ok($bookTitles['Book III']);
     ok(!isset($bookTitles['Book I Ex']));
     $author->delete();
 }
Exemplo n.º 3
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.º 4
0
 /**
  * Basic CRUD Test 
  */
 public function testBasicCRUDOperations()
 {
     $author = new Author();
     $a2 = new Author();
     $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);
     $this->assertEquals($id, $author->id);
     $this->assertEquals('Foo', $author->name);
     $this->assertEquals('*****@*****.**', $author->email);
     $this->assertEquals(false, $author->confirmed);
     $ret = $author->load(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);
     $this->assertEquals('Bar', $author->name);
     $ret = $author->delete();
     $this->assertResultSuccess($ret);
     $data = $author->toArray();
     $this->assertEmpty($data);
 }