public function TaxonomyAccessConfigTest::testTermConfig in Taxonomy Access Control 7
Tests configuring specific terms.
Verifies that:
- Access is updated correctly when the term configuration is added.
- Access is updated correctly when there is a vocabulary default.
- Access is updated correctly when multiple configurations are changed.
- Access is updated correctly when the term configuration is deleted.
File
- ./
taxonomy_access.test, line 807 - Automated tests for the Taxonomy Access Control module.
Class
- TaxonomyAccessConfigTest
- Tests the module's configuration forms.
Code
public function testTermConfig() {
// Log in as the administrator.
$this
->drupalLogin($this->users['site_admin']);
// Use the admin form to enable v1 and give anonymous view allow for v1t1.
$this
->drupalGet(TAXONOMY_ACCESS_CONFIG . '/role/' . DRUPAL_ANONYMOUS_RID . '/edit');
$edit = array();
$edit['enable_vocab'] = $this->vocabs['v1']->vid;
$this
->drupalPost(NULL, $edit, t('Add'));
$edit = array();
$this
->addFormRow($edit, $this->vocabs['v1']->vid, $this->terms['v1t1']->tid, TAXONOMY_ACCESS_NODE_ALLOW);
$this
->drupalPost(NULL, $edit, 'Add');
// Log out.
$this
->drupalLogout();
// Visit each page and verify whether access is allowed or denied.
foreach ($this->pages as $key => $page) {
$this
->drupalGet('node/' . $page->nid);
// If the page is tagged with v1t1, access should be allowed.
if (strpos($key, 'v1t1') !== FALSE) {
$this
->assertResponse(200, t("Access to %name page (nid %nid) is allowed.", array(
'%name' => $key,
'%nid' => $page->nid,
)));
}
else {
$this
->assertResponse(403, t("Access to %name page (nid %nid) is denied.", array(
'%name' => $key,
'%nid' => $page->nid,
)));
}
}
// Enable v2 programmatically.
taxonomy_access_enable_vocab($this->vocabs['v2']->vid, DRUPAL_ANONYMOUS_RID);
// Log in as the administrator.
$this
->drupalLogin($this->users['site_admin']);
// Use the admin form to give anonymous view deny for v2t1.
$this
->drupalGet(TAXONOMY_ACCESS_CONFIG . '/role/' . DRUPAL_ANONYMOUS_RID . '/edit');
$edit = array();
$this
->addFormRow($edit, $this->vocabs['v2']->vid, $this->terms['v2t1']->tid, TAXONOMY_ACCESS_NODE_DENY);
$this
->drupalPost(NULL, $edit, 'Add');
// Log out.
$this
->drupalLogout();
// Visit each page and verify whether access is allowed or denied.
foreach ($this->pages as $key => $page) {
$this
->drupalGet('node/' . $page->nid);
switch (TRUE) {
// If the page is tagged with v2t1, access should be denied.
case strpos($key, 'v2t1') !== FALSE:
$this
->assertResponse(403, t("Access to %name page (nid %nid) is denied.", array(
'%name' => $key,
'%nid' => $page->nid,
)));
break;
// Otherwise, if the page is tagged with v1t1, it's allowed.
case strpos($key, 'v1t1') !== FALSE:
$this
->assertResponse(200, t("Access to %name page (nid %nid) is allowed.", array(
'%name' => $key,
'%nid' => $page->nid,
)));
break;
// Access should be denied by default.
default:
$this
->assertResponse(403, t("Access to %name page (nid %nid) is denied.", array(
'%name' => $key,
'%nid' => $page->nid,
)));
break;
}
}
// Log in as the administrator.
$this
->drupalLogin($this->users['site_admin']);
// Use the form to change the configuration: Allow for v2t1; Deny for v1t1.
$this
->drupalGet(TAXONOMY_ACCESS_CONFIG . '/role/' . DRUPAL_ANONYMOUS_RID . '/edit');
$edit = array();
$this
->configureFormRow($edit, $this->vocabs['v2']->vid, $this->terms['v2t1']->tid, TAXONOMY_ACCESS_NODE_ALLOW);
$this
->configureFormRow($edit, $this->vocabs['v1']->vid, $this->terms['v1t1']->tid, TAXONOMY_ACCESS_NODE_DENY);
$this
->drupalPost(NULL, $edit, 'Save all');
// Log out.
$this
->drupalLogout();
// Visit each page and verify whether access is allowed or denied.
foreach ($this->pages as $key => $page) {
$this
->drupalGet('node/' . $page->nid);
switch (TRUE) {
// If the page is tagged with v1t1, access should be denied.
case strpos($key, 'v1t1') !== FALSE:
$this
->assertResponse(403, t("Access to %name page (nid %nid) is denied.", array(
'%name' => $key,
'%nid' => $page->nid,
)));
break;
// Otherwise, if the page is tagged with v2t1, it's allowed.
case strpos($key, 'v2t1') !== FALSE:
$this
->assertResponse(200, t("Access to %name page (nid %nid) is allowed.", array(
'%name' => $key,
'%nid' => $page->nid,
)));
break;
// Access should be denied by default.
default:
$this
->assertResponse(403, t("Access to %name page (nid %nid) is denied.", array(
'%name' => $key,
'%nid' => $page->nid,
)));
break;
}
}
// Log in as the administrator.
$this
->drupalLogin($this->users['site_admin']);
// Use the form to delete the v2t1 configuration.
$this
->drupalGet(TAXONOMY_ACCESS_CONFIG . '/role/' . DRUPAL_ANONYMOUS_RID . '/edit');
$edit = array();
$edit["grants[{$this->vocabs['v2']->vid}][{$this->terms['v2t1']->tid}][remove]"] = 1;
$this
->drupalPost(NULL, $edit, 'Delete selected');
// Log out.
$this
->drupalLogout();
// Visit each page and verify whether access is allowed or denied.
foreach ($this->pages as $key => $page) {
$this
->drupalGet('node/' . $page->nid);
// Access to all pages should be denied.
$this
->assertResponse(403, t("Access to %name page (nid %nid) is denied.", array(
'%name' => $key,
'%nid' => $page->nid,
)));
}
}