/** * Test #11. SYNCH get an existent object. * @depends testDataWipedBeforeTest * @depends testGetExistent */ public function testSynchGet() { global $testTripId1; global $synchAuthToken; $object = new Trip($testTripId1); $object->setName("Trip 1"); $object->setDescription("Description 1"); $object->setBannerImg("test-01.png"); $object->setStartDate("2015-09-01"); $object->setEndDate("2015-09-30"); $object->setActive("Y"); $object->setDeleted('Y'); $object->save(); $hash = $object->getHash(); $data = array('hash' => $hash); $result = getApi('synchTrip.php', $data, $synchAuthToken); $this->assertEquals(RESPONSE_SUCCESS, $result['resultCode']); $this->assertTrue(isset($result['tripId'])); $this->assertTrue(isset($result['created'])); $this->assertTrue(isset($result['updated'])); $this->assertTrue(isset($result['name'])); $this->assertTrue(isset($result['description'])); $this->assertTrue(isset($result['bannerImg'])); $this->assertTrue(isset($result['startDate'])); $this->assertTrue(isset($result['endDate'])); $this->assertTrue(isset($result['active'])); $this->assertTrue(isset($result['deleted'])); $this->assertTrue(isset($result['hash'])); $this->assertEquals($testTripId1, $result['tripId']); $this->assertEquals($object->getCreated(), $result['created']); $this->assertEquals($object->getUpdated(), $result['updated']); $this->assertEquals("Trip 1", $result['name']); $this->assertEquals("Description 1", $result['description']); $this->assertEquals("test-01.png", $result['bannerImg']); $this->assertEquals("2015-09-01", $result['startDate']); $this->assertEquals("2015-09-30", $result['endDate']); $this->assertEquals("Y", $result['active']); $this->assertEquals('Y', $result['deleted']); $this->assertEquals($hash, $result['hash']); }
$tripId = $data['tripId']; $trip = new Trip($tripId); if (isset($data['created'])) { $trip->setCreated($data['created']); } if (isset($data['updated'])) { $trip->setUpdated($data['updated']); } if (isset($data['name'])) { $trip->setName($data['name']); } if (isset($data['description'])) { $trip->setDescription($data['description']); } if (isset($data['bannerImg'])) { $trip->setBannerImg($data['bannerImg']); } if (isset($data['startDate'])) { $trip->setStartDate($data['startDate']); } if (isset($data['endDate'])) { $trip->setEndDate($data['endDate']); } if (isset($data['active'])) { $trip->setActive($data['active']); } if (isset($data['deleted'])) { $trip->setDeleted($data['deleted']); } if (isset($data['hash'])) { $trip->setHash($data['hash']);
$tripId = ''; if (isset($data['tripId'])) { $tripId = $data['tripId']; } if ($tripId === '') { $response = errorResponse(RESPONSE_BAD_REQUEST); } else { $object = new Trip($tripId); if (isset($data['name'])) { $object->setName($data['name']); } if (isset($data['description'])) { $object->setDescription($data['description']); } if (isset($data['bannerImg'])) { $object->setBannerImg($data['bannerImg']); } if (isset($data['startDate'])) { $object->setStartDate($data['startDate']); } if (isset($data['endDate'])) { $object->setEndDate($data['endDate']); } if (isset($data['active'])) { $object->setActive($data['active']); } if (isset($data['deleted'])) { $object->setDeleted($data['deleted']); } if ($object->save()) { $response = successResponse();
/** * Test #17. * The findByHash function returns an object populated with previous * values if a hash for a previous instance is given. * @depends testUpdate * @depends testHashGetInstance */ public function testHashOldInstance() { global $testTripId1; // create the object and save it $object = new Trip($testTripId1); $object->setName('Test Trip'); $object->setDescription('Test Description'); $object->setBannerImg('test-01.png'); $object->setStartDate('2015-08-01'); $object->setEndDate('2015-09-30'); $object->setActive('Y'); $object->setDeleted('Y'); $this->assertTrue($object->save()); $this->assertEquals(1, $this->countTestRows()); $old_hash = $object->getHash(); // change values and update the object $object->setName('Test Trip 2'); $object->setDescription('Test Description 2'); $object->setBannerImg('test-02.png'); $object->setStartDate('2014-08-01'); $object->setEndDate('2014-09-30'); $object->setActive('N'); $object->setDeleted('N'); $this->assertTrue($object->save()); $this->assertEquals(2, $this->countTestRows()); $new_hash = $object->getHash(); // read the object from the database and confirm that the old // values are returned $object = Trip::findByHash($old_hash); $this->assertNotNull($object); $this->assertEquals($testTripId1, $object->getTripId()); $this->assertEquals('Test Trip', $object->getName()); $this->assertEquals('Test Description', $object->getDescription()); $this->assertEquals('test-01.png', $object->getBannerImg()); $this->assertEquals('2015-08-01', $object->getStartDate()); $this->assertEquals('2015-09-30', $object->getEndDate()); $this->assertEquals('Y', $object->getActive()); $this->assertEquals('Y', $object->getDeleted()); $this->assertEquals($old_hash, $object->getHash()); // read the new object from the database and confirm that the new // values are returned $object = Trip::findByHash($new_hash); $this->assertNotNull($object); $this->assertEquals($testTripId1, $object->getTripId()); $this->assertEquals('Test Trip 2', $object->getName()); $this->assertEquals('Test Description 2', $object->getDescription()); $this->assertEquals('test-02.png', $object->getBannerImg()); $this->assertEquals('2014-08-01', $object->getStartDate()); $this->assertEquals('2014-09-30', $object->getEndDate()); $this->assertEquals('N', $object->getActive()); $this->assertEquals('N', $object->getDeleted()); $this->assertEquals($new_hash, $object->getHash()); }