/** * Includes acl_add_user, acl_remove_user, acl_has_users, * acl_get_id_by_name, acl_has_user, acl_get_uids */ function testNodeAclSingleUserAddRemove() { // Add a node. $node1 = $this->drupalCreateNode(array('type' => 'page', 'promote' => 0)); $this->assertTrue(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 = 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'); // 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 = db_query('SELECT acl_id, uid FROM {acl_user} WHERE uid = :uid', array(':uid' => $web_user_1->id()))->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 = db_query('SELECT acl_id, uid FROM {acl_user} WHERE uid = :uid', array(':uid' => $web_user_1->id()))->fetchAll(); // Verify user is removed. $this->assertEqual(count($records), 0, t('User was successfully removed.'), $group = 'ACL'); }
/** * Tests migration of ACL List. */ public function testMigration() { // Checking `number` to `figure` migration. $acl_id = acl_get_id_by_name('acl_node_test', 'test_name', 123); $this->assertNotEqual($acl_id, FALSE); // One more check. $acl_id = acl_get_id_by_figure('acl_node_test', 5); $this->assertEqual($acl_id, 2); // Testing `acl_user` migration. $this->assertEqual(acl_has_user(1, 1), TRUE); $this->assertEqual(acl_has_user(2, 1), TRUE); $this->assertEqual(acl_has_user(1, 2), TRUE); $this->assertNotEqual(acl_has_user(2, 2), TRUE); // Testing first migrated node grants. $node = Node::load(1); $grants = \Drupal::entityManager()->getAccessControlHandler('node')->acquireGrants($node); $acl_grant_exists = FALSE; foreach ($grants as $grant) { if ($grant['realm'] == 'acl' && $grant['grant_update'] == TRUE && $grant['priority'] == 5) { $acl_grant_exists = TRUE; } } $this->assertEqual($acl_grant_exists, TRUE); // Testing second migrated node grants. $node = Node::load(2); $grants = \Drupal::entityManager()->getAccessControlHandler('node')->acquireGrants($node); $acl_grant_count = 0; foreach ($grants as $grant) { if ($grant['realm'] == 'acl') { if ($grant['grant_view'] == TRUE && $grant['grant_delete'] == TRUE && $grant['priority'] == 10) { $acl_grant_count++; } if ($grant['grant_view'] == TRUE && $grant['grant_update'] == TRUE && $grant['priority'] == 8) { $acl_grant_count++; } } } $this->assertEqual($acl_grant_count, 2); }