示例#1
0
 public function testCrudMulti()
 {
     $records = array('cities' => Galleries::create(array('name' => 'Cities', 'active' => true)), 'flowers' => Galleries::create(array('name' => 'Flowers', 'active' => true)), 'poneys' => Galleries::create(array('name' => 'Poneys', 'active' => true)));
     foreach ($records as $key => $record) {
         $this->assertFalse($record->exists());
         $this->assertTrue($record->save());
         $this->assertTrue($record->exists());
     }
     $this->assertEqual(3, Galleries::count());
     $all = Galleries::all();
     $this->assertEqual(3, $all->count());
     $match = 'Cities';
     $filter = function ($entity) use(&$match) {
         return $entity->name === $match;
     };
     foreach (array('Cities', 'Flowers', 'Poneys') as $match) {
         $this->assertTrue($all->first($filter)->exists());
     }
     $this->assertEqual(array(true, true, true), array_values($all->delete()));
     $this->assertEqual(0, Galleries::count());
 }
示例#2
0
 public function testCreateData()
 {
     $gallery = Galleries::create(array('name' => 'New Gallery'));
     $this->assertTrue($gallery->save());
     $this->assertNotEmpty($gallery->id);
     $this->assertTrue(Galleries::count() === 3);
     $img = Images::create(array('image' => 'newimage.png', 'title' => 'New Image', 'gallery_id' => $gallery->id));
     $this->assertEqual(true, $img->save());
     $img = Images::find($img->id);
     $this->assertEqual($gallery->id, $img->gallery_id);
 }
示例#3
0
 public function testReadWriteMultiple()
 {
     $this->skipIf($this->with(array('CouchDb')));
     $galleries = array();
     $key = Galleries::meta('key');
     foreach ($this->galleriesData as $data) {
         $galleries[] = Galleries::create($data);
         $this->assertTrue(end($galleries)->save());
         $this->assertNotEmpty(end($galleries)->{$key});
     }
     $this->assertIdentical(2, Galleries::count());
     $this->assertIdentical(1, Galleries::count(array('active' => true)));
     $this->assertIdentical(1, Galleries::count(array('active' => false)));
     $this->assertIdentical(0, Galleries::count(array('active' => null)));
     $all = Galleries::all();
     $this->assertIdentical(2, Galleries::count());
     $expected = count($this->galleriesData);
     $this->assertEqual($expected, $all->count());
     $this->assertEqual($expected, count($all));
     $id = (string) $all->first()->{$key};
     $this->assertTrue(strlen($id) > 0);
     $this->assertNotEmpty($all->data());
     foreach ($galleries as $galleries) {
         $this->assertTrue($galleries->delete());
     }
     $this->assertIdentical(0, Galleries::count());
 }