public function PreviewTest::testPreviewWithPagersUI in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/views_ui/src/Tests/PreviewTest.php \Drupal\views_ui\Tests\PreviewTest::testPreviewWithPagersUI()
Tests pagers in the preview form.
File
- core/
modules/ views_ui/ src/ Tests/ PreviewTest.php, line 110 - Contains \Drupal\views_ui\Tests\PreviewTest.
Class
- PreviewTest
- Tests the UI preview functionality.
Namespace
Drupal\views_ui\TestsCode
public function testPreviewWithPagersUI() {
// Create 11 nodes and make sure that everyone is returned.
$this
->drupalCreateContentType(array(
'type' => 'page',
));
for ($i = 0; $i < 11; $i++) {
$this
->drupalCreateNode();
}
// Test Full Pager.
$this
->getPreviewAJAX('test_pager_full', 'default', 5);
// Test that the pager is present and rendered.
$elements = $this
->xpath('//ul[contains(@class, :class)]/li', array(
':class' => 'pager__items',
));
$this
->assertTrue(!empty($elements), 'Full pager found.');
// Verify elements and links to pages.
// We expect to find 5 elements: current page == 1, links to pages 2 and
// and 3, links to 'next >' and 'last >>' pages.
$this
->assertClass($elements[0], 'is-active', 'Element for current page has .is-active class.');
$this
->assertTrue($elements[0]->a, 'Element for current page has link.');
$this
->assertClass($elements[1], 'pager__item', 'Element for page 2 has .pager__item class.');
$this
->assertTrue($elements[1]->a, 'Link to page 2 found.');
$this
->assertClass($elements[2], 'pager__item', 'Element for page 3 has .pager__item class.');
$this
->assertTrue($elements[2]->a, 'Link to page 3 found.');
$this
->assertClass($elements[3], 'pager__item--next', 'Element for next page has .pager__item--next class.');
$this
->assertTrue($elements[3]->a, 'Link to next page found.');
$this
->assertClass($elements[4], 'pager__item--last', 'Element for last page has .pager__item--last class.');
$this
->assertTrue($elements[4]->a, 'Link to last page found.');
// Navigate to next page.
$elements = $this
->xpath('//li[contains(@class, :class)]/a', array(
':class' => 'pager__item--next',
));
$this
->clickPreviewLinkAJAX($elements[0]['href'], 5);
// Test that the pager is present and rendered.
$elements = $this
->xpath('//ul[contains(@class, :class)]/li', array(
':class' => 'pager__items',
));
$this
->assertTrue(!empty($elements), 'Full pager found.');
// Verify elements and links to pages.
// We expect to find 7 elements: links to '<< first' and '< previous'
// pages, link to page 1, current page == 2, link to page 3 and links
// to 'next >' and 'last >>' pages.
$this
->assertClass($elements[0], 'pager__item--first', 'Element for first page has .pager__item--first class.');
$this
->assertTrue($elements[0]->a, 'Link to first page found.');
$this
->assertClass($elements[1], 'pager__item--previous', 'Element for previous page has .pager__item--previous class.');
$this
->assertTrue($elements[1]->a, 'Link to previous page found.');
$this
->assertClass($elements[2], 'pager__item', 'Element for page 1 has .pager__item class.');
$this
->assertTrue($elements[2]->a, 'Link to page 1 found.');
$this
->assertClass($elements[3], 'is-active', 'Element for current page has .is-active class.');
$this
->assertTrue($elements[3]->a, 'Element for current page has link.');
$this
->assertClass($elements[4], 'pager__item', 'Element for page 3 has .pager__item class.');
$this
->assertTrue($elements[4]->a, 'Link to page 3 found.');
$this
->assertClass($elements[5], 'pager__item--next', 'Element for next page has .pager__item--next class.');
$this
->assertTrue($elements[5]->a, 'Link to next page found.');
$this
->assertClass($elements[6], 'pager__item--last', 'Element for last page has .pager__item--last class.');
$this
->assertTrue($elements[6]->a, 'Link to last page found.');
// Test Mini Pager.
$this
->getPreviewAJAX('test_mini_pager', 'default', 3);
// Test that the pager is present and rendered.
$elements = $this
->xpath('//ul[contains(@class, :class)]/li', array(
':class' => 'pager__items',
));
$this
->assertTrue(!empty($elements), 'Mini pager found.');
// Verify elements and links to pages.
// We expect to find current pages element with no link, next page element
// with a link, and not to find previous page element.
$this
->assertClass($elements[0], 'is-active', 'Element for current page has .is-active class.');
$this
->assertClass($elements[1], 'pager__item--next', 'Element for next page has .pager__item--next class.');
$this
->assertTrue($elements[1]->a, 'Link to next page found.');
// Navigate to next page.
$elements = $this
->xpath('//li[contains(@class, :class)]/a', array(
':class' => 'pager__item--next',
));
$this
->clickPreviewLinkAJAX($elements[0]['href'], 3);
// Test that the pager is present and rendered.
$elements = $this
->xpath('//ul[contains(@class, :class)]/li', array(
':class' => 'pager__items',
));
$this
->assertTrue(!empty($elements), 'Mini pager found.');
// Verify elements and links to pages.
// We expect to find 3 elements: previous page with a link, current
// page with no link, and next page with a link.
$this
->assertClass($elements[0], 'pager__item--previous', 'Element for previous page has .pager__item--previous class.');
$this
->assertTrue($elements[0]->a, 'Link to previous page found.');
$this
->assertClass($elements[1], 'is-active', 'Element for current page has .is-active class.');
$this
->assertFalse(isset($elements[1]->a), 'Element for current page has no link.');
$this
->assertClass($elements[2], 'pager__item--next', 'Element for next page has .pager__item--next class.');
$this
->assertTrue($elements[2]->a, 'Link to next page found.');
}