You are here

function FilterFormatAccessTest::testFormatRoles in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/filter/src/Tests/FilterFormatAccessTest.php \Drupal\filter\Tests\FilterFormatAccessTest::testFormatRoles()

Tests if text format is available to a role.

File

core/modules/filter/src/Tests/FilterFormatAccessTest.php, line 188
Contains \Drupal\filter\Tests\FilterFormatAccessTest.

Class

FilterFormatAccessTest
Tests access to text formats.

Namespace

Drupal\filter\Tests

Code

function testFormatRoles() {

  // Get the role ID assigned to the regular user.
  $roles = $this->webUser
    ->getRoles(TRUE);
  $rid = $roles[0];

  // 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($rid, array_keys(filter_get_roles_by_format($this->allowedFormat))), '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($rid, array_keys(filter_get_roles_by_format($this->disallowedFormat))), '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->allowedFormat
    ->id(), array_keys(filter_get_formats_by_role($rid))), 'A text format which a role has access to appears in the list of formats available to that role.');
  $this
    ->assertFalse(in_array($this->disallowedFormat
    ->id(), array_keys(filter_get_formats_by_role($rid))), '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(entity_load('filter_format', filter_fallback_format())), user_role_names(), 'All roles have access to the fallback format.');
  $this
    ->assertTrue(in_array(filter_fallback_format(), array_keys(filter_get_formats_by_role($rid))), 'The fallback format appears in the list of allowed formats for any role.');
}