function testdllValidation() { Mock::generatePartial('OA_Dll_User', 'PartialMockOA_Dll_User', array('raiseError')); $dllUserMock = new PartialMockOA_Dll_User(); $dllUserMock->setReturnValue('raiseError', true); $dllUserMock->expectCallCount('raiseError', 2); $oUserInfo = new OA_Dll_UserInfo(); // Test with nothing set $this->assertFalse($this->oPlugin->dllValidation($dllUserMock, $oUserInfo)); // Test with username set $oUserInfo->username = '******'; $this->assertFalse($this->oPlugin->dllValidation($dllUserMock, $oUserInfo)); // Test with username and password set $oUserInfo->password = '******'; $this->assertTrue($this->oPlugin->dllValidation($dllUserMock, $oUserInfo)); $this->assertEqual($oUserInfo->password, md5('pwd')); // Test edit $oUserInfo = new OA_Dll_UserInfo(); $oUserInfo->userId = 1; $this->assertTrue($this->oPlugin->dllValidation($dllUserMock, $oUserInfo)); $this->assertNull($oUserInfo->password); // Test edit with new password $oUserInfo->password = '******'; $this->assertTrue($this->oPlugin->dllValidation($dllUserMock, $oUserInfo)); $this->assertEqual($oUserInfo->password, md5('pwd')); $dllUserMock->tally(); }
function testLinkUser() { $dllUserPartialMock = new PartialMockOA_Dll_User($this); $dllUserPartialMock->setReturnValue('checkPermissions', true); // create user $userId = DataGenerator::generateOne('users'); // Invalid advertiser account $this->assertTrue(!$dllUserPartialMock->linkUserToAdvertiserAccount($userId, 9999) && $dllUserPartialMock->getLastError() == OA_Dll_User::ERROR_UNKNOWN_ACC_ID, $this->_getMethodShouldReturnError(OA_Dll_User::ERROR_UNKNOWN_ACC_ID)); // Create advertiser $advertiserId = DataGenerator::generateOne('clients'); $doAdvertiser = OA_Dal::staticGetDO('clients', $advertiserId); $advertiserAccountId = $doAdvertiser->account_id; $aAdvertiserPermissions = array(OA_PERM_SUPER_ACCOUNT, OA_PERM_BANNER_EDIT, OA_PERM_BANNER_DEACTIVATE, OA_PERM_BANNER_ACTIVATE, OA_PERM_USER_LOG_ACCESS); // Invalid user $this->assertTrue(!$dllUserPartialMock->linkUserToAdvertiserAccount(9999, $advertiserAccountId) && $dllUserPartialMock->getLastError() == OA_Dll_User::ERROR_UNKNOWN_USER_ID, $this->_getMethodShouldReturnError(OA_Dll_User::ERROR_UNKNOWN_USER_ID)); // linkUserToAdvertiserAccount $this->assertTrue($dllUserPartialMock->linkUserToAdvertiserAccount($userId, $advertiserAccountId, $aAdvertiserPermissions)); // Check the link was made $this->assertLink($userId, $advertiserAccountId); // Check the correct permissions were added $this->assertPermissions($userId, $advertiserAccountId, $aAdvertiserPermissions); // Re-link should not give an error $this->assertTrue($dllUserPartialMock->linkUserToAdvertiserAccount($userId, $advertiserAccountId, $aAdvertiserPermissions)); // linkUserToTraffickerAccount $websiteId = DataGenerator::generateOne('affiliates'); $doWebsite = OA_Dal::staticGetDO('affiliates', $websiteId); $traffickerAccountId = $doWebsite->account_id; $aTraffickerPermissions = array(OA_PERM_SUPER_ACCOUNT, OA_PERM_ZONE_EDIT, OA_PERM_ZONE_ADD, OA_PERM_ZONE_DELETE, OA_PERM_ZONE_LINK, OA_PERM_ZONE_INVOCATION, OA_PERM_USER_LOG_ACCESS); $this->assertTrue($dllUserPartialMock->linkUserToTraffickerAccount($userId, $traffickerAccountId, $aTraffickerPermissions)); $this->assertLink($userId, $traffickerAccountId); $this->assertPermissions($userId, $traffickerAccountId, $aTraffickerPermissions); // linkUserToManagerAccount $agencyId = DataGenerator::generateOne('agency'); $doAgency = OA_Dal::staticGetDO('agency', $agencyId); $managerAccountId = $doAgency->account_id; $aManagerPermissions = array(OA_PERM_SUPER_ACCOUNT); $this->assertTrue($dllUserPartialMock->linkUserToManagerAccount($userId, $managerAccountId, $aManagerPermissions)); $this->assertLink($userId, $managerAccountId); $this->assertPermissions($userId, $traffickerAccountId, $aManagerPermissions); // Link to the wrong types of accounts $this->assertTrue(!$dllUserPartialMock->linkUserToAdvertiserAccount($userId, $managerAccountId) && $dllUserPartialMock->getLastError() == OA_Dll_User::ERROR_ACCOUNT_TYPE_MISMATCH, $this->_getMethodShouldReturnError(OA_Dll_User::ERROR_ACCOUNT_TYPE_MISMATCH)); $this->assertTrue(!$dllUserPartialMock->linkUserToTraffickerAccount($userId, $advertiserAccountId) && $dllUserPartialMock->getLastError() == OA_Dll_User::ERROR_ACCOUNT_TYPE_MISMATCH, $this->_getMethodShouldReturnError(OA_Dll_User::ERROR_ACCOUNT_TYPE_MISMATCH)); $this->assertTrue(!$dllUserPartialMock->linkUserToManagerAccount($userId, $advertiserAccountId) && $dllUserPartialMock->getLastError() == OA_Dll_User::ERROR_ACCOUNT_TYPE_MISMATCH, $this->_getMethodShouldReturnError(OA_Dll_User::ERROR_ACCOUNT_TYPE_MISMATCH)); }