Example #1
0
 /**
  * Test #11. SYNCH get an existent object.
  * @depends testDataWipedBeforeTest
  * @depends testGetExistent
  */
 public function testSynchGet()
 {
     global $testUserId1;
     global $synchAuthToken;
     $object = new User($testUserId1);
     $object->setName("Test User");
     $object->setExternalType("externaltype");
     $object->setExternalId("externalid");
     $object->setAccess("Y");
     $object->setEmail("*****@*****.**");
     $object->setNotification("Y");
     $object->setTempCode("tempcode");
     $object->setDeleted('Y');
     $object->save();
     $hash = $object->getHash();
     $data = array('hash' => $hash);
     $result = getApi('synchUser.php', $data, $synchAuthToken);
     $this->assertEquals(RESPONSE_SUCCESS, $result['resultCode']);
     $this->assertTrue(isset($result['userId']));
     $this->assertTrue(isset($result['created']));
     $this->assertTrue(isset($result['updated']));
     $this->assertTrue(isset($result['name']));
     $this->assertTrue(isset($result['externalType']));
     $this->assertTrue(isset($result['externalId']));
     $this->assertTrue(isset($result['access']));
     $this->assertTrue(isset($result['email']));
     $this->assertTrue(isset($result['notification']));
     $this->assertTrue(isset($result['tempCode']));
     $this->assertTrue(isset($result['deleted']));
     $this->assertTrue(isset($result['hash']));
     $this->assertEquals($testUserId1, $result['userId']);
     $this->assertEquals($object->getCreated(), $result['created']);
     $this->assertEquals($object->getUpdated(), $result['updated']);
     $this->assertEquals("Test User", $result['name']);
     $this->assertEquals("externaltype", $result['externalType']);
     $this->assertEquals("externalid", $result['externalId']);
     $this->assertEquals("Y", $result['access']);
     $this->assertEquals("*****@*****.**", $result['email']);
     $this->assertEquals("Y", $result['notification']);
     $this->assertEquals("tempcode", $result['tempCode']);
     $this->assertEquals('Y', $result['deleted']);
     $this->assertEquals($hash, $result['hash']);
 }
Example #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 $testUserId1;
     // create the object and save it
     $object = new User($testUserId1);
     $object->setName('Test User');
     $object->setExternalType('externaltype');
     $object->setExternalId('externalid');
     $object->setAccess('access');
     $object->setEmail('*****@*****.**');
     $object->setNotification('Y');
     $object->setTempCode('tempcode');
     $object->setDeleted('Y');
     $this->assertTrue($object->save());
     $this->assertEquals(1, $this->countTestRows());
     $old_hash = $object->getHash();
     // change values and update the object
     $object->setName('Test User 2');
     $object->setExternalType('externaltype 2');
     $object->setExternalId('externalid 2');
     $object->setAccess('access 2');
     $object->setEmail('*****@*****.**');
     $object->setNotification('N');
     $object->setTempCode('tempcode 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 = User::findByHash($old_hash);
     $this->assertNotNull($object);
     $this->assertEquals($testUserId1, $object->getUserId());
     $this->assertEquals('Test User', $object->getName());
     $this->assertEquals('externaltype', $object->getExternalType());
     $this->assertEquals('externalid', $object->getExternalId());
     $this->assertEquals('access', $object->getAccess());
     $this->assertEquals('*****@*****.**', $object->getEmail());
     $this->assertEquals('Y', $object->getNotification());
     $this->assertEquals('tempcode', $object->getTempCode());
     $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 = User::findByHash($new_hash);
     $this->assertNotNull($object);
     $this->assertEquals($testUserId1, $object->getUserId());
     $this->assertEquals('Test User 2', $object->getName());
     $this->assertEquals('externaltype 2', $object->getExternalType());
     $this->assertEquals('externalid 2', $object->getExternalId());
     $this->assertEquals('access 2', $object->getAccess());
     $this->assertEquals('*****@*****.**', $object->getEmail());
     $this->assertEquals('N', $object->getNotification());
     $this->assertEquals('tempcode 2', $object->getTempCode());
     $this->assertEquals('N', $object->getDeleted());
     $this->assertEquals($new_hash, $object->getHash());
 }
Example #3
0
                $object->setExternalType($data['externalType']);
            }
            if (isset($data['externalId'])) {
                $object->setExternalId($data['externalId']);
            }
            if (isset($data['access'])) {
                $object->setAccess($data['access']);
            }
            if (isset($data['email'])) {
                $object->setEmail($data['email']);
            }
            if (isset($data['notification'])) {
                $object->setNotification($data['notification']);
            }
            if (isset($data['tempCode'])) {
                $object->setTempCode($data['tempCode']);
            }
            if (isset($data['deleted'])) {
                $object->setDeleted($data['deleted']);
            }
            if ($object->save()) {
                $response = successResponse();
            } else {
                $response = errorResponse(RESPONSE_INTERNAL_ERROR);
            }
        }
    }
} else {
    $response = errorResponse(RESPONSE_METHOD_NOT_ALLOWED, 'Use Put method');
}
echo json_encode($response);