public function testDateCastingUsingExists() { Galleries::config(array('schema' => array('_id' => 'id', 'created_at' => 'date'))); $gallery = Galleries::create(array('created_at' => time())); $gallery->save(); $result = Galleries::first(array('conditions' => array('created_at' => array('$exists' => false)))); $this->assertNull($result); }
public function testFieldsWithJoins() { $db = $this->_db; $this->skipIf(!$db::enabled('relationships')); $this->skipIf($this->with(array('MongoDb'))); $new = Galleries::create(array('name' => 'Celebrities')); $cKey = Galleries::meta('key'); $result = $new->save(); $this->assertTrue($result); $cId = (string) $new->{$cKey}; $new = Images::create(array('gallery_id' => $cId, 'title' => 'John Doe')); $eKey = Images::meta('key'); $result = $new->save(); $this->assertTrue($result); $eId = (string) $new->{$eKey}; $entity = Galleries::first(array('with' => 'Images', 'conditions' => array('Galleries.id' => $cId), 'fields' => array('Galleries' => array('name'), 'Images' => array('id', 'title')))); $expected = array('id' => $cId, 'name' => 'Celebrities', 'images' => array($eId => array('id' => $eId, 'title' => 'John Doe'))); $this->assertEqual($expected, $entity->data()); }
public function testUpdateWithNewArray() { $new = Galleries::create(array('name' => 'Poneys', 'active' => true)); $expected = array('name' => 'Poneys', 'active' => true); $result = $new->data(); $this->assertEqual($expected, $result); $new->foo = array('bar'); $expected = array('name' => 'Poneys', 'active' => true, 'foo' => array('bar')); $result = $new->data(); $this->assertEqual($expected, $result); $this->assertTrue($new->save()); $updated = Galleries::find((string) $new->_id); $expected = 'bar'; $result = $updated->foo[0]; $this->assertEqual($expected, $result); $updated->foo[1] = 'baz'; $this->assertTrue($updated->save()); $updated = Galleries::find((string) $updated->_id); $expected = 'baz'; $result = $updated->foo[1]; $this->assertEqual($expected, $result); }
public function testRemove() { $this->assertTrue(Galleries::remove()); $this->assertTrue(Images::remove()); }
/** * Tests that even when using a subquery the correct * number of records is returned. * * @link https://github.com/UnionOfRAD/lithium/issues/1209 */ public function testSubqueryWithMultipleRecords() { $results = Galleries::find('all', array('fields' => array('name', '(SELECT 23) AS number'))); $this->assertEqual(2, $results->count()); }
/** * Verifies that setting options using a raw SQL string works, when * the operation returns no result. * * @link https://github.com/UnionOfRAD/lithium/issues/1210 */ public function testRawOptionSettingWithNoResultResource() { $expected = array(); $result = Galleries::connection()->read('SET @TEST = 1;'); $this->assertEqual($expected, $result); }
public function testDefaultValues() { $this->_db->dropSchema('galleries'); $schema = new Schema(array('fields' => array('id' => array('type' => 'id'), 'name' => array('type' => 'string', 'length' => 255, 'default' => 'image'), 'active' => array('type' => 'boolean', 'default' => false), 'show' => array('type' => 'boolean', 'default' => true), 'empty' => array('type' => 'text', 'null' => true), 'created' => array('type' => 'timestamp', 'null' => true, 'default' => (object) 'CURRENT_TIMESTAMP'), 'modified' => array('type' => 'timestamp', 'null' => false, 'default' => (object) 'CURRENT_TIMESTAMP')))); $this->_db->createSchema('galleries', $schema); $gallery = Galleries::create(); $this->assertEqual('image', $gallery->name); $this->assertEqual(false, $gallery->active); $this->assertEqual(true, $gallery->show); $this->assertEqual(null, $gallery->empty); $gallery->save(); $result = Galleries::find('first')->data(); $this->assertEqual(1, $result['id']); $this->assertEqual('image', $result['name']); $this->assertEqual(false, $result['active']); $this->assertEqual(true, $result['show']); $this->assertEqual(null, $result['empty']); $this->assertPattern('$\\d{4}-\\d\\d-\\d\\d \\d\\d:\\d\\d:\\d\\d$', $result['created']); $this->assertPattern('$\\d{4}-\\d\\d-\\d\\d \\d\\d:\\d\\d:\\d\\d$', $result['modified']); $time = time(); $this->assertTrue($time - strtotime($result['created']) < 24 * 3600); $this->assertTrue($time - strtotime($result['modified']) < 24 * 3600); }
public function testUpdateWithNewProperties() { $db = $this->_db; $this->skipIf($db::enabled('schema')); $new = Galleries::create(array('name' => 'Flowers', 'active' => true)); $expected = array('name' => 'Flowers', 'active' => true); $result = $new->data(); $this->assertEqual($expected, $result); $new->foo = 'bar'; $expected = array('name' => 'Flowers', 'active' => true, 'foo' => 'bar'); $result = $new->data(); $this->assertEqual($expected, $result); $this->assertTrue($new->save()); $updated = Galleries::find('first', array('conditions' => Galleries::key($new))); $expected = 'bar'; $result = $updated->foo; $this->assertEqual($expected, $result); }
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()); } }