You are here

function DrupalApacheSolrNodeAccess::testQuery in Apache Solr Search 6

Same name and namespace in other branches
  1. 5 contrib/apachesolr_nodeaccess/tests/apachesolr_nodeaccess.test \DrupalApacheSolrNodeAccess::testQuery()
  2. 6.2 contrib/apachesolr_nodeaccess/tests/apachesolr_nodeaccess.test \DrupalApacheSolrNodeAccess::testQuery()

File

contrib/apachesolr_nodeaccess/tests/apachesolr_nodeaccess.test, line 87
Tests for the apachsolr_nodeaccess module.

Class

DrupalApacheSolrNodeAccess
@file Tests for the apachsolr_nodeaccess module.

Code

function testQuery() {
  $basic_user = $this->basic_user;

  // Login as basic user
  $this
    ->drupalLogin($basic_user);
  module_load_include('php', 'apachesolr', 'Solr_Base_Query');
  $query = apachesolr_current_query();
  $params = array();
  $subquery = _apachesolr_nodeaccess_build_subquery($basic_user);
  $roles = array_keys($basic_user->roles);
  $assigned_role = end($roles);
  $expected_criterion = array(
    'nodeaccess_all' => 0,
    'nodeaccess_' . apachesolr_site_hash() . '_all' => 0,
    'nodeaccess_' . apachesolr_site_hash() . '_nodeaccess_rid' => array(
      2,
      $assigned_role,
    ),
    'nodeaccess_' . apachesolr_site_hash() . '_nodeaccess_uid' => $basic_user->uid,
    'nodeaccess_' . apachesolr_site_hash() . '_nodeaccess_author' => $basic_user->uid,
  );
  $fields = $subquery
    ->get_filters();
  foreach ($fields as $field) {
    if (is_array($expected_criterion[$field['#name']])) {
      $this
        ->assertTrue(in_array($field['#value'], $expected_criterion[$field['#name']]), t('Expected node access grant @name == @value found', array(
        '@name' => $field['#name'],
        '@value' => $field['#value'],
      )));

      //This is sorta a bug
      $found_criterion[$field['#name']] = $expected_criterion[$field['#name']];
    }
    else {
      $this
        ->assertEqual($field['#value'], $expected_criterion[$field['#name']], t('Expected node access grant @name == @value found', array(
        '@name' => $field['#name'],
        '@value' => $field['#value'],
      )));
      $found_criterion[$field['#name']] = $expected_criterion[$field['#name']];
    }
  }
  $this
    ->assertEqual($expected_criterion, $found_criterion, 'All Criteria was accounted for in fields. If not accounted for, Unaccounted Criteria [' . var_export(array_diff($expected_criterion, $found_criterion), 1) . ']');
}