function AclTest::testNodeAclSingleUserAddRemove in ACL 8
Includes acl_add_user, acl_remove_user, acl_has_users, acl_get_id_by_name, acl_has_user, acl_get_uids
File
- src/
Tests/ AclTest.php, line 89
Class
- AclTest
- Test case for ACL module.
Namespace
Drupal\acl\TestsCode
function testNodeAclSingleUserAddRemove() {
// Add a node.
$node1 = $this
->drupalCreateNode(array(
'type' => 'page',
'promote' => 0,
));
$this
->assertTrue((bool) Node::load($node1
->id()), t('Page node created.'));
acl_create_acl('test2', $node1
->getTitle());
// Check to see if grants added by node_test_node_access_records()
// made it in.
$acl_id = acl_get_id_by_name('test2', $node1
->getTitle());
$this
->assertNotNull($acl_id, t('ACL ID was successfully found.'), $group = 'ACL');
$records = \Drupal::database()
->select('acl')
->fields('acl', [
'acl_id',
'name',
])
->condition('acl_id', $acl_id)
->execute()
->fetchAll();
$this
->assertEqual(count($records), 1, t('ACL was succesfully created.'), $group = 'ACL');
// Add user (can't we use the user created in setup?).
$web_user_1 = $this
->drupalCreateUser();
//$this->drupalLogin($web_user);
acl_add_user($acl_id, $web_user_1
->id());
$records = \Drupal::database()
->select('acl_user')
->fields('acl_user', [
'acl_id',
'uid',
])
->condition('uid', $web_user_1
->id())
->execute()
->fetchAll();
// Verify user is added.
$this
->assertEqual(count($records), 1, t('User was successfully added.'), $group = 'ACL');
// Remove user.
acl_remove_user($acl_id, $web_user_1
->id());
$records = \Drupal::database()
->select('acl_user')
->fields('acl_user', [
'acl_id',
'uid',
])
->condition('uid', $web_user_1
->id())
->execute()
->fetchAll();
// Verify user is removed.
$this
->assertEqual(count($records), 0, t('User was successfully removed.'), $group = 'ACL');
}