コード例 #1
0
ファイル: MongoDbTest.php プロジェクト: unionofrad/lithium
 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);
 }
コード例 #2
0
ファイル: FieldsTest.php プロジェクト: nilamdoc/KYCGlobal
 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());
 }
コード例 #3
0
ファイル: DocumentTest.php プロジェクト: nilamdoc/KYCGlobal
 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);
 }
コード例 #4
0
ファイル: DatabaseTest.php プロジェクト: rapzo/lithium
 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);
 }
コード例 #5
0
ファイル: DatabaseTest.php プロジェクト: fedeisas/lithium
 /**
  * Tests if DISTINCT queries work as expected and do not
  * duplicate records.
  *
  * @link https://github.com/UnionOfRAD/lithium/issues/1175
  */
 public function testDistinctResultsInNoDuplicates()
 {
     Galleries::create(array('name' => 'A'))->save();
     Galleries::create(array('name' => 'B'))->save();
     Galleries::create(array('name' => 'C'))->save();
     Galleries::create(array('name' => 'D'))->save();
     Galleries::create(array('name' => 'A'))->save();
     Galleries::create(array('name' => 'A'))->save();
     Galleries::create(array('name' => 'A'))->save();
     Galleries::create(array('name' => 'B'))->save();
     Galleries::create(array('name' => 'C'))->save();
     Galleries::create(array('name' => 'D'))->save();
     $results = Galleries::find('all', array('fields' => array('DISTINCT name as d__name')));
     $names = array();
     foreach ($results as $result) {
         $this->assertNotContains($result->d__name, $names);
         $names[] = $result->d__name;
     }
     $results = Galleries::find('all', array('fields' => array('DISTINCT id AS d__id', 'name')));
     $ids = array();
     foreach ($results as $result) {
         $this->assertNotContains($result->d__id, $ids);
         $ids[] = $result->d__id;
     }
 }
コード例 #6
0
ファイル: MySqlTest.php プロジェクト: unionofrad/lithium
 /**
  * Contrary to other data sources, MySQL only support one TIMESTAMP column by table.
  */
 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'))));
     $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->assertTrue(time() - strtotime($result['created']) < 24 * 3600);
 }
コード例 #7
0
ファイル: CrudTest.php プロジェクト: fedeisas/lithium
 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);
 }
コード例 #8
0
ファイル: SourceTest.php プロジェクト: fedeisas/lithium
 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());
     }
 }