Beispiel #1
0
 /**
  * Method to test flush().
  *
  * @return void
  *
  * @covers Windwalker\DataMapper\AbstractDataMapper::flush
  */
 public function testFlush()
 {
     // Prepare test data
     $this->db->setQuery('UPDATE ww_flower SET catid = 3 WHERE id IN (6, 7, 8)')->execute();
     $dataset = array(array('title' => 'Baby\'s Breath2', 'catid' => 3), array('title' => 'Bachelor Button2', 'catid' => 3), array('title' => 'Begonia2', 'catid' => 3));
     // Delete all catid = 3 and re insert them.
     $returns = $this->instance->flush($dataset, array('catid' => 3));
     $newDataset = $this->loadToDataset('SELECT * FROM ww_flower WHERE catid = 3');
     $this->assertEquals(array('Baby\'s Breath2', 'Bachelor Button2', 'Begonia2'), $newDataset->title);
     $this->assertEquals(array(94, 95, 96), $returns->id);
 }
 /**
  * @covers Windwalker\DataMapper\AbstractDataMapper::updateAll
  * @todo   Implement testUpdateAll().
  */
 public function testFlush()
 {
     $mapper = new DataMapper('ww_content_tags');
     $dataset = new DataSet();
     $dataset[] = new Data(array('content_id' => 4, 'tag_id' => 1));
     $dataset[] = new Data(array('content_id' => 4, 'tag_id' => 2));
     $dataset[] = new Data(array('content_id' => 4, 'tag_id' => 4));
     $dataset[] = new Data(array('content_id' => 4, 'tag_id' => 5));
     $mapper->flush($dataset, array('content_id' => 4));
     $tagMaps = $mapper->find(array('content_id' => 4));
     $this->assertEquals(array(1, 2, 4, 5), ArrayHelper::getColumn((array) $tagMaps, 'tag_id'), 'Flush data wrong.');
 }
 /**
  * Flush records, will delete all by conditions then recreate new.
  *
  * @param mixed $dataset    Data set contain data we want to update.
  * @param mixed $conditions Where conditions, you can use array or Compare object.
  *                          Example:
  *                          - `array('id' => 5)` => id = 5
  *                          - `new GteCompare('id', 20)` => 'id >= 20'
  *                          - `new Compare('id', '%Flower%', 'LIKE')` => 'id LIKE "%Flower%"'
  *
  * @return  mixed|DataSet Updated data set.
  */
 public function flush($dataset, $conditions = array())
 {
     $this->observers->update('onBeforeFlush', array(&$dataset, &$conditions));
     $dataset = parent::flush($dataset, $conditions);
     $this->observers->update('onAfterFlush', array(&$dataset));
     return $dataset;
 }