public function AuthcacheTestAdminWidgets::testRoleRestrictWidget in Authenticated User Page Caching (Authcache) 7.2
Test role restrict widget.
File
- tests/
authcache.widget.test, line 219 - Test cases for pluggable cache backends.
Class
- AuthcacheTestAdminWidgets
- Cover authcache module.
Code
public function testRoleRestrictWidget() {
$form = system_settings_form(array(
'authcache_widget_test_roles' => array(
'#title' => $this
->randomName(8),
'#type' => 'authcache_role_restrict',
),
));
$form_stub = $this->stubmod
->hook('form', $form);
$this
->drupalGet('authcache-widget-test-form');
$this
->assertStub($form_stub, HookStub::once());
$this
->assertNoText('Currently there are no roles enabled for authcache');
$this
->assertNoLink('authcache settings');
$this
->assertNoFieldChecked('edit-authcache-widget-test-roles-custom');
$roles = user_roles();
$expected_roles = $this->authcacheRoles;
foreach ($roles as $rid => $name) {
if (in_array($rid, $expected_roles)) {
$this
->assertFieldChecked('edit-authcache-widget-test-roles-roles-' . $rid);
$this
->assertText($name);
}
else {
$this
->assertNoText($name);
}
}
// Enable role restriction.
$edit = array(
'authcache_widget_test_roles[custom]' => TRUE,
);
$expect = array(
'custom' => 1,
'roles' => drupal_map_assoc(array_keys($this->authcacheRoles)),
);
$this
->drupalPost(NULL, $edit, t('Save configuration'));
$actual = variable_get('authcache_widget_test_roles');
$this
->assertEqual($expect, $actual);
// Exclude anonymous users.
$edit = array(
'authcache_widget_test_roles[custom]' => TRUE,
'authcache_widget_test_roles[roles][1]' => FALSE,
);
$roles = drupal_map_assoc(array_keys($this->authcacheRoles));
unset($roles[1]);
$expect = array(
'custom' => 1,
'roles' => $roles,
);
$this
->drupalPost(NULL, $edit, t('Save configuration'));
$actual = variable_get('authcache_widget_test_roles');
$this
->assertEqual($expect, $actual);
// Disable all roles.
$edit = array(
'authcache_widget_test_roles[custom]' => TRUE,
);
foreach ($this->authcacheRoles as $rid) {
$edit['authcache_widget_test_roles[roles][' . $rid . ']'] = FALSE;
}
$expect = array(
'custom' => 1,
'roles' => array(),
);
$this
->drupalPost(NULL, $edit, t('Save configuration'));
$actual = variable_get('authcache_widget_test_roles');
$this
->assertEqual($expect, $actual);
// Disable role restriction.
$edit = array(
'authcache_widget_test_roles[custom]' => FALSE,
);
$this
->drupalPost(NULL, $edit, t('Save configuration'));
$actual = variable_get('authcache_widget_test_roles');
$this
->assertNull($actual);
}