Exemplo n.º 1
0
 protected function setUp()
 {
     $this->PDO = \DB::getInstance();
     $this->PDO->exec('DELETE FROM `runalyze_training`');
     $this->PDO->exec('DELETE FROM `runalyze_account` WHERE `username` = "LinkerOther"');
     $this->ThisAccountID = \SessionAccountHandler::getId();
     $this->PDO->exec('INSERT INTO `runalyze_account` (`username`, `name`, `mail`) VALUES ("LinkerOther", "LinkerOther", "*****@*****.**")');
     $this->OtherAccountID = $this->PDO->lastInsertId();
     $activities = [[0, $this->OtherAccountID], [1, $this->ThisAccountID], [2, $this->OtherAccountID], [3, $this->ThisAccountID], [3, $this->ThisAccountID], [4, $this->OtherAccountID], [5, $this->ThisAccountID], [6, $this->OtherAccountID]];
     foreach ($activities as $data) {
         $this->PDO->exec('INSERT INTO `runalyze_training` (`time`, `accountid`) VALUES (' . $data[0] . ', ' . $data[1] . ')');
         if ($data[1] == $this->ThisAccountID) {
             $this->ThisIDs[] = $this->PDO->lastInsertId();
         }
     }
 }
 /**
  * Test deletes
  */
 public function testDontDeleteTooMuch()
 {
     $_POST['delete_trainings'] = true;
     // Data of account 0
     $this->DB->exec('INSERT INTO `runalyze_equipment_type` (`accountid`,`name`) VALUES(0, "")');
     $FirstEquipmentType = $this->DB->lastInsertId();
     $this->DB->exec('INSERT INTO `runalyze_equipment` (`accountid`,`typeid`,`name`,`notes`) VALUES(0, ' . $FirstEquipmentType . ', "", "")');
     $FirstEquipment = $this->DB->lastInsertId();
     $this->DB->exec('INSERT INTO `runalyze_route` (`accountid`) VALUES(0)');
     $FirstRoute = $this->DB->lastInsertId();
     $this->DB->exec('INSERT INTO `runalyze_training` (`accountid`,`routeid`) VALUES(0, ' . $FirstRoute . ')');
     $FirstTraining = $this->DB->lastInsertId();
     $this->DB->exec('INSERT INTO `runalyze_trackdata` (`accountid`,`activityid`) VALUES(0, ' . $FirstTraining . ')');
     $this->DB->exec('INSERT INTO `runalyze_swimdata` (`accountid`,`activityid`) VALUES(0, ' . $FirstTraining . ')');
     $this->DB->exec('INSERT INTO `runalyze_hrv` (`accountid`,`activityid`) VALUES(0, ' . $FirstTraining . ')');
     $this->DB->exec('INSERT INTO `runalyze_activity_equipment` (`activityid`,`equipmentid`) VALUES(' . $FirstTraining . ', ' . $FirstEquipment . ')');
     // Data of account 1
     $this->DB->exec('INSERT INTO `runalyze_equipment_type` (`accountid`,`name`) VALUES(1, "")');
     $SecondEquipmentType = $this->DB->lastInsertId();
     $this->DB->exec('INSERT INTO `runalyze_equipment` (`accountid`,`typeid`,`name`,`notes`) VALUES(1, ' . $SecondEquipmentType . ', "", "")');
     $SecondEquipment = $this->DB->lastInsertId();
     $this->DB->exec('INSERT INTO `runalyze_route` (`accountid`) VALUES(1)');
     $SecondRoute = $this->DB->lastInsertId();
     $this->DB->exec('INSERT INTO `runalyze_training` (`accountid`,`routeid`) VALUES(1, ' . $SecondRoute . ')');
     $SecondTraining = $this->DB->lastInsertId();
     $this->DB->exec('INSERT INTO `runalyze_trackdata` (`accountid`,`activityid`) VALUES(1, ' . $SecondTraining . ')');
     $this->DB->exec('INSERT INTO `runalyze_swimdata` (`accountid`,`activityid`) VALUES(1, ' . $SecondTraining . ')');
     $this->DB->exec('INSERT INTO `runalyze_hrv` (`accountid`,`activityid`) VALUES(1, ' . $SecondTraining . ')');
     $this->DB->exec('INSERT INTO `runalyze_activity_equipment` (`activityid`,`equipmentid`) VALUES(' . $SecondTraining . ', ' . $SecondEquipment . ')');
     $Importer = new RunalyzeJsonImporter('../tests/testfiles/backup/default-empty.json.gz', 0);
     $Importer->importData();
     $this->assertEquals(0, $this->DB->query('SELECT COUNT(*) FROM `runalyze_route` WHERE `accountid`=0')->fetchColumn());
     $this->assertEquals(0, $this->DB->query('SELECT COUNT(*) FROM `runalyze_training` WHERE `accountid`=0')->fetchColumn());
     $this->assertEquals(0, $this->DB->query('SELECT COUNT(*) FROM `runalyze_trackdata` WHERE `accountid`=0')->fetchColumn());
     $this->assertEquals(0, $this->DB->query('SELECT COUNT(*) FROM `runalyze_swimdata` WHERE `accountid`=0')->fetchColumn());
     $this->assertEquals(0, $this->DB->query('SELECT COUNT(*) FROM `runalyze_hrv` WHERE `accountid`=0')->fetchColumn());
     $this->assertEquals(0, $this->DB->query('SELECT COUNT(*) FROM `runalyze_activity_equipment` WHERE `equipmentid`=' . $FirstEquipment)->fetchColumn());
     $this->assertEquals(1, $this->DB->query('SELECT COUNT(*) FROM `runalyze_route` WHERE `accountid`=1')->fetchColumn());
     $this->assertEquals(1, $this->DB->query('SELECT COUNT(*) FROM `runalyze_training` WHERE `accountid`=1')->fetchColumn());
     $this->assertEquals(1, $this->DB->query('SELECT COUNT(*) FROM `runalyze_trackdata` WHERE `accountid`=1')->fetchColumn());
     $this->assertEquals(1, $this->DB->query('SELECT COUNT(*) FROM `runalyze_swimdata` WHERE `accountid`=1')->fetchColumn());
     $this->assertEquals(1, $this->DB->query('SELECT COUNT(*) FROM `runalyze_hrv` WHERE `accountid`=1')->fetchColumn());
     $this->assertEquals(1, $this->DB->query('SELECT COUNT(*) FROM `runalyze_activity_equipment` WHERE `equipmentid`=' . $SecondEquipment)->fetchColumn());
 }
 /**
  * Test with existing equipment
  */
 public function testWithExistingEquipment()
 {
     $this->DB->exec('INSERT INTO `runalyze_sport` (`name`, `accountid`) VALUES("Sport A", ' . $this->AccountID . ')');
     $ExistingSportA = $this->DB->lastInsertId();
     $this->DB->exec('INSERT INTO `runalyze_equipment_type` (`name`, `accountid`) VALUES("Typ A", ' . $this->AccountID . ')');
     $ExistingTypeA = $this->DB->lastInsertId();
     $this->DB->exec('INSERT INTO `runalyze_equipment_type` (`name`, `accountid`) VALUES("Typ AB", ' . $this->AccountID . ')');
     $ExistingTypeAB = $this->DB->lastInsertId();
     $this->DB->exec('INSERT INTO `runalyze_equipment_sport` (`sportid`, `equipment_typeid`) VALUES(' . $ExistingSportA . ', ' . $ExistingTypeA . ')');
     $Importer = new RunalyzeJsonImporter('../tests/testfiles/backup/with-equipment.json.gz', $this->AccountID);
     $Importer->importData();
     $SportA = $this->DB->query('SELECT `id` FROM `runalyze_sport` WHERE `name`="Sport A"')->fetchColumn();
     $SportB = $this->DB->query('SELECT `id` FROM `runalyze_sport` WHERE `name`="Sport B"')->fetchColumn();
     $this->assertEquals($ExistingSportA, $SportA);
     $TypeA = $this->DB->query('SELECT `id` FROM `runalyze_equipment_type` WHERE `name`="Typ A"')->fetchColumn();
     $TypeAB = $this->DB->query('SELECT `id` FROM `runalyze_equipment_type` WHERE `name`="Typ AB"')->fetchColumn();
     $this->assertEquals($ExistingTypeA, $TypeA);
     $this->assertEquals($ExistingTypeAB, $TypeAB);
     $this->assertEquals(array(array($SportA, $TypeA), array($SportA, $TypeAB), array($SportB, $TypeAB)), $this->DB->query('SELECT `sportid`, `equipment_typeid` FROM `runalyze_equipment_sport`')->fetchAll(PDO::FETCH_NUM));
 }
Exemplo n.º 4
0
 /**
  * Insert
  * @param array $Values
  * @return int last inserted ID
  */
 public function insert(array $Values)
 {
     $this->Statement->execute($Values);
     return $this->DB->lastInsertId();
 }