/** * 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()); }
/** * @covers PDOforRunalyze::insert * @covers PDOforRunalyze::update * @covers PDOforRunalyze::updateWhere * @covers PDOforRunalyze::exec */ public function testUpdate() { $this->object->insert('training', array('id', 's', 'distance'), array(1, 600, 1)); $this->object->insert('training', array('id', 's', 'distance'), array(2, 900, 1)); $this->object->insert('training', array('id', 's', 'distance'), array(3, 300, 1)); $this->object->update('training', 1, 'distance', 2); $this->assertEquals(array(600, 2), $this->object->query('SELECT `s`, `distance` FROM `runalyze_training` WHERE `id`=1 LIMIT 1')->fetch(PDO::FETCH_NUM)); $this->object->update('training', 2, 'distance', 3); $this->assertEquals(array(900, 3), $this->object->query('SELECT `s`, `distance` FROM `runalyze_training` WHERE `id`=2 LIMIT 1')->fetch(PDO::FETCH_NUM)); $this->object->update('training', 3, array('s', 'distance'), array(150, 0.5)); $this->assertEquals(array(150, 0.5), $this->object->query('SELECT `s`, `distance` FROM `runalyze_training` WHERE `id`=3 LIMIT 1')->fetch(PDO::FETCH_NUM)); $this->object->updateWhere('training', '`distance` > 1', 'comment', 'Super weit.'); $this->assertEquals("1,2", $this->object->query('SELECT GROUP_CONCAT(`id`) FROM `runalyze_training` WHERE `comment`="Super weit." GROUP BY `accountid`')->fetchColumn()); $this->assertEquals(3, $this->object->exec('DELETE FROM `runalyze_training`')); $this->assertEquals(0, $this->object->query('SELECT COUNT(*) FROM `runalyze_training`')->fetchColumn()); $this->object->exec('TRUNCATE TABLE `runalyze_training`'); }
protected function setUp() { $this->DB = \DB::getInstance(); $this->DB->exec('TRUNCATE TABLE `runalyze_training`'); $Date = new \DateTime('today 15:30'); $this->DB->insert('training', array('time', 'trimp', 'sportid'), array($Date->getTimestamp(), 100, 1)); $Date->modify('-1 day 10:00'); $this->DB->insert('training', array('time', 'trimp', 'sportid'), array($Date->getTimestamp(), 30, 1)); $Date->modify('-0 day 16:30'); $this->DB->insert('training', array('time', 'trimp', 'sportid'), array($Date->getTimestamp(), 20, 2)); $Date->modify('-2 days 07:00'); $this->DB->insert('training', array('time', 'trimp', 'sportid'), array($Date->getTimestamp(), 70, 2)); $Date->modify('-7 days 19:00'); $this->DB->insert('training', array('time', 'trimp', 'sportid'), array($Date->getTimestamp(), 150, 1)); }
private function fillDummyUser() { $this->DB->insert('user', array('time', 'weight'), array(time() - DAY_IN_S, 72)); $this->DB->insert('user', array('time', 'weight'), array(time(), 70)); return 2; }