/** * Display form: import finished */ protected function displayImportFinish() { require_once __DIR__ . '/class.RunalyzeBulkInsert.php'; require_once __DIR__ . '/class.RunalyzeJsonImporterResults.php'; require_once __DIR__ . '/class.RunalyzeJsonImporter.php'; $fileName = '../data/DbBackup/import/' . $_POST['file']; $Importer = new RunalyzeJsonImporter($fileName); $Importer->importData(); Filesystem::deleteFile($fileName); Ajax::setReloadFlag(Ajax::$RELOAD_ALL); $Fieldset = new FormularFieldset(__('Import data')); $Fieldset->addText(__('All data have been imported.')); $Fieldset->addText(__('It is recommended to use the <em>Database cleanup</em> tool.')); $Fieldset->addInfo($Importer->resultsAsString()); $Fieldset->addBlock(Ajax::getReloadCommand()); $Formular = new Formular(); $Formular->setId('import-finished'); $Formular->addFieldset($Fieldset); $Formular->display(); }
/** * Test inserts */ public function testInserts() { $TestClothes = $this->DB->insert('runalyze_clothes', array('name'), array('Test-Clothes')); $TestSport = $this->DB->insert('runalyze_sport', array('name'), array('Testsport')); $TestType = $this->DB->insert('runalyze_type', array('name', 'sportid'), array('Testtype', $TestSport)); // Act $Importer = new RunalyzeJsonImporter('../tests/testfiles/backup/default-insert.json.gz'); $Importer->importData(); // Check nothing changed $this->assertEquals($TestClothes, $this->DB->query('SELECT `id` FROM `runalyze_clothes` WHERE `name`="Test-Clothes"')->fetchColumn()); $this->assertEquals($TestSport, $this->DB->query('SELECT `id` FROM `runalyze_sport` WHERE `name`="Testsport"')->fetchColumn()); $this->assertEquals($TestType, $this->DB->query('SELECT `id` FROM `runalyze_type` WHERE `name`="Testtype"')->fetchColumn()); // Check existing/new $NewClothes = $this->DB->query('SELECT `id` FROM `runalyze_clothes` WHERE `name`="New-Clothes"')->fetchColumn(); $NewSport = $this->DB->query('SELECT `id` FROM `runalyze_sport` WHERE `name`="Newsport"')->fetchColumn(); $NewType = $this->DB->query('SELECT `id` FROM `runalyze_type` WHERE `name`="Newtype"')->fetchColumn(); $NewShoe = $this->DB->query('SELECT `id` FROM `runalyze_shoe` WHERE `name`="Testshoe"')->fetchColumn(); $this->assertNotEquals(0, $NewClothes); $this->assertNotEquals(0, $NewSport); $this->assertNotEquals(0, $NewType); $this->assertNotEquals(0, $NewShoe); // Check inserts $this->assertEquals(array('time' => '1234567890', 'weight' => '70', 'pulse_rest' => '45', 'pulse_max' => '205'), $this->DB->query('SELECT `time`, `weight`, `pulse_rest`, `pulse_max` FROM `runalyze_user` WHERE `time`="1234567890" LIMIT 1')->fetch()); $this->assertEquals(array('time' => '1234567890', 'sportid' => $TestSport, 'typeid' => $TestType, 's' => '900.00', 'clothes' => $TestClothes . ',' . $NewClothes, 'shoeid' => '0'), $this->DB->query('SELECT `time`, `sportid`, `typeid`, `s`, `clothes`, `shoeid` FROM `runalyze_training` WHERE `comment`="UNITTEST-1" LIMIT 1')->fetch()); $this->assertEquals(array('time' => '1234567890', 'sportid' => $NewSport, 'typeid' => $NewType, 's' => '1500.00', 'clothes' => $NewClothes, 'shoeid' => $NewShoe), $this->DB->query('SELECT `time`, `sportid`, `typeid`, `s`, `clothes`, `shoeid` FROM `runalyze_training` WHERE `comment`="UNITTEST-2" LIMIT 1')->fetch()); }
/** * 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)); }