This repository has been archived on 2025-01-19. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
// Query the node table with the node access tag in several languages.
// Query with no language specified. The fallback (hu or und) will be used.
$select=db_select('node','n')
->fields('n',array('nid'))
->addMetaData('account',$this->webUser)
->addTag('node_access');
$nids=$select->execute()->fetchAllAssoc('nid');
// Four nodes should be returned with public Hungarian translations or the
// no language public node.
$this->assertEqual(count($nids),4,'db_select() returns 4 nodes when no langcode is specified.');
$this->assertTrue(array_key_exists($this->nodes['public_both_public']->id(),$nids),'Returned node ID is full public node.');
$this->assertTrue(array_key_exists($this->nodes['public_ca_private']->id(),$nids),'Returned node ID is Hungarian public only node.');
$this->assertTrue(array_key_exists($this->nodes['private_both_public']->id(),$nids),'Returned node ID is both public non-language-aware private only node.');
$this->assertTrue(array_key_exists($this->nodes['public_no_language_public']->id(),$nids),'Returned node ID is no language public node.');
// Query with Hungarian (hu) specified.
$select=db_select('node','n')
->fields('n',array('nid'))
->addMetaData('account',$this->webUser)
->addMetaData('langcode','hu')
->addTag('node_access');
$nids=$select->execute()->fetchAllAssoc('nid');
// Three nodes should be returned (with public Hungarian translations).
$this->assertTrue(array_key_exists($this->nodes['public_both_public']->id(),$nids),'Returned node ID is both public node.');
$this->assertTrue(array_key_exists($this->nodes['public_ca_private']->id(),$nids),'Returned node ID is Hungarian public only node.');
$this->assertTrue(array_key_exists($this->nodes['private_both_public']->id(),$nids),'Returned node ID is both public non-language-aware private only node.');
// Query with Catalan (ca) specified.
$select=db_select('node','n')
->fields('n',array('nid'))
->addMetaData('account',$this->webUser)
->addMetaData('langcode','ca')
->addTag('node_access');
$nids=$select->execute()->fetchAllAssoc('nid');
// Three nodes should be returned (with public Catalan translations).
$this->assertTrue(array_key_exists($this->nodes['public_both_public']->id(),$nids),'Returned node ID is both public node.');
$this->assertTrue(array_key_exists($this->nodes['public_hu_private']->id(),$nids),'Returned node ID is Catalan public only node.');
$this->assertTrue(array_key_exists($this->nodes['private_both_public']->id(),$nids),'Returned node ID is both public non-language-aware private only node.');
// Query with German (de) specified.
$select=db_select('node','n')
->fields('n',array('nid'))
->addMetaData('account',$this->webUser)
->addMetaData('langcode','de')
->addTag('node_access');
$nids=$select->execute()->fetchAllAssoc('nid');
// There are no nodes with German translations, so no results are returned.
$this->assertTrue(empty($nids),'db_select() returns an empty result.');
// Query the nodes table as admin user (full access) with the node access
// tag and no specific langcode.
$select=db_select('node','n')
->fields('n',array('nid'))
->addMetaData('account',$this->adminUser)
->addTag('node_access');
$nids=$select->execute()->fetchAllAssoc('nid');
// All nodes are returned.
$this->assertEqual(count($nids),10,'db_select() returns all nodes.');
// Query the nodes table as admin user (full access) with the node access
// tag and langcode de.
$select=db_select('node','n')
->fields('n',array('nid'))
->addMetaData('account',$this->adminUser)
->addMetaData('langcode','de')
->addTag('node_access');
$nids=$select->execute()->fetchAllAssoc('nid');
// Even though there is no German translation, all nodes are returned
// because node access filtering does not occur when the user is user 1.
$this->assertEqual(count($nids),10,'db_select() returns all nodes.');