public function AuthcacheMenuTestItemTitle::testNodeViewLocalTask in Authenticated User Page Caching (Authcache) 7.2
Test local tasts on node-view.
File
- modules/
authcache_menu/ tests/ authcache_menu.test, line 190 - Test classes for Authcache Menu module.
Class
- AuthcacheMenuTestItemTitle
- Test personalization of menu item titles.
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 = 'client-tag-' . $this
->randomName(8);
$page = array(
'#markup' => 'page-markup-' . $this
->randomName(64),
);
$admin = $this
->drupalCreateUser(array(
'administer menu',
));
$this
->drupalLogin($admin);
// Create menu link in the main-menu
$main_menu_title = 'main-menu-' . $this
->randomName(8);
$edit = array(
'link_title' => $main_menu_title,
'link_path' => 'user',
'options[authcache]' => TRUE,
);
$this
->drupalPost('admin/structure/menu/manage/main-menu/add', $edit, t('Save'));
// Create menu link in the navigation-menu
$nav_menu_title = 'nav-menu-' . $this
->randomName(8);
$edit = array(
'link_title' => $nav_menu_title,
'link_path' => 'node',
'options[authcache]' => TRUE,
);
$this
->drupalPost('admin/structure/menu/manage/navigation/add', $edit, t('Save'));
$this
->drupalLogout();
$pagestub = $this->stubmod
->hook('page', $page);
$themestub = HookStub::on('theme_authcache_p13n_fragment__authcache_menu_test', $client_tag);
$this
->drupalGet('tab-root-std-access');
$this
->assertNoText($main_menu_title);
$this
->assertNoText($nav_menu_title);
$this
->assertText($client_tag);
$this
->assertText($page['#markup']);
$this
->assertStub($pagestub, HookStub::once());
$this
->assertStub($themestub, HookStub::times(2));
$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');
$this
->assertNoText($main_menu_title);
$this
->assertNoText($nav_menu_title);
$this
->assertText($client_tag);
$this
->assertText($page['#markup']);
$this
->assertStub($pagestub, HookStub::once());
$this
->assertStub($themestub, HookStub::times(2));
$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');
$this
->assertText($main_menu_title);
$this
->assertText($nav_menu_title);
$this
->assertNoText($client_tag);
$this
->assertText($page['#markup']);
$this
->assertStub($pagestub, HookStub::once());
$this
->assertStub($themestub, HookStub::never());
// Test menu item retrieval.
$url = authcache_p13n_request_get_callback('frag/menu-item-title', 'node');
$headers = array(
'X-Authcache: 1',
);
$this
->drupalGet($GLOBALS['base_root'] . $url['path'], $url['options'], $headers);
$this
->assertResponse(200);
$this
->assertText($nav_menu_title);
}