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 testRemove() { $this->assertTrue(Galleries::remove()); $this->assertTrue(Images::remove()); }
public function testSerializingCollection() { Fixtures::save('db'); $data = Images::find('all'); $this->skipIf(!$data, 'Fixtures not applied/available.'); $result = true; try { $data = serialize($data); $data = unserialize($data); } catch (Exception $e) { $result = false; $data = array(); } $this->assertTrue($result); $expected = 'Amiga 1200'; foreach ($data as $item) { $result = $item->title; break; } $this->assertEqual($expected, $result); }
/** * Prove that two distinct models each having a different connection to a different * database are working independently upon the correct databases. */ public function testSwitchingDatabaseDistinctModels() { $connection1 = $this->_connection; $connection2 = $this->_connection . '_alternative'; $connectionConfig1 = Connections::get($connection1, array('config' => true)); $connectionConfig2 = Connections::get($connection2, array('config' => true)); parent::connect($connection2); $this->skipIf(!$connectionConfig2, "The `'{$connection2}' connection is not available`."); $this->skipIf(!$this->with(array('MySql', 'PostgreSql', 'Sqlite3'))); $bothInMemory = $connectionConfig1['database'] == ':memory:'; $bothInMemory = $bothInMemory && $connectionConfig2['database'] == ':memory:'; $this->skipIf($bothInMemory, 'Cannot use two connections with in memory databases'); Fixtures::save('db_alternative'); Galleries::config(array('meta' => array('connection' => $connection1))); Images::config(array('meta' => array('connection' => $connection1))); $galleriesCountOriginal = Galleries::find('count'); $imagesCountOriginal = Images::find('count'); $gallery = Galleries::create(array('name' => 'record_in_db')); $gallery->save(); $image = Images::find('first', array('conditions' => array('id' => 1))); $image->delete(); Galleries::config(array('meta' => array('connection' => $connection2))); $expected = $galleriesCountOriginal; $result = Galleries::find('count'); $this->assertEqual($expected, $result); $expected = $imagesCountOriginal - 1; $result = Images::find('count'); $this->assertEqual($expected, $result); Fixtures::clear('db_alternative'); }
/** * Tests the default relationship information provided by the backend data source. */ public function testDefaultRelationshipInfo() { $db = $this->_db; $this->skipIf(!$db::enabled('relationships')); $this->assertEqual(array('Images'), array_keys(Galleries::relations())); $this->assertEqual(array('Galleries', 'ImagesTags', 'Comments'), array_keys(Images::relations())); $this->assertEqual(array('Images'), Galleries::relations('hasMany')); $this->assertEqual(array('Galleries'), Images::relations('belongsTo')); $this->assertEmpty(Galleries::relations('belongsTo')); $this->assertEmpty(Galleries::relations('hasOne')); $this->assertEqual(array('ImagesTags', 'Comments'), Images::relations('hasMany')); $this->assertEmpty(Images::relations('hasOne')); $result = Galleries::relations('Images'); $this->assertEqual('hasMany', $result->data('type')); $this->assertEqual($this->_classes['images'], $result->data('to')); }