Tests node_access() with multiple node languages and no private nodes.
function testNodeAccess() {
$web_user = $this
->drupalCreateUser(array(
'access content',
));
$expected_node_access = array(
'view' => TRUE,
'update' => FALSE,
'delete' => FALSE,
);
$expected_node_access_no_access = array(
'view' => FALSE,
'update' => FALSE,
'delete' => FALSE,
);
// Creating a public node with langcode Hungarian, will be saved as the
// fallback in node access table.
$node_public = $this
->drupalCreateNode(array(
'body' => array(
array(),
),
'langcode' => 'hu',
'private' => FALSE,
));
$this
->assertTrue($node_public->langcode == 'hu', 'Node created as Hungarian.');
// Tests the default access is provided for the public Hungarian node.
$this
->assertNodeAccess($expected_node_access, $node_public, $web_user);
// Tests that Hungarian provided specifically results in the same.
$this
->assertNodeAccess($expected_node_access, $node_public, $web_user, 'hu');
// There is no specific Catalan version of this node and Croatian is not
// even set up on the system in this scenario, so the user will not get
// access to these nodes.
$this
->assertNodeAccess($expected_node_access_no_access, $node_public, $web_user, 'ca');
$this
->assertNodeAccess($expected_node_access_no_access, $node_public, $web_user, 'hr');
// Creating a public node with no special langcode, like when no language
// module enabled.
$node_public_no_language = $this
->drupalCreateNode(array(
'private' => FALSE,
));
$this
->assertTrue($node_public_no_language->langcode == Language::LANGCODE_NOT_SPECIFIED, 'Node created with not specified language.');
// Tests that access is granted if requested with no language.
$this
->assertNodeAccess($expected_node_access, $node_public_no_language, $web_user);
// Tests that access is not granted if requested with Hungarian language.
$this
->assertNodeAccess($expected_node_access_no_access, $node_public_no_language, $web_user, 'hu');
// There is no specific Catalan version of this node and Croatian is not
// even set up on the system in this scenario, so the user will not get
// access to these nodes.
$this
->assertNodeAccess($expected_node_access_no_access, $node_public_no_language, $web_user, 'ca');
$this
->assertNodeAccess($expected_node_access_no_access, $node_public_no_language, $web_user, 'hr');
// Reset the node access cache and turn on our test node_access() code.
drupal_static_reset('node_access');
variable_set('node_access_test_secret_catalan', 1);
// Tests that access is granted if requested with no language.
$this
->assertNodeAccess($expected_node_access, $node_public_no_language, $web_user);
// Tests that Hungarian is still not accessible.
$this
->assertNodeAccess($expected_node_access_no_access, $node_public_no_language, $web_user, 'hu');
// Tests that Catalan is still not accessible.
$this
->assertNodeAccess($expected_node_access_no_access, $node_public_no_language, $web_user, 'ca');
}