protected function UcAddressesViewsTestCase::assertAddressAccessResponse in Ubercart Addresses 6.2
Same name and namespace in other branches
- 7 tests/uc_addresses.views.test \UcAddressesViewsTestCase::assertAddressAccessResponse()
Pass if the user with access get's a 200 and 403 if the user should not have access.
Parameters
object $account: The current logged in user.
string $access_type: The permission to check: view, edit or delete.
string $owner: The address owner.
boolean $is_default_address: (optional) If access is checked for a default address or not.
string $fail_response: (optional) The response code when the user should not have access. Defaults to 403.
1 call to UcAddressesViewsTestCase::assertAddressAccessResponse()
- UcAddressesViewsTestCase::doDisplayAccessTests in tests/
uc_addresses.views.test - Tests for each user if he/she should have access to pages:
File
- tests/
uc_addresses.views.test, line 416 - Test cases for Views integration.
Class
- UcAddressesViewsTestCase
- Test cases for Views integration.
Code
protected function assertAddressAccessResponse($account, $access_type, $owner, $is_default_address = FALSE, $fail_response = 403) {
// Prepare assert message.
$access_own = $account->uc_addresses_permissions[$access_type . '_own'];
$access_all = $account->uc_addresses_permissions[$access_type . '_all'];
switch ($access_type) {
case 'view':
if ($is_default_address) {
$access_own = $account->uc_addresses_permissions['view_own_def'];
$access_all = $account->uc_addresses_permissions['view_all_def'];
}
break;
case 'delete':
if ($is_default_address) {
$access_own = FALSE;
$access_all = FALSE;
}
break;
}
$message_vars = array(
'!name' => check_plain($account->name),
'!access_type' => $access_type,
'!access_own' => $access_own ? '' : 'NOT ',
'!access_all' => $access_all ? '' : 'NOT ',
'!default' => $is_default_address ? ' default' : '',
);
if ($account->uid == $owner->uid) {
$message = strtr('User !name may !access_own!access_type own!default addresses.', $message_vars);
$this
->assertResponse($access_own ? 200 : $fail_response, $message);
}
else {
$message = strtr('User !name may !access_all!access_type all!default addresses.', $message_vars);
$this
->assertResponse($access_all ? 200 : $fail_response, $message);
}
}