/** * 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']); }
if (isPutMethod()) { $data = getPostData(); if (isset($data['tripId']) && $data['tripId'] !== '') { $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']);
} else { if (isPutMethod()) { $data = getPostData(); $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']);
/** * Extra test * Make sure that a long text is saved in the trip, one that has * at least more than 256 characters. * @depends testSaveEmptyObject * @depends testSetAttributes */ public function testLongText() { global $testTripId1; $longText = "This is a long text. This is a very long text. This is a ver, very long text. In fact, this text will just go on and on and on, for up to 400 characters. So when we set and retrieve this text, we will know for sure that the system supports these long texts. Of course, if this fails, we won't know any such thing for sure. Would that be to happen, we will have to go and spend some quality debugging time with the system."; $object = new Trip($testTripId1); $object->setDescription($longText); $this->assertTrue($object->save()); $object = new Trip($testTripId1); $this->assertEquals($longText, $object->getDescription()); }