You are here

class DrupalApacheSolrNodeAccess in Apache Solr Search 5

Same name and namespace in other branches
  1. 8 apachesolr_access/tests/apachesolr_access.test \DrupalApacheSolrNodeAccess
  2. 6.3 apachesolr_access/tests/apachesolr_access.test \DrupalApacheSolrNodeAccess
  3. 6 contrib/apachesolr_nodeaccess/tests/apachesolr_nodeaccess.test \DrupalApacheSolrNodeAccess
  4. 6.2 contrib/apachesolr_nodeaccess/tests/apachesolr_nodeaccess.test \DrupalApacheSolrNodeAccess
  5. 7 apachesolr_access/tests/apachesolr_access.test \DrupalApacheSolrNodeAccess

Hierarchy

Expanded class hierarchy of DrupalApacheSolrNodeAccess

File

contrib/apachesolr_nodeaccess/tests/apachesolr_nodeaccess.test, line 3

View source
class DrupalApacheSolrNodeAccess extends DrupalTestCase {
  function get_info() {
    return array(
      'name' => 'Node Access',
      'description' => 'Test Access Control',
      'group' => 'Apache Solr tests',
    );
  }
  function setUp() {
    parent::setUp("nodeaccess", "apachesolr", "apachesolr_search", "apachesolr_nodeaccess");
    print_r($this);

    // Create a basic user, which is subject to moderation.
    $permissions = array(
      'access content',
      'create page content',
      'edit own page content',
      'create story content',
      'edit own story content',
    );
    $this->basic_user = $this
      ->drupalCreateUserRolePerm($permissions);
  }
  function testIndexing() {
    $basic_user = $this->basic_user;

    // Login as basic user to perform initial content creation.
    $this
      ->drupalLoginUser($basic_user);

    //Create 2 nodes
    $role_restricted_node = new StdClass();
    $role_restricted_node->title = $this
      ->randomName(32);
    $role_restricted_node->body = $this
      ->randomName(32);
    $role_restricted_node->comment = 2;
    $role_restricted_node->changed = time();
    $role_restricted_node->format = FILTER_FORMAT_DEFAULT;
    $role_restricted_node->moderate = 0;
    $role_restricted_node->promote = 0;
    $role_restricted_node->revision = 1;
    $role_restricted_node->log = '';
    $role_restricted_node->status = 1;
    $role_restricted_node->sticky = 0;
    $role_restricted_node->type = 'page';
    $role_restricted_node->revisions = NULL;
    $role_restricted_node->taxonomy = NULL;
    node_save($node);
    $author_restricted_node = new StdClass();
    $author_restricted_node->title = $this
      ->randomName(32);
    $author_restricted_node->body = $this
      ->randomName(32);
    $role_restricted_node->comment = 2;
    $role_restricted_node->changed = time();
    $role_restricted_node->format = FILTER_FORMAT_DEFAULT;
    $role_restricted_node->moderate = 0;
    $role_restricted_node->promote = 0;
    $role_restricted_node->revision = 1;
    $role_restricted_node->log = '';
    $role_restricted_node->status = 1;
    $role_restricted_node->sticky = 0;
    $role_restricted_node->type = 'page';
    $role_restricted_node->revisions = NULL;
    $role_restricted_node->taxonomy = NULL;
    node_save($node);

    // No Drupal Logout in SimpleTest 1    $this->drupalLogout();
    $roles = array_keys($basic_user->roles);

    // The assigned role will be the last in the array.
    $assigned_role = end($roles);
    $role_grant = array(
      'gid' => $assigned_role,
      'realm' => 'nodeaccess_rid',
      'grant_view' => '1',
      'grant_update' => '0',
      'grant_delete' => '0',
    );
    node_access_write_grants($role_restricted_node, array(
      $role_grant,
    ), "nodeaccess_rid");
    $author_grant = array(
      'gid' => $basic_user->uid,
      'realm' => 'nodeaccess_author',
      'grant_view' => '1',
      'grant_update' => '0',
      'grant_delete' => '0',
    );
    node_access_write_grants($author_restricted_node, array(
      $author_grant,
    ), "nodeaccess_author");
    $include_path = get_include_path();
    set_include_path('./' . drupal_get_path('module', 'apachesolr') . '/SolrPhpClient/');
    include_once 'Apache/Solr/Service.php';
    set_include_path($include_path);
    $document = new Apache_Solr_Document();
    apachesolr_nodeaccess_apachesolr_update_index($document, $role_restricted_node);
    $this
      ->assertEqual($document->nodeaccess_nodeaccess_rid[0], $assigned_role, "Solr Document being indexed is restricted by the proper role");
    $document = new Apache_Solr_Document();
    apachesolr_nodeaccess_apachesolr_update_index($document, $author_restricted_node);
    $this
      ->assertEqual($document->nodeaccess_nodeaccess_author[0], $basic_user->uid, "Solr Document being indexed is restricted by the proper author");
  }
  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) . "]");
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DrupalApacheSolrNodeAccess::get_info function
DrupalApacheSolrNodeAccess::setUp function
DrupalApacheSolrNodeAccess::testIndexing function
DrupalApacheSolrNodeAccess::testQuery function
DrupalTestCase::$_cleanupModules property
DrupalTestCase::$_cleanupRoles property
DrupalTestCase::$_cleanupUsers property
DrupalTestCase::$_cleanupVariables property
DrupalTestCase::$_content property
DrupalTestCase::assertCopy function Will trigger a pass if both parameters refer to different objects. Fail otherwise.
DrupalTestCase::assertEqual function Will trigger a pass if the two parameters have the same value only. Otherwise a fail.
DrupalTestCase::assertError function Confirms that an error has occurred and optionally that the error text matches exactly.
DrupalTestCase::assertErrorPattern function Confirms that an error has occurred and that the error text matches a Perl regular expression.
DrupalTestCase::assertIdentical function Will trigger a pass if the two parameters have the same value and same type. Otherwise a fail.
DrupalTestCase::assertIsA function Type and class test. Will pass if class matches the type name or is a subclass or if not an object, but the type is correct.
DrupalTestCase::assertNoErrors function Confirms that no errors have occurred so far in the test method.
DrupalTestCase::assertNotA function Type and class mismatch test. Will pass if class name or underling type does not match the one specified.
DrupalTestCase::assertNotEqual function Will trigger a pass if the two parameters have a different value. Otherwise a fail.
DrupalTestCase::assertNotIdentical function Will trigger a pass if the two parameters have the different value or different type.
DrupalTestCase::assertNotNull function Will be true if the value is set.
DrupalTestCase::assertNoUnwantedPattern function Will trigger a pass if the Perl regex pattern is not present in subject. Fail if found.
DrupalTestCase::assertNoUnwantedRaw function Will trigger a pass if the raw text is NOT found on the loaded page Fail otherwise.
DrupalTestCase::assertNull function Will be true if the value is null.
DrupalTestCase::assertReference function Will trigger a pass if both parameters refer to the same object. Fail otherwise.
DrupalTestCase::assertWantedPattern function Will trigger a pass if the Perl regex pattern is found in the subject. Fail otherwise.
DrupalTestCase::assertWantedRaw function Will trigger a pass if the raw text is found on the loaded page Fail otherwise.
DrupalTestCase::clickLink function Follows a link by name. Will click the first link found with this link text by default, or a later one if an index is given. Match is case insensitive with normalised space. Does make assertations if the click was sucessful or not and it does…
DrupalTestCase::drupalCheckAuth function @abstract Checks to see if we need to send a http-auth header to authenticate when browsing a site.
DrupalTestCase::drupalCreateRolePerm function Create a role / perm combination specified by permissions
DrupalTestCase::drupalCreateUserRolePerm function Creates a user / role / permissions combination specified by permissions
DrupalTestCase::drupalGet function @abstract Brokder for the get function adds the authentication headers if necessary @author Earnest Berry III <earnest.berry@gmail.com>
DrupalTestCase::drupalGetContent function @TODO: needs documentation
DrupalTestCase::drupalLoginUser function Logs in a user with the internal browser
DrupalTestCase::drupalModuleDisable function Disables a drupal module
DrupalTestCase::drupalModuleEnable function Enables a drupal module
DrupalTestCase::drupalPostRequest function Do a post request on a drupal page. It will be done as usual post request with SimpleBrowser
DrupalTestCase::drupalRawPost function @abstract Broker for the post function adds the authentication headers if necessary @author Earnest Berry III <earnest.berry@gmail.com>
DrupalTestCase::DrupalTestCase function
DrupalTestCase::drupalVariableSet function Set a druapl variable and keep track of the changes for tearDown()
DrupalTestCase::randomName function Generates a random string, to be used as name or whatever
DrupalTestCase::run function Just some info for the reporter
DrupalTestCase::tearDown function tearDown implementation, setting back switched modules etc 1