You are here

public function FacetapiAdminInterfaceTestCase::testFormAccess in Facet API 7

Same name and namespace in other branches
  1. 6.3 tests/facetapi.test \FacetapiAdminInterfaceTestCase::testFormAccess()
  2. 7.2 tests/facetapi.test \FacetapiAdminInterfaceTestCase::testFormAccess()

Tests access to callbacks.

@todo Test invalid adapters, realms, facets. Test multiple realms.

File

tests/facetapi.test, line 162
Tests for the Facet API module.

Class

FacetapiAdminInterfaceTestCase
Test cases for operations taken through the admin UI.

Code

public function testFormAccess() {
  $paths = array(
    'admin/config/search/facetapi_test/facets' => t('realm settings'),
    'admin/config/search/facetapi/facetapi_test/block/enabled/edit' => t('display settings'),
    'admin/config/search/facetapi/facetapi_test/block/enabled/dependencies' => t('dependency settings'),
    'admin/config/search/facetapi/facetapi_test/block/enabled/filters' => t('filter settings'),
    'admin/config/search/facetapi/facetapi_test/block/enabled/export' => t('export settings'),
    'admin/config/search/facetapi/facetapi_test/block/enabled/revert' => t('revert settings'),
  );

  // Test wheter unprivileged user is denied access to forms.
  $this
    ->drupalLogin($this->authenticatedUser);
  foreach ($paths as $path => $form_name) {
    $this
      ->drupalGet($path);
    $this
      ->assertResponse(403, t('Unprivileged user does not have access to the @form-name form.', array(
      '@form-name' => $form_name,
    )), 'Facet API');
  }

  // Common message for privileged access checks.
  $privileged_message = t('Privileged user with "@permission" permission is granted access to the @form-name form.');

  // Test whether privileged user is granted access for forms.
  // NOTE: $this->adminUser has "administer search" permission.
  $this
    ->drupalLogin($this->adminUser);
  foreach ($paths as $path => $form_name) {
    $this
      ->drupalGet($path);
    $args = array(
      '@permission' => 'administer search',
      '@form-name' => $form_name,
    );
    $this
      ->assertResponse(200, t($privileged_message, $args));
  }

  // Tests whether privileged user is granted access for forms.
  // Create another user with the "administer facets" permission, test whether
  $facet_admin_user = $this
    ->drupalCreateUser(array(
    'administer facets',
  ));
  $this
    ->drupalLogin($facet_admin_user);
  foreach ($paths as $path => $form_name) {
    $this
      ->drupalGet($path);
    $args = array(
      '@permission' => 'administer facets',
      '@form-name' => $form_name,
    );
    $this
      ->assertResponse(200, t($privileged_message, $args));
  }
}