/** * 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()); }
<?php include_once dirname(__FILE__) . "/../common/common.php"; include_once dirname(__FILE__) . '/../business/AuthB.php'; include_once dirname(__FILE__) . '/../database/User.php'; $auth = new AuthB(); if (!$auth->canSynchUser()) { $response = errorResponse(RESPONSE_UNAUTHORIZED); } else { if (isGetMethod()) { if (isset($_GET['hash'])) { $hash = $_GET['hash']; if ($hash === '') { $response = errorResponse(RESPONSE_BAD_REQUEST, 'Need hash'); } else { $object = User::findByHash($hash); if ($object === null) { $response = errorResponse(RESPONSE_NOT_FOUND); } else { $response = successResponse(); $response['userId'] = $object->getUserId(); $response['passwordHash'] = $object->getPasswordHash(); $response['created'] = $object->getCreated(); $response['updated'] = $object->getUpdated(); $response['name'] = $object->getName(); $response['externalType'] = $object->getExternalType(); $response['externalId'] = $object->getExternalId(); $response['access'] = $object->getAccess(); $response['email'] = $object->getEmail(); $response['notification'] = $object->getNotification(); $response['tempCode'] = $object->getTempCode();