Пример #1
0
 /**
  * Extra test. Make sure a large amount of text can be uploaded by
  * synch.
  * @depends testSynchPut
  */
 public function testSynchPutLarge()
 {
     global $testTripId1;
     global $synchAuthToken;
     $largeText = $this->getLargeText(15000);
     $this->assertEquals(0, $this->countTestRows());
     $data = array('tripId' => $testTripId1, 'created' => '2015-10-01', 'updated' => '2015-10-02', 'name' => 'Test Trip', 'description' => $largeText, 'bannerImg' => 'test-01.png', 'startDate' => '2015-09-01', 'endDate' => '2015-09-30', 'active' => 'Y', 'deleted' => 'Y', 'hash' => 'forced hash');
     $result = putApi('synchTrip.php', $data, $synchAuthToken);
     $this->assertEquals(RESPONSE_SUCCESS, $result['resultCode']);
     $this->assertEquals(1, $this->countTestRows());
     $object = new Trip($testTripId1);
     $this->assertEquals('2015-10-01 00:00:00.000000', $object->getCreated());
     $this->assertEquals('2015-10-02 00:00:00.000000', $object->getUpdated());
     $this->assertEquals("Test Trip", $object->getName());
     $this->assertEquals($largeText, $object->getDescription());
     $this->assertEquals("test-01.png", $object->getBannerImg());
     $this->assertEquals("2015-09-01", $object->getStartDate());
     $this->assertEquals("2015-09-30", $object->getEndDate());
     $this->assertEquals("Y", $object->getActive());
     $this->assertEquals("Y", $object->getDeleted());
     $this->assertEquals('forced hash', $object->getHash());
 }
Пример #2
0
 /**
  * test #14.
  * Overriding automatic attributes using a future date. Because
  * a future date is used, the record can no longer be changed after
  * it was saved.
  * @depends testSaveEmptyObject
  * @depends testSetAttributes
  * @depends testUpdate
  * @depends testOverrideAutomaticAttributesNewRecord
  */
 public function testOverrideAutomaticAttributesFutureDate()
 {
     global $testTripId1;
     // Create the object, which automatically gets the current date
     $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());
     $originalCreated = $object->getCreated();
     $originalUpdated = $object->getUpdated();
     $originalHash = $object->getHash();
     // Change the object with different values, using a guaranteed
     // future date for the Created and Updated fields. Note that
     // the mySQL timestamp values allow for dates up to January 19,
     // 2038. Select as the future date for this test January 18, 2038
     // values after first save are unchanged
     $object->setCreated('2038-01-18 10:10:10.000000');
     $object->setUpdated('2038-01-18 10:10:11.000000');
     $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');
     $object->setHash('future date hash');
     // Check the values before saving
     $this->assertEquals($testTripId1, $object->getTripId());
     $this->assertEquals('2038-01-18 10:10:10.000000', $object->getCreated());
     $this->assertEquals('2038-01-18 10:10:11.000000', $object->getUpdated());
     $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('future date hash', $object->getHash());
     // update the record, this adds a row in the database
     $this->assertTrue($object->save());
     $this->assertEquals(2, $this->countTestRows());
     // after the update, the information has been saved
     $this->assertEquals($testTripId1, $object->getTripId());
     $this->assertEquals('2038-01-18 10:10:10.000000', $object->getCreated());
     $this->assertEquals('2038-01-18 10:10:11.000000', $object->getUpdated());
     $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('future date hash', $object->getHash());
     // Try to update the record. This will add a row in the database
     $object->setName('Test Trip 3');
     $object->setDescription('Test Description 3');
     $object->setBannerImg('test-03.png');
     $object->setStartDate('2013-08-01');
     $object->setEndDate('2013-09-30');
     $object->setActive('Y');
     $object->setDeleted('Y');
     $this->assertTrue($object->save());
     $this->assertEquals(3, $this->countTestRows());
     // but the new information is not saved. The previously saved
     // information cannot be overwritten without manually setting the
     // updated field.
     $this->assertEquals($testTripId1, $object->getTripId());
     $this->assertEquals('2038-01-18 10:10:10.000000', $object->getCreated());
     $this->assertEquals('2038-01-18 10:10:11.000000', $object->getUpdated());
     $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());
     // Note: this will FAIL in the current implementation!
     //$this->assertEquals('future date hash', $object->getHash());
 }
Пример #3
0
    if ($tripId === '') {
        $response = errorResponse(RESPONSE_BAD_REQUEST);
    } else {
        $object = new Trip($tripId);
        if ($object->getCreated() === null) {
            $response = errorResponse(RESPONSE_NOT_FOUND);
        } else {
            $response = successResponse();
            $response['tripId'] = $object->getTripId();
            $response['created'] = $object->getCreated();
            $response['updated'] = $object->getUpdated();
            $response['name'] = $object->getName();
            $response['description'] = $object->getDescription();
            $response['bannerImg'] = $object->getBannerImg();
            $response['startDate'] = $object->getStartDate();
            $response['endDate'] = $object->getEndDate();
            $response['active'] = $object->getActive();
            $response['deleted'] = $object->getDeleted();
            // Do NOT return the hash field on the GET service.
            $journal = Journal::getFirstJournal($object->getTripId());
            if ($journal !== null) {
                $response['firstJournalId'] = $journal->getJournalId();
            }
            $journal = Journal::getLastJournal($object->getTripId());
            if ($journal !== null) {
                $response['lastJournalId'] = $journal->getJournalId();
            }
        }
    }
}
echo json_encode($response);
Пример #4
0
<?php

session_start();
$user = new User();
if ($user->selectByEmail(Database::sessionDecrypt($_SESSION['user']))) {
    $trip = new Trip();
    $trip->fillByAssoc($_POST);
    $trip->setUserId($user->getUserId());
    $trip->setNPart(1);
    if (Util::compareDate($trip->getStartDate(), $trip->getEndDate())) {
        $res = $trip->insert();
        if ($res) {
            Logger::var_dump_log('AddTrip', $trip->getName());
            echo ReturnCode::$success;
        } else {
            Logger::log('AddTrip', 'Failed');
            echo ReturnCode::$error;
        }
    } else {
        echo ReturnCode::$error;
    }
} else {
    echo ReturnCode::$userNotFound;
}