Ejemplo n.º 1
0
 /**
  * Method to test update().
  *
  * @return void
  *
  * @covers Windwalker\DataMapper\AbstractDataMapper::update
  */
 public function testUpdate()
 {
     // Update from array
     $dataset = array(array('id' => 1, 'state' => 1), array('id' => 2, 'state' => 1), array('id' => 3, 'state' => 1));
     $returns = $this->instance->update($dataset, 'id');
     $updateDataset = $this->loadToDataset('SELECT * FROM ww_flower LIMIT 3');
     $this->assertEquals(array(1, 1, 1), $updateDataset->state);
     $this->assertInstanceOf('Windwalker\\Data\\Data', $returns[0], 'Return not Data object.');
     // Use from DataSet
     $dataset = new DataSet(array(new Data(array('id' => 1, 'state' => 0)), new Data(array('id' => 2, 'state' => 0)), new Data(array('id' => 3, 'state' => 0))));
     $returns = $this->instance->update($dataset, 'id');
     $updateDataset = $this->loadToDataset('SELECT * FROM ww_flower LIMIT 3');
     $this->assertEquals(array(0, 0, 0), $updateDataset->state);
     $this->assertInstanceOf('Windwalker\\Data\\Data', $returns[0], 'Return not Data object.');
     // TODO: Test Update Nulls
 }
 /**
  * Update records by data set. Every data depend on this table's primary key to update itself.
  *
  * @param mixed $dataset      Data set contain data we want to update.
  * @param array $condFields   The where condition tell us record exists or not, if not set,
  *                            will use primary key instead.
  * @param bool  $updateNulls  Update empty fields or not.
  *
  * @return mixed|DataSet
  */
 public function update($dataset, $condFields = null, $updateNulls = false)
 {
     $this->observers->update('onBeforeUpdate', array(&$dataset, &$condFields, &$updateNulls));
     $dataset = parent::update($dataset, $condFields, $updateNulls);
     $this->observers->update('onAfterUpdate', array(&$dataset));
     return $dataset;
 }