1 filter.test FilterFormatAccessTestCase::testFormatRoles()

Tests if text format is available to a role.

File

core/modules/filter/tests/filter.test, line 679
Tests for filter.module.

Class

FilterFormatAccessTestCase
Tests the filter format access functionality in the Filter module.

Code

function testFormatRoles() {
  // Get the role name assigned to the regular user.
  $roles = array_diff($this->web_user->roles, array(BACKDROP_AUTHENTICATED_ROLE));
  $role_name = reset($roles);

  // Check that this role appears in the list of roles that have access to an
  // allowed text format, but does not appear in the list of roles that have
  // access to a disallowed text format.
  $this->assertTrue(in_array($role_name, filter_get_roles_by_format($this->allowed_format)), 'A role which has access to a text format appears in the list of roles that have access to that format.');
  $this->assertFalse(in_array($role_name, filter_get_roles_by_format($this->disallowed_format)), 'A role which does not have access to a text format does not appear in the list of roles that have access to that format.');

  // Check that the correct text format appears in the list of formats
  // available to that role.
  $this->assertTrue(in_array($this->allowed_format->format, array_keys(filter_get_formats_by_role($role_name))), 'A text format which a role has access to appears in the list of formats available to that role.');
  $this->assertFalse(in_array($this->disallowed_format->format, array_keys(filter_get_formats_by_role($role_name))), 'A text format which a role does not have access to does not appear in the list of formats available to that role.');

  // Check that the fallback format is always allowed.
  $this->assertEqual(filter_get_roles_by_format(filter_format_load(filter_fallback_format())), array_keys(user_roles()), 'All roles have access to the fallback format.');
  $this->assertTrue(in_array(filter_fallback_format(), array_keys(filter_get_formats_by_role($role_name))), 'The fallback format appears in the list of allowed formats for any role.');
}