You are here

function DrupalApacheSolrNodeAccess::testQuery in Apache Solr Search 5

Same name and namespace in other branches
  1. 6 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 107

Class

DrupalApacheSolrNodeAccess

Code

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

  // Login as basic user
  $this
    ->drupalLoginUser($basic_user);
  include_once drupal_get_path('module', 'apachesolr') . '/Solr_Base_Query.php';
  $query = apachesolr_drupal_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_nodeaccess_rid" => array(
      2,
      $assigned_role,
    ),
    "nodeaccess_nodeaccess_uid" => $basic_user->uid,
    "nodeaccess_nodeaccess_author" => $basic_user->uid,
  );
  $fields = $subquery
    ->get_fields();
  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($expected_criterion[$field['#name']], $field['#value'], 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) . "]");
}