Пример #1
0
 public function testCollection()
 {
     $author = new Author();
     ok($author);
     foreach (range(1, 3) as $i) {
         $ret = $author->create(array('name' => 'Bar-' . $i, 'email' => 'bar@bar' . $i, 'identity' => 'bar' . $i, 'confirmed' => $i % 2 ? true : false));
         $this->resultOK(true, $ret);
     }
     foreach (range(1, 20) as $i) {
         $ret = $author->create(array('name' => 'Foo-' . $i, 'email' => 'foo@foo' . $i, 'identity' => 'foo' . $i, 'confirmed' => $i % 2 ? true : false));
         $this->resultOK(true, $ret);
     }
     $authors2 = new AuthorCollection();
     $authors2->where()->like('name', 'Foo');
     $count = $authors2->queryCount();
     is(20, $count);
     $authors = new AuthorCollection();
     $authors->where()->like('name', 'Foo');
     $items = $authors->items();
     is(20, $authors->size());
     ok(is_array($items));
     foreach ($items as $item) {
         ok($item->id);
         $this->assertInstanceOf('AuthorBooks\\Model\\Author', $item);
         $ret = $item->delete();
         ok($ret->success);
     }
     $size = $authors->free()->size();
     is(0, $size);
     $authors = new AuthorCollection();
     foreach ($authors as $a) {
         $a->delete();
     }
 }