コード例 #1
0
<?php

include_once dirname(__FILE__) . "/../common/common.php";
include_once dirname(__FILE__) . '/../business/AuthB.php';
include_once dirname(__FILE__) . '/../database/TripAttribute.php';
$auth = new AuthB();
if (!$auth->canSynchTripAttribute()) {
    $response = errorResponse(RESPONSE_UNAUTHORIZED);
} else {
    if (isGetMethod()) {
        if (isset($_GET['hash'])) {
            $hash = $_GET['hash'];
            if ($hash === '') {
                $response = errorResponse(RESPONSE_BAD_REQUEST);
            } else {
                $object = TripAttribute::findByHash($hash);
                if ($object === null) {
                    $response = errorResponse(RESPONSE_NOT_FOUND);
                } else {
                    $response = successResponse();
                    $response['tripId'] = $object->getTripId();
                    $response['name'] = $object->getName();
                    $response['created'] = $object->getCreated();
                    $response['updated'] = $object->getUpdated();
                    $response['value'] = $object->getValue();
                    $response['deleted'] = $object->getDeleted();
                    $response['hash'] = $object->getHash();
                }
            }
        } else {
            $response = errorResponse(RESPONSE_BAD_REQUEST);
コード例 #2
0
 /**
  * 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 TripAttribute($testTripId1, 'name');
     $object->setValue('value');
     $object->setDeleted('Y');
     $this->assertTrue($object->save());
     $this->assertEquals(1, $this->countTestRows());
     $old_hash = $object->getHash();
     // change values and update the object
     $object->setValue('value 2');
     $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 = TripAttribute::findByHash($old_hash);
     $this->assertNotNull($object);
     $this->assertEquals($testTripId1, $object->getTripId());
     $this->assertEquals('name', $object->getName());
     $this->assertEquals('value', $object->getValue());
     $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 = TripAttribute::findByHash($new_hash);
     $this->assertNotNull($object);
     $this->assertEquals($testTripId1, $object->getTripId());
     $this->assertEquals('name', $object->getName());
     $this->assertEquals('value 2', $object->getValue());
     $this->assertEquals('N', $object->getDeleted());
     $this->assertEquals($new_hash, $object->getHash());
 }