$fallback_format = FilterFormat::
load(filter_fallback_format());
$disallowed_format_name =
$this->disallowedFormat->
getPermissionName();
$this->
assertTrue($this->allowedFormat->
access('use',
$this->webUser
), 'A regular user has access to use a text format they were granted access to.'
);
$this->
assertEquals(AccessResult::
allowed()->
addCacheContexts(['user.permissions'
]),
$this->allowedFormat->
access('use',
$this->webUser, TRUE
), 'A regular user has access to use a text format they were granted access to.'
);
$this->
assertFalse($this->disallowedFormat->
access('use',
$this->webUser
), 'A regular user does not have access to use a text format they were not granted access to.'
);
$this->
assertEquals(AccessResult::
neutral("The '
$disallowed_format_name' permission is required."
)->
cachePerPermissions(),
$this->disallowedFormat->
access('use',
$this->webUser, TRUE
), 'A regular user does not have access to use a text format they were not granted access to.'
);
$this->
assertTrue($fallback_format->
access('use',
$this->webUser
), 'A regular user has access to use the fallback format.'
);
$this->
assertEquals(AccessResult::
allowed(),
$fallback_format->
access('use',
$this->webUser, TRUE
), 'A regular user has access to use the fallback format.'
);
// Perform similar checks as above, but now against the entire list of
// available formats for this user.
$this->
assertContains($this->allowedFormat->
id(),
array_keys(filter_formats($this->webUser
)), 'The allowed format appears in the list of available formats for a regular user.'
);
$this->
assertNotContains($this->disallowedFormat->
id(),
array_keys(filter_formats($this->webUser
)), 'The disallowed format does not appear in the list of available formats for a regular user.'
);
$this->
assertContains(filter_fallback_format(),
array_keys(filter_formats($this->webUser
)), 'The fallback format appears in the list of available formats for a regular user.'
);
// Make sure that a regular user only has permission to use the format
// they were granted access to.
$this->
assertTrue($this->webUser->
hasPermission($this->allowedFormat->
getPermissionName()), 'A regular user has permission to use the allowed text format.'
);
$this->
assertFalse($this->webUser->
hasPermission($this->disallowedFormat->
getPermissionName()), 'A regular user does not have permission to use the disallowed text format.'
);
// Make sure that the allowed format appears on the node form and that
// the disallowed format and fallback format do not.
$this->
drupalLogin($this->webUser
);