Exemple #1
0
 /**
  * Run route loop
  */
 protected function runRouteLoop()
 {
     require_once __DIR__ . '/ElevationsRecalculator.php';
     $Recalculator = new ElevationsRecalculator(DB::getInstance());
     $Recalculator->run();
     $this->ElevationResults = $Recalculator->results();
     $this->addMessage(sprintf(__('Elevations have been recalculated for %d routes.'), count($this->ElevationResults)));
 }
 public function testSimpleRecalculations()
 {
     $id = (int) \SessionAccountHandler::getId();
     $this->PDO->exec('INSERT INTO `' . PREFIX . 'route` VALUES(' . $id . ', 1,   0,   0,  0, "100|200|150", "")');
     $this->PDO->exec('INSERT INTO `' . PREFIX . 'route` VALUES(' . $id . ', 2, 100, 100, 50, "100|200|150", "")');
     $this->PDO->exec('INSERT INTO `' . PREFIX . 'route` VALUES(' . $id . ', 3,   0,   0,  0, "", "150|200|100")');
     $this->PDO->exec('INSERT INTO `' . PREFIX . 'route` VALUES(' . $id . ', 4, 100,   0,  0, "", "")');
     $Job = new ElevationsRecalculator($this->PDO);
     $Job->run();
     $Fetch = $this->PDO->prepare('SELECT `elevation`, `elevation_up`, `elevation_down` FROM `' . PREFIX . 'route` WHERE `id`=:id');
     $Fetch->setFetchMode(PDO::FETCH_NUM);
     $this->assertEquals(2, $Job->numberOfRoutes());
     $Fetch->execute(array(':id' => 1));
     $this->assertEquals(array(100, 100, 50), $Fetch->fetch());
     $Fetch->execute(array(':id' => 2));
     $this->assertEquals(array(100, 100, 50), $Fetch->fetch());
     $Fetch->execute(array(':id' => 3));
     $this->assertEquals(array(100, 50, 100), $Fetch->fetch());
     $Fetch->execute(array(':id' => 4));
     $this->assertEquals(array(100, 0, 0), $Fetch->fetch());
     $this->assertEquals(array(1 => array(100, 100, 50), 2 => array(100, 100, 50), 3 => array(100, 50, 100)), $Job->results());
 }