/** * 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); }
function createForum($id, $tag, $description, array $accesses) { $edit = array('name' => "Forum {$id} {$tag}", 'description' => $description, 'parent[0]' => 0, 'weight' => '0'); $forum = (object) ($edit + array('tid' => 2)); $edit["forum_access[grants][checkboxes][view][1]"] = FALSE; $edit["forum_access[grants][checkboxes][view][2]"] = FALSE; $edit["forum_access[grants][checkboxes][create][2]"] = FALSE; foreach (array($this->webmaster_rid, $this->forum_admin_rid, $this->edit_any_content_rid, $this->edit_own_content_rid, $this->create_content_rid, $this->admin_rid, $this->anon_rid, $this->auth_rid) as $rid) { foreach ($accesses as $access) { $key = "{$access}-{$rid}"; if (array_search($key, array('update-3', 'delete-3')) === FALSE) { $edit["forum_access[grants][checkboxes][{$access}][{$rid}]"] = TRUE; } } } $this->drupalPost('admin/structure/forum/add/forum', $edit, t('Save')); $this->assertResponse(200, "'{$forum->name}' added."); // Set moderator. $acl_id = _forum_access_get_acl($forum->tid); $this->assertNotNull($acl_id); acl_add_user($acl_id, $this->moderator->uid); $this->assertTrue(acl_has_user($acl_id, $this->moderator->uid), t('User %moderator is moderator.', array('%user' => $this->moderator->uid))); // Show the result. $this->drupalGet("admin/structure/forum/edit/forum/{$forum->tid}"); $this->assertResponse(200, "^^^ '{$forum->name}' exists, with these settings."); $this->drupalGet('forum'); $this->assertResponse(200, 'Forum Overview'); return $forum; }