public function testSimpleUpdate() { $Inserter = new Inserter($this->PDO); $Inserter->setAccountID(1); $Inserter->insert(new Object(array(Object::NAME => 'Sport name', Object::CALORIES_PER_HOUR => 700))); $Sport = new Object($this->PDO->query('SELECT * FROM `' . PREFIX . 'sport` WHERE `id`=' . $Inserter->insertedID())->fetch(PDO::FETCH_ASSOC)); $Sport->set(Object::CALORIES_PER_HOUR, 0); $Changed = clone $Sport; $Changed->set(Object::NAME, 'New sport name'); $Updater = new Updater($this->PDO, $Changed, $Sport); $Updater->setAccountID(1); $Updater->update(); $Result = new Object($this->PDO->query('SELECT * FROM `' . PREFIX . 'sport` WHERE `id`=' . $Inserter->insertedID())->fetch(PDO::FETCH_ASSOC)); $this->assertEquals('New sport name', $Result->name()); $this->assertEquals(700, $Result->caloriesPerHour()); }
public function testSimpleInsert() { $Object = new Object(array(Object::NAME => 'Sport name', Object::SHORT => 0, Object::CALORIES_PER_HOUR => 700, Object::HR_AVG => 140, Object::HAS_DISTANCES => 1, Object::PACE_UNIT => 'foo', Object::HAS_POWER => 0, Object::IS_OUTSIDE => 1)); $Inserter = new Inserter($this->PDO, $Object); $Inserter->setAccountID(1); $Inserter->insert(); $data = $this->PDO->query('SELECT * FROM `' . PREFIX . 'sport` WHERE `accountid`=1')->fetch(PDO::FETCH_ASSOC); $Sport = new Object($data); $this->assertEquals('Sport name', $Sport->name()); $this->assertEquals(700, $Sport->caloriesPerHour()); $this->assertEquals(140, $Sport->avgHR()); $this->assertEquals('foo', $Sport->paceUnitEnum()); $this->assertTrue($Sport->hasDistances()); $this->assertTrue($Sport->isOutside()); $this->assertFalse($Sport->usesShortDisplay()); $this->assertFalse($Sport->hasPower()); }