Пример #1
0
 /**
  * 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');
 }
Пример #2
0
 public function testOrder()
 {
     $images = Images::find('all', array('order' => 'id DESC', 'conditions' => array('gallery_id' => 1)));
     $this->assertCount(3, $images);
     $id = $images->first()->id;
     foreach ($images as $image) {
         $this->assertTrue($id >= $image->id);
     }
 }
Пример #3
0
 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);
 }