/** * @covers PDOforRunalyze::prepare */ public function testPrepare() { $Insert = $this->object->prepare('INSERT INTO `runalyze_training` (`id`, `s`, `distance`, `accountid`) VALUES (:id, :s, :distance, 0)'); $Insert->bindValue('id', 1); $Insert->bindValue('s', 300); $Insert->bindValue('distance', 1); $Insert->execute(); $Insert->bindValue('id', 2); $Insert->bindValue('s', 610); $Insert->bindValue('distance', 2.1); $Insert->execute(); $Insert->bindValue('id', 3); $Insert->bindValue('s', 3111); $Insert->bindValue('distance', 11.23); $Insert->execute(); $id = 0; $RequestDistance = $this->object->prepare('SELECT `distance` FROM `runalyze_training` WHERE `id`=:id'); $RequestDistance->bindParam('id', $id); $id = 1; $RequestDistance->execute(); $this->assertEquals(1, $RequestDistance->fetchColumn()); $id = 2; $RequestDistance->execute(); $this->assertEquals(2.1, $RequestDistance->fetchColumn()); $id = 3; $RequestDistance->execute(); $this->assertEquals(11.23, $RequestDistance->fetchColumn()); $this->object->exec('TRUNCATE TABLE `runalyze_training`'); }
/** * 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)); }
protected function tearDown() { $this->PDO->exec('DELETE FROM `runalyze_training`'); }
public function testEquipment() { $this->DB->exec('INSERT INTO `runalyze_sport` (`id`, `name`, `accountid`) VALUES(1, "Sport A", ' . $this->accountID . ')'); $this->DB->exec('INSERT INTO `runalyze_sport` (`id`, `name`, `accountid`) VALUES(2, "Sport B", ' . $this->accountID . ')'); $this->DB->exec('INSERT INTO `runalyze_sport` (`id`, `name`, `accountid`) VALUES(3, "Sport C", ' . $this->accountID . ')'); $this->DB->exec('INSERT INTO `runalyze_equipment_type` (`id`, `name`, `accountid`) VALUES(1, "Equipment Type AB", ' . $this->accountID . ')'); $this->DB->exec('INSERT INTO `runalyze_equipment_type` (`id`, `name`, `accountid`) VALUES(2, "Equipment Type C", ' . $this->accountID . ')'); $this->DB->exec('INSERT INTO `runalyze_equipment_sport` (`sportid`, `equipment_typeid`) VALUES(1, 1)'); $this->DB->exec('INSERT INTO `runalyze_equipment_sport` (`sportid`, `equipment_typeid`) VALUES(2, 1)'); $this->DB->exec('INSERT INTO `runalyze_equipment_sport` (`sportid`, `equipment_typeid`) VALUES(3, 2)'); $this->DB->exec('INSERT INTO `runalyze_equipment` (`id`, `name`, `typeid`, `notes`, `accountid`) VALUES(1, "Equipment A1", 1, "", ' . $this->accountID . ')'); $this->DB->exec('INSERT INTO `runalyze_equipment` (`id`, `name`, `typeid`, `notes`, `accountid`) VALUES(2, "Equipment A2", 1, "", ' . $this->accountID . ')'); $this->DB->exec('INSERT INTO `runalyze_equipment` (`id`, `name`, `typeid`, `notes`, `accountid`) VALUES(3, "Equipment B", 1, "", ' . $this->accountID . ')'); $this->DB->exec('INSERT INTO `runalyze_equipment` (`id`, `name`, `typeid`, `notes`, `accountid`) VALUES(4, "Equipment C", 2, "", ' . $this->accountID . ')'); $this->DB->exec('INSERT INTO `runalyze_training` (`id`, `sportid`, `accountid`) VALUES(1, 1, ' . $this->accountID . ')'); $this->DB->exec('INSERT INTO `runalyze_training` (`id`, `sportid`, `accountid`) VALUES(2, 2, ' . $this->accountID . ')'); $this->DB->exec('INSERT INTO `runalyze_training` (`id`, `sportid`, `accountid`) VALUES(3, 3, ' . $this->accountID . ')'); $this->DB->exec('INSERT INTO `runalyze_activity_equipment` (`activityid`, `equipmentid`) VALUES(1, 1)'); $this->DB->exec('INSERT INTO `runalyze_activity_equipment` (`activityid`, `equipmentid`) VALUES(1, 2)'); $this->DB->exec('INSERT INTO `runalyze_activity_equipment` (`activityid`, `equipmentid`) VALUES(2, 3)'); $this->DB->exec('INSERT INTO `runalyze_activity_equipment` (`activityid`, `equipmentid`) VALUES(3, 4)'); $this->assertEquals(array(1, 2), $this->object->sportForEquipmentType(1, true)); $this->assertEquals(array($this->object->sport(1), $this->object->sport(2)), $this->object->sportForEquipmentType(1)); $this->assertEquals(array(3), $this->object->sportForEquipmentType(2, true)); $this->assertEquals(array($this->object->sport(3)), $this->object->sportForEquipmentType(2)); $this->assertEquals(array(1, 2), $this->object->equipmentForActivity(1, true)); $this->assertEquals(array($this->object->equipment(1), $this->object->equipment(2)), $this->object->equipmentForActivity(1)); $this->assertEquals(array(3), $this->object->equipmentForActivity(2, true)); $this->assertEquals(array($this->object->equipment(3)), $this->object->equipmentForActivity(2)); $this->assertEquals(array(4), $this->object->equipmentForActivity(3, true)); $this->assertEquals(array($this->object->equipment(4)), $this->object->equipmentForActivity(3)); $this->assertEquals(array(), $this->object->allTypes()); $this->assertEquals(array($this->object->sport(1), $this->object->sport(2), $this->object->sport(3)), $this->object->allSports()); $this->assertEquals(array($this->object->equipmentType(1), $this->object->equipmentType(2)), $this->object->allEquipmentTypes()); $this->assertEquals(array($this->object->equipment(1), $this->object->equipment(2), $this->object->equipment(3), $this->object->equipment(4)), $this->object->allEquipments()); }
protected function tearDown() { $this->DB->exec('TRUNCATE TABLE `runalyze_training`'); }
private function truncateTables() { $this->DB->exec('TRUNCATE TABLE `runalyze_training`'); $this->DB->exec('TRUNCATE TABLE `runalyze_user`'); $this->DB->exec('TRUNCATE TABLE `runalyze_shoe`'); $this->DB->exec('DELETE FROM `runalyze_conf` WHERE `key`="TEST_CONF"'); $this->DB->exec('DELETE FROM `runalyze_dataset` WHERE `name`="test-dataset"'); $this->DB->exec('DELETE FROM `runalyze_plugin` WHERE `key`="RunalyzePluginTool_TEST"'); $this->DB->exec('DELETE FROM `runalyze_plugin_conf` WHERE `config`="test_one"'); $this->DB->exec('DELETE FROM `runalyze_plugin_conf` WHERE `config`="test_two"'); $this->DB->exec('DELETE FROM `runalyze_clothes` WHERE `name`="Test-Clothes"'); $this->DB->exec('DELETE FROM `runalyze_clothes` WHERE `name`="New-Clothes"'); $this->DB->exec('DELETE FROM `runalyze_sport` WHERE `name`="Testsport"'); $this->DB->exec('DELETE FROM `runalyze_sport` WHERE `name`="Newsport"'); $this->DB->exec('DELETE FROM `runalyze_type` WHERE `name`="Testtype"'); $this->DB->exec('DELETE FROM `runalyze_type` WHERE `name`="Newtype"'); }