You are here

function ModuleGrantsBaseTestCase::assertNodeQueryAlter in Module Grants 7

Based on node.test's test methods

1 call to ModuleGrantsBaseTestCase::assertNodeQueryAlter()
ModuleGrantsBaseTestCase::assetNodeViewAccess in ./module_grants.test
node_accesses: array of node title => true/false
1 method overrides ModuleGrantsBaseTestCase::assertNodeQueryAlter()
ModuleGrantsBasicTestCase::assertNodeQueryAlter in ./module_grants.test
Based on node.test's test methods

File

./module_grants.test, line 190

Class

ModuleGrantsBaseTestCase

Code

function assertNodeQueryAlter($node_accesses, $account) {
  $num_of_visible_nodes = count(array_filter($node_accesses));
  $msg = t("@count nodes were found for user with permissions @permissions, lenient mode @lenient.", array(
    '@count' => $num_of_visible_nodes,
    '@permissions' => implode(',', $this
      ->getUserPermissions($account)),
    '@lenient' => variable_get('module_grants_lenient', true) ? 'on' : 'off',
  ));

  // UI test
  $this
    ->drupalGet('node_access_test_page');
  $this
    ->assertNoText('Exception', "No database exception");
  if ($num_of_visible_nodes > 0) {
    $this
      ->assertText("Yes, {$num_of_visible_nodes} nodes", $msg);
  }
  else {
    $this
      ->assertText('No nodes', $msg);
  }

  // Low level test
  try {
    $query = db_select('node', 'mytab')
      ->fields('mytab');
    $query
      ->addTag('node_access');
    $query
      ->addMetaData('op', 'view');
    $query
      ->addMetaData('account', $account);
    $result = $query
      ->execute()
      ->fetchAll();
    $this
      ->assertEqual(count($result), $num_of_visible_nodes, 'Use db_select with node_access tag: ' . $msg);
  } catch (Exception $e) {
    $this
      ->fail(t('Altered query is malformed'));
  }
}