public function ViewsNavigationTestCase::testViewsNavigation in Views navigation 7
File
- tests/
views_navigation.test, line 60 - Test class for Views Navigation.
Class
- ViewsNavigationTestCase
- Class ViewsNavigationTestCase
Code
public function testViewsNavigation() {
// Enable simple views navigation.
$view_edit_url = 'admin/structure/views/view/frontpage/edit';
$this
->drupalGet($view_edit_url);
$settings_link = reset($this
->xpath('//a[@id=:id]', [
':id' => 'views-page-views-navigation',
]));
$settings_url = $this
->getAbsoluteUrl($settings_link['href']);
$edit = [];
$edit['views_navigation'] = TRUE;
$this
->drupalPost($settings_url, $edit, 'Apply');
$this
->drupalPost($view_edit_url, [], 'Save');
// Check simple views navigation.
$this
->drupalGet('frontpage');
$node_links = $this
->xpath('//span[@class=:class]//a', [
':class' => 'field-content',
]);
$this
->clickLink((string) reset($node_links));
$this
->clickLink('Next');
$this
->assertTitle($node_links[1] . ' | Drupal', 'Next from first item leads to second item.');
$this
->clickLink('Next');
$this
->assertTitle($node_links[2] . ' | Drupal', 'Next from second item leads to third item.');
$this
->clickLink('Previous');
$this
->assertTitle($node_links[1] . ' | Drupal', 'Previous from third item leads to second item.');
$this
->drupalGet('frontpage');
$this
->clickLink((string) end($node_links));
$this
->clickLink('Next');
$last_title = (string) current($this
->xpath('//title'));
$this
->drupalGet($this
->getAbsoluteUrl('frontpage?page=1'));
$node_links1 = $this
->xpath('//span[@class=:class]//a', [
':class' => 'field-content',
]);
$this
->assertEqual($last_title, reset($node_links1) . ' | Drupal', 'Next from last item leads to first item of next page.');
$this
->clickLink((string) reset($node_links1));
$this
->clickLink('Previous');
$this
->assertTitle(end($node_links) . ' | Drupal', 'Previous from first item of second page leads to last item of first page.');
// Check several field handlers.
$edit = [];
// Simple link to the node.
$edit['name[views_entity_node.view_node]'] = TRUE;
// Node path (can be useful as a token).
$edit['name[node.path]'] = TRUE;
// We won't check image fields for now, it's much work.
$this
->drupalPost('admin/structure/views/nojs/add-item/frontpage/page/field', $edit, 'Add and configure fields');
$this
->drupalPost($this
->getUrl(), [], 'Apply');
$this
->drupalPost($this
->getUrl(), [], 'Apply');
$this
->drupalPost($view_edit_url, [], 'Save');
// Check they work.
$this
->drupalGet('frontpage');
$node_paths = $this
->xpath('//div[@class=:class1]/span[@class=:class2]', [
':class1' => 'views-field views-field-path',
':class2' => 'field-content',
]);
$this
->verbose(print_r($node_paths, 1));
$this
->clickLink('view');
$this
->assertLink('Next', 0, 'The simple node view link field is correctly handled.');
$this
->drupalGet($this
->getAbsoluteUrl(reset($node_paths)));
$this
->assertLink('Next', 0, 'The node path field is correctly handled.');
// Check back link with and without view's title.
$edit = [];
$edit['views_navigation_back'] = TRUE;
$this
->drupalPost($settings_url, $edit, 'Apply');
$this
->drupalPost($view_edit_url, [], 'Save');
$this
->drupalGet('frontpage');
$node_links = $this
->xpath('//span[@class=:class]//a', [
':class' => 'field-content',
]);
$this
->clickLink((string) reset($node_links));
$this
->clickLink('Back');
$this
->assertUrl('frontpage', [], "Back link from a first page's result leads back to the first view page.");
$this
->drupalGet($this
->getAbsoluteUrl('frontpage?page=1'));
$node_links1 = $this
->xpath('//span[@class=:class]//a', [
':class' => 'field-content',
]);
$this
->clickLink((string) reset($node_links1));
$this
->clickLink('Back');
$this
->assertUrl('frontpage', [], "Back link from a second page's result leads back to the first view page.");
$edit = [];
$edit['views_navigation_title'] = TRUE;
$this
->drupalPost($settings_url, $edit, 'Apply');
$edit = [];
$edit['title'] = 'My beautiful view';
$this
->drupalPost('admin/structure/views/nojs/display/frontpage/page/title', $edit, 'Apply');
$this
->drupalPost($view_edit_url, [], 'Save');
$this
->drupalGet('frontpage');
$node_links = $this
->xpath('//span[@class=:class]//a', [
':class' => 'field-content',
]);
$this
->clickLink((string) reset($node_links));
$back_links = $this
->xpath('//a[normalize-space(string())=:text]', [
':text' => 'Back to My beautiful view',
]);
$url_target = $this
->getAbsoluteUrl($back_links[0]['href']);
$this
->drupalGet($url_target);
$this
->assertUrl('frontpage', [], "Back link with view's title works too.");
// Check cycling navigation.
$edit = [];
$edit['views_navigation_cycle'] = TRUE;
$this
->drupalPost($settings_url, $edit, 'Apply');
$this
->drupalPost($view_edit_url, [], 'Save');
$this
->drupalGet('frontpage');
$node_links = $this
->xpath('//span[@class=:class]//a', [
':class' => 'field-content',
]);
$this
->clickLink((string) reset($node_links));
$first_title = (string) current($this
->xpath('//title'));
$this
->drupalGet($this
->getAbsoluteUrl('frontpage?page=1'));
$node_links = $this
->xpath('//span[@class=:class]//a', [
':class' => 'field-content',
]);
$this
->clickLink((string) end($node_links));
$this
->clickLink('Next');
$this
->assertEqual($first_title, (string) current($this
->xpath('//title')), 'Next from last item of last page leads to first item of first page when cycling is on.');
// Same checks in SEO mode. Reset the view.
$edit = [];
$edit['views_navigation_seo_first'] = TRUE;
$edit['views_navigation_back'] = FALSE;
$edit['views_navigation_title'] = FALSE;
$edit['views_navigation_cycle'] = FALSE;
$this
->drupalPost($settings_url, $edit, 'Apply');
$this
->drupalPost('admin/structure/views/nojs/config-item/frontpage/page/field/view_node', [], 'Remove');
$this
->drupalPost('admin/structure/views/nojs/config-item/frontpage/page/field/path', [], 'Remove');
$this
->drupalPost($view_edit_url, [], 'Save');
$this
->drupalGet('frontpage');
$node_links = $this
->xpath('//span[@class=:class]//a', [
':class' => 'field-content',
]);
$this
->clickLink((string) reset($node_links));
$this
->clickLink((string) $node_links[1]);
$this
->assertTitle($node_links[1] . ' | Drupal', "Second item's title as a link from first item leads to second item.");
$this
->clickLink((string) $node_links[2]);
$this
->assertTitle($node_links[2] . ' | Drupal', "Third item's title as a link from second item leads to third item.");
$this
->clickLink((string) $node_links[1]);
$this
->assertTitle($node_links[1] . ' | Drupal', "Second item's title as a link from third item leads to second item.");
$this
->drupalGet($this
->getAbsoluteUrl('frontpage?page=1'));
$node_links1 = $this
->xpath('//span[@class=:class]//a', [
':class' => 'field-content',
]);
$last_title = (string) reset($node_links1);
$this
->drupalGet('frontpage');
$this
->clickLink((string) end($node_links));
$this
->clickLink($last_title);
$this
->assertEqual((string) current($this
->xpath('//title')), $last_title . ' | Drupal', 'A link from last item leads to first item of next page.');
$this
->drupalGet($this
->getAbsoluteUrl('frontpage?page=1'));
$this
->clickLink((string) reset($node_links1));
$this
->clickLink((string) end($node_links));
$this
->assertTitle(end($node_links) . ' | Drupal', 'A link from first item of second page leads to last item of first page.');
// Check several field handlers.
$edit = [];
// Simple link to the node.
$edit['name[views_entity_node.view_node]'] = TRUE;
// Node path (can be useful as a token).
$edit['name[node.path]'] = TRUE;
// We won't check image fields for now, it's much work.
$this
->drupalPost('admin/structure/views/nojs/add-item/frontpage/page/field', $edit, 'Add and configure fields');
$this
->drupalPost($this
->getUrl(), [], 'Apply');
$this
->drupalPost($this
->getUrl(), [], 'Apply');
$this
->drupalPost($view_edit_url, [], 'Save');
// Check they work.
$this
->drupalGet('frontpage');
$node_paths = $this
->xpath('//div[@class=:class1]/span[@class=:class2]', [
':class1' => 'views-field views-field-path',
':class2' => 'field-content',
]);
$this
->verbose(print_r($node_paths, 1));
$this
->clickLink('view');
$this
->assertLink((string) $node_links[1], 0, 'The simple node view link field is correctly handled.');
$this
->drupalGet($this
->getAbsoluteUrl(reset($node_paths)));
$this
->assertLink((string) $node_links[1], 0, 'The node path field is correctly handled.');
// Check back link with and without view's title.
$edit = [];
$edit['views_navigation_back'] = TRUE;
$this
->drupalPost($settings_url, $edit, 'Apply');
$this
->drupalPost($view_edit_url, [], 'Save');
$this
->drupalGet('frontpage');
$node_links = $this
->xpath('//span[@class=:class]//a', [
':class' => 'field-content',
]);
$this
->clickLink((string) reset($node_links));
$this
->clickLink('Back');
$this
->assertUrl('frontpage', [], "Back link from a first page's result leads back to the first view page.");
$this
->drupalGet($this
->getAbsoluteUrl('frontpage?page=1'));
$node_links1 = $this
->xpath('//span[@class=:class]//a', [
':class' => 'field-content',
]);
$this
->clickLink((string) reset($node_links1));
$this
->clickLink('Back');
$this
->assertUrl('frontpage', [], "Back link from a second page's result leads back to the first view page.");
$edit = [];
$edit['views_navigation_title'] = TRUE;
$this
->drupalPost($settings_url, $edit, 'Apply');
$edit = [];
$edit['title'] = 'My beautiful view';
$this
->drupalPost('admin/structure/views/nojs/display/frontpage/page/title', $edit, 'Apply');
$this
->drupalPost($view_edit_url, [], 'Save');
$this
->drupalGet('frontpage');
$node_links = $this
->xpath('//span[@class=:class]//a', [
':class' => 'field-content',
]);
$this
->clickLink((string) reset($node_links));
$back_links = $this
->xpath('//a[normalize-space(string())=:text]', [
':text' => 'Back to My beautiful view',
]);
$url_target = $this
->getAbsoluteUrl($back_links[0]['href']);
$this
->drupalGet($url_target);
$this
->assertUrl('frontpage', [], "Back link with view's title works too.");
// Check cycling navigation.
$edit = [];
$edit['views_navigation_cycle'] = TRUE;
$this
->drupalPost($settings_url, $edit, 'Apply');
$this
->drupalPost($view_edit_url, [], 'Save');
$this
->drupalGet('frontpage');
$node_links = $this
->xpath('//span[@class=:class]//a', [
':class' => 'field-content',
]);
$this
->clickLink((string) reset($node_links));
$first_title = (string) current($this
->xpath('//title'));
$this
->drupalGet($this
->getAbsoluteUrl('frontpage?page=1'));
$node_links1 = $this
->xpath('//span[@class=:class]//a', [
':class' => 'field-content',
]);
$this
->clickLink((string) end($node_links1));
$this
->clickLink((string) reset($node_links));
$this
->assertEqual($first_title, (string) current($this
->xpath('//title')), 'A link from last item of last page leads to first item of first page when cycling is on.');
}