Example #1
0
 /**
   Create, update, and delete a batch
   Try each mode with and without an owner filter
 */
 public function unitTest($phpunit)
 {
     $get = $this->get_view();
     $phpunit->assertNotEquals(0, strlen($get));
     $this->connection->selectDB($this->config->get('OP_DB'));
     $model = new BatchesModel($this->connection);
     $this->newType = 1;
     $this->newName = 'Test BatchListPage';
     $this->newStart = date('Y-m-d 00:00:00');
     $this->newEnd = date('Y-m-d 00:00:00');
     $this->newOwner = 'IT';
     ob_start();
     $this->post_newType_newName_newStart_newEnd_newOwner_handler();
     ob_end_clean();
     $model->batchName($this->newName);
     $matches = $model->find();
     $phpunit->assertEquals(1, count($matches));
     $model->reset();
     $model->batchID($matches[0]->batchID());
     $phpunit->assertEquals(true, $model->load());
     $phpunit->assertEquals($this->newType, $model->batchType());
     $phpunit->assertEquals($this->newName, $model->batchName());
     $phpunit->assertEquals($this->newStart, $model->startDate());
     $phpunit->assertEquals($this->newEnd, $model->endDate());
     $phpunit->assertEquals($this->newOwner, $model->owner());
     $this->id = $model->batchID();
     $this->batchName = 'Change BatchListPage';
     $this->batchType = 2;
     $this->startDate = date('Y-m-d 00:00:00', strtotime('yesterday'));
     $this->endDate = $this->startDate;
     $this->owner = 'Admin';
     ob_start();
     $this->post_id_batchName_batchType_startDate_endDate_owner_handler();
     ob_end_clean();
     $model->reset();
     $model->batchID($this->id);
     $phpunit->assertEquals(true, $model->load());
     $phpunit->assertEquals($this->batchType, $model->batchType());
     $phpunit->assertEquals($this->batchName, $model->batchName());
     $phpunit->assertEquals($this->startDate, $model->startDate());
     $phpunit->assertEquals($this->endDate, $model->endDate());
     $phpunit->assertEquals($this->owner, $model->owner());
     $this->delete = 1;
     ob_start();
     $this->post_delete_id_handler();
     ob_end_clean();
     $model->reset();
     $model->batchID($this->id);
     $phpunit->assertEquals(false, $model->load());
     $modes = array('pending', 'current', 'historical', 'all');
     foreach ($modes as $m) {
         $get = $this->batchListDisplay('', $m, rand(0, 50));
         $phpunit->assertNotEquals(0, strlen($get));
         $get = $this->batchListDisplay('IT', $m, rand(0, 50));
         $phpunit->assertNotEquals(0, strlen($get));
     }
 }
Example #2
0
 protected function hookAddColumnowner()
 {
     // copy existing values from batchowner.owner to
     // new batches.owner column
     if ($this->connection->table_exists('batchowner')) {
         $dataR = $this->connection->query('SELECT batchID, owner FROM batchowner');
         $tempModel = new BatchesModel($this->connection);
         while ($dataW = $this->connection->fetch_row($dataR)) {
             $tempModel->reset();
             $tempModel->batchID($dataW['batchID']);
             if ($tempModel->load()) {
                 $tempModel->owner($dataW['owner']);
                 $tempModel->save();
             }
         }
     }
 }