コード例 #1
0
     }
 } else {
     if (isPutMethod()) {
         $data = getPostData();
         if (isset($data['tripId']) && isset($data['userId']) && $data['tripId'] !== '' && $data['userId'] !== '') {
             $tripId = $data['tripId'];
             $userId = $data['userId'];
             $object = new TripUser($tripId, $userId);
             if (isset($data['created'])) {
                 $object->setCreated($data['created']);
             }
             if (isset($data['updated'])) {
                 $object->setUpdated($data['updated']);
             }
             if (isset($data['role'])) {
                 $object->setRole($data['role']);
             }
             if (isset($data['message'])) {
                 $object->setMessage($data['message']);
             }
             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);
             }
コード例 #2
0
ファイル: TripUserTest.php プロジェクト: egrivel/vacationblog
 /**
  * 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, $testUserId1, $testUserId1;
     // create the object and save it
     $object = new TripUser($testTripId1, $testUserId1);
     $object->setRole('role-1');
     $object->setMessage('message');
     $object->setDeleted('N');
     $this->assertTrue($object->save());
     $this->assertEquals(1, $this->countTestRows());
     $old_hash = $object->getHash();
     // change values and update the object
     $object->setRole('role-2');
     $object->setMessage('message 2');
     $object->setDeleted('Y');
     $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 = TripUser::findByHash($old_hash);
     $this->assertNotNull($object);
     $this->assertEquals($testTripId1, $object->getTripId());
     $this->assertEquals($testUserId1, $object->getUserId());
     $this->assertEquals('role-1', $object->getRole());
     $this->assertEquals('message', $object->getMessage());
     $this->assertEquals('N', $object->getDeleted());
     $this->assertEquals($old_hash, $object->getHash());
     // read the new object from the database and confirm that the new
     // values are returned
     $object = TripUser::findByHash($new_hash);
     $this->assertNotNull($object);
     $this->assertEquals($testTripId1, $object->getTripId());
     $this->assertEquals($testUserId1, $object->getUserId());
     $this->assertEquals('role-2', $object->getRole());
     $this->assertEquals('message 2', $object->getMessage());
     $this->assertEquals('Y', $object->getDeleted());
     $this->assertEquals($new_hash, $object->getHash());
 }
コード例 #3
0
 /**
  * Test #11. SYNCH get an existent object.
  * @depends testDataWipedBeforeTest
  * @depends testGetExistent
  */
 public function testSynchGet()
 {
     global $testTripId1;
     global $testUserId1;
     global $synchAuthToken;
     // Create the object and set attributes
     $object = new TripUser($testTripId1, $testUserId1);
     $object->setRole('maintainer');
     $object->setMessage('Message 1');
     $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('synchTripUser.php', $data, $synchAuthToken);
     $this->assertEquals(RESPONSE_SUCCESS, $result['resultCode']);
     $this->assertTrue(isset($result['tripId']));
     $this->assertTrue(isset($result['userId']));
     $this->assertTrue(isset($result['created']));
     $this->assertTrue(isset($result['updated']));
     $this->assertTrue(isset($result['role']));
     $this->assertTrue(isset($result['message']));
     $this->assertTrue(isset($result['deleted']));
     $this->assertTrue(isset($result['hash']));
     $this->assertEquals($testTripId1, $result['tripId']);
     $this->assertEquals($testUserId1, $result['userId']);
     $this->assertEquals($object->getCreated(), $result['created']);
     $this->assertEquals($object->getUpdated(), $result['updated']);
     $this->assertEquals('maintainer', $result['role']);
     $this->assertEquals('Message 1', $result['message']);
     $this->assertEquals('Y', $result['deleted']);
     $this->assertEquals($object->getHash(), $result['hash']);
 }