View source
<?php
class AclWebTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'ACL access permissions',
'description' => 'Test ACL permissions for reading a node.',
'group' => 'ACL',
);
}
function setUp() {
parent::setUp('acl', 'acl_node_test');
$web_user = $this
->drupalCreateUser(array(
'create page content',
));
$this
->drupalLogin($web_user);
}
function testNodeAclCreateDelete() {
$node1 = $this
->drupalCreateNode(array(
'type' => 'page',
'promote' => 0,
));
$this
->assertTrue(node_load($node1->nid), t('Page node created.'));
acl_create_acl('test1', $node1->title);
$acl_id = acl_get_id_by_name('test1', $node1->title);
$this
->assertNotNull($acl_id, t('ACL ID was succesfully found.'), $group = 'ACL');
$records = db_query('SELECT acl_id, name FROM {acl} WHERE acl_id = :acl_id', array(
':acl_id' => $acl_id,
))
->fetchAll();
$this
->assertEqual(count($records), 1, t('ACL was succesfully created.'), $group = 'ACL');
acl_delete_acl($records[0]->acl_id);
$records = db_query('SELECT acl_id, name FROM {acl} WHERE acl_id = :acl_id', array(
':acl_id' => $records[0]->acl_id,
))
->fetchAll();
$this
->pass(var_export($records, TRUE));
$this
->assertEqual(count($records), 0, t('ACL was succesfully removed.'), $group = 'ACL');
}
function testNodeAclSingleUserAddRemove() {
$node1 = $this
->drupalCreateNode(array(
'type' => 'page',
'promote' => 0,
));
$this
->assertTrue(node_load($node1->nid), t('Page node created.'));
acl_create_acl('test2', $node1->title);
$acl_id = acl_get_id_by_name('test2', $node1->title);
$this
->assertNotNull($acl_id, t('ACL ID was succesfully found.'), $group = 'ACL');
$records = db_query('SELECT acl_id, name FROM {acl} WHERE acl_id = :acl_id', array(
':acl_id' => $acl_id,
))
->fetchAll();
$this
->assertEqual(count($records), 1, t('ACL was succesfully created.'), $group = 'ACL');
$web_user_1 = $this
->drupalCreateUser();
acl_add_user($acl_id, $web_user_1->uid);
$records = db_query('SELECT acl_id, uid FROM {acl_user} WHERE uid = :uid', array(
':uid' => $web_user_1->uid,
))
->fetchAll();
$this
->assertEqual(count($records), 1, t('User was succesfully added.'), $group = 'ACL');
acl_remove_user($acl_id, $web_user_1->uid);
$records = db_query('SELECT acl_id, uid FROM {acl_user} WHERE uid = :uid', array(
':uid' => $web_user_1->uid,
))
->fetchAll();
$this
->assertEqual(count($records), 0, t('User was succesfully removed.'), $group = 'ACL');
}
function testNodeAclAddRemoveFromNode() {
$node1 = $this
->drupalCreateNode(array(
'type' => 'page',
'promote' => 0,
));
$this
->assertTrue(node_load($node1->nid), t('Page node created.'));
$node2 = $this
->drupalCreateNode(array(
'type' => 'page',
'promote' => 0,
));
$this
->assertTrue(node_load($node2->nid), t('Page node created.'));
$node3 = $this
->drupalCreateNode(array(
'type' => 'page',
'promote' => 0,
));
$this
->assertTrue(node_load($node3->nid), t('Page node created.'));
$acl_id1 = acl_create_acl('test3', 'test', 1);
$this
->assertNotNull($acl_id1, t('ACL ID was created.'), $group = 'ACL');
$query = db_select('node', 'n')
->fields('n', array(
'nid',
))
->condition('nid', array(
$node1->nid,
$node2->nid,
), 'IN');
acl_add_nodes($query, $acl_id1, 1, 1, 1);
$count = db_query('SELECT COUNT(nid) FROM {acl_node} WHERE acl_id = :acl_id', array(
':acl_id' => $acl_id1,
))
->fetchField();
$this
->assertEqual($count, 2, t("2 nodes under control ({$count})."), $group = 'ACL');
acl_node_add_acl($node3->nid, $acl_id1, 1, 1, 1);
$count = db_query('SELECT COUNT(nid) FROM {acl_node} WHERE acl_id = :acl_id', array(
':acl_id' => $acl_id1,
))
->fetchField();
$this
->assertEqual($count, 3, t('3 nodes under control.'), $group = 'ACL');
acl_node_add_acl($node2->nid, $acl_id1, 1, 1, 1);
$count = db_query('SELECT COUNT(nid) FROM {acl_node} WHERE acl_id = :acl_id', array(
':acl_id' => $acl_id1,
))
->fetchField();
$this
->assertEqual($count, 3, t('Still only 3 nodes under control.'), $group = 'ACL');
acl_node_remove_acl($node2->nid, $acl_id1);
$count = db_query('SELECT COUNT(nid) FROM {acl_node} WHERE acl_id = :acl_id', array(
':acl_id' => $acl_id1,
))
->fetchField();
$this
->assertEqual($count, 2, t('2 nodes left under control.'), $group = 'ACL');
acl_node_remove_acl($node2->nid, $acl_id1);
$count = db_query('SELECT COUNT(nid) FROM {acl_node} WHERE acl_id = :acl_id', array(
':acl_id' => $acl_id1,
))
->fetchField();
$this
->assertEqual($count, 2, t('Still 2 nodes left under control.'), $group = 'ACL');
$acl_id2 = acl_create_acl('test3', 'test', 2);
$this
->assertNotNull($acl_id2, t('ACL ID was created.'), $group = 'ACL');
acl_node_add_acl($node1->nid, $acl_id2, 1, 1, 1);
acl_node_add_acl($node2->nid, $acl_id2, 1, 1, 1);
$count = db_query('SELECT COUNT(nid) FROM {acl_node} WHERE acl_id = :acl_id', array(
':acl_id' => $acl_id2,
))
->fetchField();
$this
->assertEqual($count, 2, t('2 nodes under control.'), $group = 'ACL');
acl_node_clear_acls($node1->nid, 'test3');
$count = db_query('SELECT COUNT(nid) FROM {acl_node} WHERE acl_id = :acl_id', array(
':acl_id' => $acl_id1,
))
->fetchField();
$this
->assertEqual($count, 1, t('1 node left under control.'), $group = 'ACL');
$count = db_query('SELECT COUNT(nid) FROM {acl_node} WHERE acl_id = :acl_id', array(
':acl_id' => $acl_id2,
))
->fetchField();
$this
->assertEqual($count, 1, t('1 node left under control.'), $group = 'ACL');
}
}
function testNodeAclAddAndRemoveNode() {
}
function testNodeAclAddAndRemoveUser() {
}
function testNodeAclPermissionCheck() {
}