private function updateSensor() { $sensor = $_SESSION['sensor']; if (empty($sensor)) { HomeView::show(); header('Location: /' . $_SESSION['base']); } elseif ($_SERVER['REQUEST_METHOD'] == 'GET') { SensorView::showUpdate(); } else { $params = $sensor->getParameters(); $params['sensor_name'] = array_key_exists('sensor_name', $_POST) ? $_POST['sensor_name'] : ''; $params['description'] = array_key_exists('description', $_POST) ? $_POST['description'] : ''; $updatedSensor = new Sensor($params); $updatedSensor->setSensorId($sensor->getSensorId()); $returnedSensor = SensorsDB::updateSensor($updatedSensor); if ($returnedSensor->getErrorCount() == 0) { // Show the Sensor View which should display the updated params SensorView::show(); header('Location: /' . $_SESSION['base'] . '/sensor/show/' . $sensor->getSensorId()); } else { // Carry over the measurements, if any $updatedSensor->setMeasurements($sensor->getMeasurements()); $_SESSION['sensor'] = $updatedSensor; SensorView::showUpdate(); } } }
public function testUpdateSequenceType() { $myDb = DBMaker::create('sensordatarepotest'); Database::clearDB(); $db = Database::getDB('sensordatarepotest', 'C:\\xampp\\myConfig.ini'); $testSensorId = 2; $sensors = SensorsDB::getSensorsBy('sensor_id', $testSensorId); $sensor = $sensors[0]; $this->assertEquals($sensor->getSequenceType(), 'SEQUENTIAL', 'Before the update, it should have sequence type SEQUENTIAL'); $params = $sensor->getParameters(); $params['sequence_type'] = 'TIME-CODED'; $newSensor = new Sensor($params); $newSensor->setSensorId($testSensorId); $returnedSensor = SensorsDB::updateSensor($newSensor); $this->assertEquals($returnedSensor->getSequenceType(), $params['sequence_type'], 'After the update it should have sequence_type ' . $params['sequence_type']); $this->assertTrue(empty($returnedSensor->getErrors()), 'The updated sensor should be error-free'); }