/** * Extra text. Make sure the get operation works with a "latest" * value. */ function testGetLatest() { global $testTripId1, $testTripId2; // use the timezone where we do our testing :-) date_default_timezone_set("America/New_York"); $now = time(); $today = date('Y-m-d', $now); $yesterday = date('Y-m-d', $now - 24 * 60 * 60); $tomorrow = date('Y-m-d', $now + 24 * 60 * 60); $past = date('Y-m-d', $now - 5 * (24 * 60 * 60)); $future = date('Y-m-d', $now + 5 * (24 * 60 * 60)); $farPast = date('Y-m-d', $now - 10 * (24 * 60 * 60)); $farFuture = date('Y-m-d', $now + 10 * (24 * 60 * 60)); $testTrip1 = new Trip($testTripId1); $testTrip2 = new Trip($testTripId2); $data = array('current' => ''); // one past and one future trip $testTrip1->setStartDate($past); $testTrip1->setEndDate($yesterday); $this->assertTrue($testTrip1->save()); $testTrip2->setStartDate($tomorrow); $testTrip2->setEndDate($future); $this->assertTrue($testTrip2->save()); $result = getApi('getTrip.php', $data); $this->assertEquals(RESPONSE_SUCCESS, $result['resultCode']); $this->assertTrue(isset($result['tripId'])); $this->assertEquals($testTripId1, $result['tripId']); // one past and one current trip $testTrip1->setStartDate($past); $testTrip1->setEndDate($yesterday); $this->assertTrue($testTrip1->save()); $testTrip2->setStartDate($yesterday); $testTrip2->setEndDate($tomorrow); $this->assertTrue($testTrip2->save()); $result = getApi('getTrip.php', $data); $this->assertEquals(RESPONSE_SUCCESS, $result['resultCode']); $this->assertTrue(isset($result['tripId'])); $this->assertEquals($testTripId2, $result['tripId']); // two past trips $testTrip1->setStartDate($past); $testTrip1->setEndDate($yesterday); $this->assertTrue($testTrip1->save()); $testTrip2->setStartDate($farPast); $testTrip2->setEndDate($past); $this->assertTrue($testTrip2->save()); $result = getApi('getTrip.php', $data); $this->assertEquals(RESPONSE_SUCCESS, $result['resultCode']); $this->assertTrue(isset($result['tripId'])); $this->assertEquals($testTripId1, $result['tripId']); // one current and one future trip $testTrip1->setStartDate($yesterday); $testTrip1->setEndDate($tomorrow); $this->assertTrue($testTrip1->save()); $testTrip2->setStartDate($tomorrow); $testTrip2->setEndDate($future); $this->assertTrue($testTrip2->save()); $result = getApi('getTrip.php', $data); $this->assertEquals(RESPONSE_SUCCESS, $result['resultCode']); $this->assertTrue(isset($result['tripId'])); $this->assertEquals($testTripId1, $result['tripId']); // two current trips, nested $testTrip1->setStartDate($yesterday); $testTrip1->setEndDate($tomorrow); $this->assertTrue($testTrip1->save()); $testTrip2->setStartDate($past); $testTrip2->setEndDate($future); $this->assertTrue($testTrip2->save()); $result = getApi('getTrip.php', $data); $this->assertEquals(RESPONSE_SUCCESS, $result['resultCode']); $this->assertTrue(isset($result['tripId'])); $this->assertEquals($testTripId1, $result['tripId']); // two current trips, staggered $testTrip1->setStartDate($past); $testTrip1->setEndDate($tomorrow); $this->assertTrue($testTrip1->save()); $testTrip2->setStartDate($yesterday); $testTrip2->setEndDate($future); $this->assertTrue($testTrip2->save()); $result = getApi('getTrip.php', $data); $this->assertEquals(RESPONSE_SUCCESS, $result['resultCode']); $this->assertTrue(isset($result['tripId'])); $this->assertEquals($testTripId2, $result['tripId']); }
$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']); } if ($trip->save()) { $response = successResponse();
} 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(); } else { $response = errorResponse(RESPONSE_INTERNAL_ERROR); }
/** * Extra test. Make sure the get operation works with a "latest" * value. */ function testGetLatest() { global $testTripId1, $testTripId2; // use the timezone where we do our testing :-) date_default_timezone_set("America/New_York"); $now = time(); $today = date('Y-m-d', $now); $yesterday = date('Y-m-d', $now - 24 * 60 * 60); $tomorrow = date('Y-m-d', $now + 24 * 60 * 60); $past = date('Y-m-d', $now - 5 * (24 * 60 * 60)); $future = date('Y-m-d', $now + 5 * (24 * 60 * 60)); $farPast = date('Y-m-d', $now - 10 * (24 * 60 * 60)); $farFuture = date('Y-m-d', $now + 10 * (24 * 60 * 60)); $testTrip1 = new Trip($testTripId1); $testTrip2 = new Trip($testTripId2); // one past and one future trip $testTrip1->setStartDate($past); $testTrip1->setEndDate($yesterday); $this->assertTrue($testTrip1->save()); $testTrip2->setStartDate($tomorrow); $testTrip2->setEndDate($future); $this->assertTrue($testTrip2->save()); $tripId = Trip::findCurrentTrip(); $this->assertEquals($testTripId1, $tripId); // one past and one current trip $testTrip1->setStartDate($past); $testTrip1->setEndDate($yesterday); $this->assertTrue($testTrip1->save()); $testTrip2->setStartDate($yesterday); $testTrip2->setEndDate($tomorrow); $this->assertTrue($testTrip2->save()); $tripId = Trip::findCurrentTrip(); $this->assertEquals($testTripId2, $tripId); // two past trips $testTrip1->setStartDate($past); $testTrip1->setEndDate($yesterday); $this->assertTrue($testTrip1->save()); $testTrip2->setStartDate($farPast); $testTrip2->setEndDate($past); $this->assertTrue($testTrip2->save()); $tripId = Trip::findCurrentTrip(); $this->assertEquals($testTripId1, $tripId); // one current and one future trip $testTrip1->setStartDate($yesterday); $testTrip1->setEndDate($tomorrow); $this->assertTrue($testTrip1->save()); $testTrip2->setStartDate($tomorrow); $testTrip2->setEndDate($future); $this->assertTrue($testTrip2->save()); $tripId = Trip::findCurrentTrip(); $this->assertEquals($testTripId1, $tripId); // two current trips, nested $testTrip1->setStartDate($yesterday); $testTrip1->setEndDate($tomorrow); $this->assertTrue($testTrip1->save()); $testTrip2->setStartDate($past); $testTrip2->setEndDate($future); $this->assertTrue($testTrip2->save()); $tripId = Trip::findCurrentTrip(); $this->assertEquals($testTripId1, $tripId); // two current trips, staggered $testTrip1->setStartDate($past); $testTrip1->setEndDate($tomorrow); $this->assertTrue($testTrip1->save()); $testTrip2->setStartDate($yesterday); $testTrip2->setEndDate($future); $this->assertTrue($testTrip2->save()); $tripId = Trip::findCurrentTrip(); $this->assertEquals($testTripId2, $tripId); }