$data = getPostData();
     if (isset($data['tripId']) && isset($data['name']) && $data['tripId'] !== '' && $data['name'] !== '') {
         $tripId = $data['tripId'];
         $name = $data['name'];
         $object = new TripAttribute($tripId, $name);
         if (isset($data['created'])) {
             $object->setCreated($data['created']);
         }
         if (isset($data['updated'])) {
             $object->setUpdated($data['updated']);
         }
         if (isset($data['value'])) {
             $object->setValue($data['value']);
         }
         if (isset($data['deleted'])) {
             $object->setDeleted($data['deleted']);
         }
         if (isset($data['hash'])) {
             $object->setHash($data['hash']);
         }
         if ($object->save()) {
             $response = successResponse();
         } else {
             $response = errorResponse(RESPONSE_INTERNAL_ERROR);
         }
     } else {
         $response = errorResponse(RESPONSE_BAD_REQUEST);
     }
 } else {
     $response = errorResponse(RESPONSE_BAD_REQUEST);
 }
 /**
  * Test #11. SYNCH get an existent object.
  * @depends testDataWipedBeforeTest
  * @depends testGetExistent
  */
 public function testSynchGet()
 {
     global $testTripId1;
     global $testName1;
     global $synchAuthToken;
     // Create the object and set Attributes
     $object = new TripAttribute($testTripId1, $testName1);
     $object->setValue('value');
     $object->setDeleted('Y');
     // Save the object and confirm a row is added to the database
     $this->assertTrue($object->save());
     $this->assertEquals(1, $this->countTestRows());
     $data = array('hash' => $object->getHash());
     $result = getApi('synchTripAttribute.php', $data, $synchAuthToken);
     $this->assertEquals(RESPONSE_SUCCESS, $result['resultCode']);
     $this->assertTrue(isset($result['tripId']));
     $this->assertTrue(isset($result['name']));
     $this->assertTrue(isset($result['created']));
     $this->assertTrue(isset($result['updated']));
     $this->assertTrue(isset($result['value']));
     $this->assertTrue(isset($result['deleted']));
     $this->assertTrue(isset($result['hash']));
     $this->assertEquals($testTripId1, $result['tripId']);
     $this->assertEquals($testName1, $result['name']);
     $this->assertEquals($object->getCreated(), $result['created']);
     $this->assertEquals($object->getUpdated(), $result['updated']);
     $this->assertEquals('value', $result['value']);
     $this->assertEquals('Y', $result['deleted']);
     $this->assertEquals($object->getHash(), $result['hash']);
 }
Esempio n. 3
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());
 }