summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--includes/pager.inc8
-rw-r--r--modules/simpletest/simpletest.info1
-rw-r--r--modules/simpletest/tests/pager.test159
3 files changed, 167 insertions, 1 deletions
diff --git a/includes/pager.inc b/includes/pager.inc
index a5d3e6be0..c060d0e7c 100644
--- a/includes/pager.inc
+++ b/includes/pager.inc
@@ -630,7 +630,13 @@ function theme_pager_link($variables) {
}
}
- return l($text, $_GET['q'], array('attributes' => $attributes, 'query' => $query));
+ // @todo l() cannot be used here, since it adds an 'active' class based on the
+ // path only (which is always the current path for pager links). Apparently,
+ // none of the pager links is active at any time - but it should still be
+ // possible to use l() here.
+ // @see http://drupal.org/node/1410574
+ $attributes['href'] = url($_GET['q'], array('query' => $query));
+ return '<a' . drupal_attributes($attributes) . '>' . check_plain($text) . '</a>';
}
/**
diff --git a/modules/simpletest/simpletest.info b/modules/simpletest/simpletest.info
index a07e29a45..6a02cf965 100644
--- a/modules/simpletest/simpletest.info
+++ b/modules/simpletest/simpletest.info
@@ -27,6 +27,7 @@ files[] = tests/lock.test
files[] = tests/mail.test
files[] = tests/menu.test
files[] = tests/module.test
+files[] = tests/pager.test
files[] = tests/password.test
files[] = tests/path.test
files[] = tests/registry.test
diff --git a/modules/simpletest/tests/pager.test b/modules/simpletest/tests/pager.test
new file mode 100644
index 000000000..30695c30e
--- /dev/null
+++ b/modules/simpletest/tests/pager.test
@@ -0,0 +1,159 @@
+<?php
+
+/**
+ * @file
+ * Tests for pager functionality.
+ */
+
+/**
+ * Tests pager functionality.
+ */
+class PagerFunctionalWebTestCase extends DrupalWebTestCase {
+ protected $profile = 'testing';
+
+ public static function getInfo() {
+ return array(
+ 'name' => 'Pager functionality',
+ 'description' => 'Tests pager functionality.',
+ 'group' => 'Pager',
+ );
+ }
+
+ function setUp() {
+ parent::setUp(array('dblog'));
+
+ // Insert 300 log messages.
+ for ($i = 0; $i < 300; $i++) {
+ watchdog('pager_test', $this->randomString(), NULL, WATCHDOG_DEBUG);
+ }
+
+ $this->admin_user = $this->drupalCreateUser(array(
+ 'access site reports',
+ ));
+ $this->drupalLogin($this->admin_user);
+ }
+
+ /**
+ * Tests markup and CSS classes of pager links.
+ */
+ function testActiveClass() {
+ // Verify first page.
+ $this->drupalGet('admin/reports/dblog');
+ $current_page = 0;
+ $this->assertPagerItems($current_page);
+
+ // Verify any page but first/last.
+ $current_page++;
+ $this->drupalGet('admin/reports/dblog', array('query' => array('page' => $current_page)));
+ $this->assertPagerItems($current_page);
+
+ // Verify last page.
+ $elements = $this->xpath('//li[contains(@class, :class)]/a', array(':class' => 'pager-last'));
+ preg_match('@page=(\d+)@', $elements[0]['href'], $matches);
+ $current_page = (int) $matches[1];
+ $this->drupalGet($GLOBALS['base_url'] . $elements[0]['href'], array('external' => TRUE));
+ $this->assertPagerItems($current_page);
+ }
+
+ /**
+ * Asserts pager items and links.
+ *
+ * @param int $current_page
+ * The current pager page the internal browser is on.
+ */
+ protected function assertPagerItems($current_page) {
+ $elements = $this->xpath('//ul[@class=:class]/li', array(':class' => 'pager'));
+ $this->assertTrue(!empty($elements), 'Pager found.');
+
+ // Make current page 1-based.
+ $current_page++;
+
+ // Extract first/previous and next/last items.
+ // first/previous only exist, if the current page is not the first.
+ if ($current_page > 1) {
+ $first = array_shift($elements);
+ $previous = array_shift($elements);
+ }
+ // next/last always exist, unless the current page is the last.
+ if ($current_page != count($elements)) {
+ $last = array_pop($elements);
+ $next = array_pop($elements);
+ }
+
+ // Verify items and links to pages.
+ foreach ($elements as $page => $element) {
+ // Make item/page index 1-based.
+ $page++;
+ if ($current_page == $page) {
+ $this->assertClass($element, 'pager-current', 'Item for current page has .pager-current class.');
+ $this->assertFalse(isset($element->a), 'Item for current page has no link.');
+ }
+ else {
+ $this->assertNoClass($element, 'pager-current', "Item for page $page has no .pager-current class.");
+ $this->assertClass($element, 'pager-item', "Item for page $page has .pager-item class.");
+ $this->assertTrue($element->a, "Link to page $page found.");
+ $this->assertNoClass($element->a, 'active', "Link to page $page is not active.");
+ }
+ unset($elements[--$page]);
+ }
+ // Verify that no other items remain untested.
+ $this->assertTrue(empty($elements), 'All expected items found.');
+
+ // Verify first/previous and next/last items and links.
+ if (isset($first)) {
+ $this->assertClass($first, 'pager-first', "Item for first page has .pager-first class.");
+ $this->assertTrue($first->a, "Link to first page found.");
+ $this->assertNoClass($first->a, 'active', "Link to first page is not active.");
+ }
+ if (isset($previous)) {
+ $this->assertClass($previous, 'pager-previous', "Item for first page has .pager-previous class.");
+ $this->assertTrue($previous->a, "Link to previous page found.");
+ $this->assertNoClass($previous->a, 'active', "Link to previous page is not active.");
+ }
+ if (isset($next)) {
+ $this->assertClass($next, 'pager-next', "Item for next page has .pager-next class.");
+ $this->assertTrue($next->a, "Link to next page found.");
+ $this->assertNoClass($next->a, 'active', "Link to next page is not active.");
+ }
+ if (isset($last)) {
+ $this->assertClass($last, 'pager-last', "Item for last page has .pager-last class.");
+ $this->assertTrue($last->a, "Link to last page found.");
+ $this->assertNoClass($last->a, 'active', "Link to last page is not active.");
+ }
+ }
+
+ /**
+ * Asserts that an element has a given class.
+ *
+ * @param SimpleXMLElement $element
+ * The element to test.
+ * @param string $class
+ * The class to assert.
+ * @param string $message
+ * (optional) A verbose message to output.
+ */
+ protected function assertClass(SimpleXMLElement $element, $class, $message = NULL) {
+ if (!isset($message)) {
+ $message = "Class .$class found.";
+ }
+ $this->assertTrue(strpos($element['class'], $class) !== FALSE, $message);
+ }
+
+ /**
+ * Asserts that an element does not have a given class.
+ *
+ * @param SimpleXMLElement $element
+ * The element to test.
+ * @param string $class
+ * The class to assert.
+ * @param string $message
+ * (optional) A verbose message to output.
+ */
+ protected function assertNoClass(SimpleXMLElement $element, $class, $message = NULL) {
+ if (!isset($message)) {
+ $message = "Class .$class not found.";
+ }
+ $this->assertTrue(strpos($element['class'], $class) === FALSE, $message);
+ }
+}
+