コード例 #1
0
ファイル: TripUserTest.php プロジェクト: egrivel/vacationblog
 /**
  * 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, $testUserId1, $testUserId1;
     global $testUserId2;
     // Create the object, which automatically gets the current date
     $object = new TripUser($testTripId1, $testUserId1);
     $object->setRole('role-1');
     $object->setMessage('message');
     $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->setRole('role-2');
     $object->setMessage('message 2');
     $object->setDeleted('N');
     $object->setHash('future date hash');
     // Check the values before saving
     $this->assertEquals($testTripId1, $object->getTripId());
     $this->assertEquals($testUserId1, $object->getUserId());
     $this->assertEquals('2038-01-18 10:10:10.000000', $object->getCreated());
     $this->assertEquals('2038-01-18 10:10:11.000000', $object->getUpdated());
     $this->assertEquals('role-2', $object->getRole());
     $this->assertEquals('message 2', $object->getMessage());
     $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($testUserId1, $object->getUserId());
     $this->assertEquals('2038-01-18 10:10:10.000000', $object->getCreated());
     $this->assertEquals('2038-01-18 10:10:11.000000', $object->getUpdated());
     $this->assertEquals('role-2', $object->getRole());
     $this->assertEquals('message 2', $object->getMessage());
     $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->setRole('role-1');
     $object->setMessage('message 3');
     $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($testUserId1, $object->getUserId());
     $this->assertEquals('2038-01-18 10:10:10.000000', $object->getCreated());
     $this->assertEquals('2038-01-18 10:10:11.000000', $object->getUpdated());
     $this->assertEquals('role-2', $object->getRole());
     $this->assertEquals('message 2', $object->getMessage());
     $this->assertEquals('N', $object->getDeleted());
     // Note: this will FAIL in the current implementation!
     //$this->assertEquals('future date hash', $object->getHash());
 }
コード例 #2
0
                 $response['deleted'] = $object->getDeleted();
                 $response['hash'] = $object->getHash();
             }
         }
     } else {
         $response = errorResponse(RESPONSE_BAD_REQUEST);
     }
 } 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']);