public function testResultSet() { for ($i = 1; $i < 9; $i++) { Galleries::create(array('id' => $i, 'name' => "Title {$i}"))->save(); } $galleries = Galleries::all(); $cpt = 0; foreach ($galleries as $gallery) { $this->assertEqual(++$cpt, $gallery->id); } $this->assertIdentical(8, $cpt); $this->assertCount(8, $galleries); }
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()); }
protected function _testResultSet($connection) { $db = Connections::get($connection); $db->dropSchema('galleries'); $schema = new Schema($this->_schema); $db->createSchema('galleries', $schema); for ($i = 1; $i < 9; $i++) { Galleries::create(array('id' => $i, 'name' => "Title {$i}"))->save(); } $galleries = Galleries::all(); $cpt = 0; foreach ($galleries as $gallery) { $this->assertEqual(++$cpt, $gallery->id); } $this->assertIdentical(8, $cpt); $this->assertCount(8, $galleries); $db->dropSchema('galleries'); }
public function testAbstractTypeHandling() { $key = Galleries::meta('key'); foreach ($this->galleriesData as $data) { $galleries[] = Galleries::create($data); $this->assertTrue(end($galleries)->save()); $this->assertNotEmpty(end($galleries)->{$key}); } foreach (Galleries::all() as $galleries) { $this->assertTrue($galleries->delete()); } }