public function AuthcacheMenuTestLocalTasks::testNodeViewLocalTask in Authenticated User Page Caching (Authcache) 7.2
Test local tasts on node-view.
File
- modules/
authcache_menu/ tests/ authcache_menu.test, line 54 - Test classes for Authcache Menu module.
Class
- AuthcacheMenuTestLocalTasks
- Test personalization of local tasks and action links.
Code
public function testNodeViewLocalTask() {
$user = $this
->drupalCreateUser();
// Turn on authcache for all user roles.
variable_set('authcache_roles', drupal_map_assoc(array_keys(user_roles())));
// Register markup substitution client.
$clients = array(
'authcache_menu_test' => array(
'title' => 'Authcache menu test stub',
'enabled' => TRUE,
),
);
$this->stubmod
->hook('authcache_p13n_client', $clients);
$client_tag = $this
->randomName(8);
$page = array(
'#markup' => $this
->randomName(64),
);
$pagestub = $this->stubmod
->hook('page', $page);
$themestub = HookStub::on('theme_authcache_p13n_fragment__authcache_menu_test', $client_tag);
$this
->drupalGet('tab-root-std-access/view');
$this
->assertNoText($client_tag);
$this
->assertText($page['#markup']);
$this
->assertStub($pagestub, HookStub::once());
$this
->assertStub($themestub, HookStub::never());
// Do not personalize when no user is logged in.
$pagestub = $this->stubmod
->hook('page', $page);
$themestub = HookStub::on('theme_authcache_p13n_fragment__authcache_menu_test', $client_tag);
$this
->drupalGet('tab-root-cust-access/view');
$this
->assertNoText($client_tag);
$this
->assertText($page['#markup']);
$this
->assertStub($pagestub, HookStub::once());
$this
->assertStub($themestub, HookStub::never());
$this
->drupalLogin($user);
$pagestub = $this->stubmod
->hook('page', $page);
$themestub = HookStub::on('theme_authcache_p13n_fragment__authcache_menu_test', $client_tag);
$this
->drupalGet('tab-root-std-access/view');
$this
->assertNoText($client_tag);
$this
->assertText($page['#markup']);
$this
->assertStub($pagestub, HookStub::once());
$this
->assertStub($themestub, HookStub::never());
$pagestub = $this->stubmod
->hook('page', $page);
$themestub = HookStub::on('theme_authcache_p13n_fragment__authcache_menu_test', $client_tag);
$this
->drupalGet('tab-root-cust-access/view');
$this
->assertText($client_tag);
$this
->assertText($page['#markup']);
$this
->assertStub($pagestub, HookStub::once());
$this
->assertStub($themestub, HookStub::once());
$admin = $this
->drupalCreateUser(array(
'bypass node access',
));
$this
->drupalLogin($admin);
$pagestub = $this->stubmod
->hook('page', $page);
$themestub = HookStub::on('theme_authcache_p13n_fragment__authcache_menu_test', $client_tag);
$this
->drupalGet('tab-root-std-access/view');
$this
->assertNoText($client_tag);
$this
->assertText($page['#markup']);
$this
->assertStub($pagestub, HookStub::once());
$this
->assertStub($themestub, HookStub::never());
$pagestub = $this->stubmod
->hook('page', $page);
$themestub = HookStub::on('theme_authcache_p13n_fragment__authcache_menu_test', $client_tag);
$this
->drupalGet('tab-root-cust-access/view');
$this
->assertNoText($client_tag);
$this
->assertText($page['#markup']);
$this
->assertStub($pagestub, HookStub::once());
$this
->assertStub($themestub, HookStub::never());
$this
->drupalLogout();
// Test menu item retrieval
// FIXME: There is no way to override default parameters like 'q' when
// generating request urls. Probably we should fix that.
$orig_q = $_GET['q'];
$_GET['q'] = 'tab-root-std-access';
$url = authcache_p13n_request_get_callback('frag/menu-local-tabs', '');
$_GET['q'] = $orig_q;
$headers = array(
'X-Authcache: 1',
);
$this
->drupalGet($GLOBALS['base_root'] . $url['path'], $url['options'], $headers);
$this
->assertResponse(200);
$this
->assertText('View');
$this
->assertText('Edit');
}