diff --git a/includes/pager.inc b/includes/pager.inc index a5d3e6b..c7416a5 100644 --- a/includes/pager.inc +++ b/includes/pager.inc @@ -188,8 +188,10 @@ function pager_find_page($element = 0) { $page = isset($_GET['page']) ? $_GET['page'] : ''; $page_array = explode(',', $page); if (!isset($page_array[$element])) { - $page_array[$element] = 0; + $page_array[$element] = 1; } + // Translate human readable page numbers to PHP offset logic. + $page_array[$element]--; return (int) $page_array[$element]; } @@ -600,7 +602,8 @@ function theme_pager_link($variables) { $page = isset($_GET['page']) ? $_GET['page'] : ''; if ($new_page = implode(',', pager_load_array($page_new[$element], $element, explode(',', $page)))) { - $parameters['page'] = $new_page; + // Translate PHP offset logic to human readable page numbers. + $parameters['page'] = $new_page + 1; } $query = array(); diff --git a/modules/comment/comment.module b/modules/comment/comment.module index f9af40a..baba2cf 100644 --- a/modules/comment/comment.module +++ b/modules/comment/comment.module @@ -1793,7 +1793,7 @@ function comment_get_display_ordinal($cid, $node_type) { function comment_get_display_page($cid, $node_type) { $ordinal = comment_get_display_ordinal($cid, $node_type); $comments_per_page = variable_get('comment_default_per_page_' . $node_type, 50); - return floor($ordinal / $comments_per_page); + return floor($ordinal / $comments_per_page) + 1; } /** diff --git a/modules/comment/comment.test b/modules/comment/comment.test index 2e96ba3..d2d3ff2 100644 --- a/modules/comment/comment.test +++ b/modules/comment/comment.test @@ -415,7 +415,7 @@ class CommentInterfaceTest extends CommentHelperCase { $this->setCommentsPerPage(2); $comment_new_page = $this->postComment($this->node, $this->randomName(), $this->randomName(), TRUE); $this->assertTrue($this->commentExists($comment_new_page), t('Page one exists. %s')); - $this->drupalGet('node/' . $this->node->nid, array('query' => array('page' => 1))); + $this->drupalGet('node/' . $this->node->nid, array('query' => array('page' => 2))); $this->assertTrue($this->commentExists($reply, TRUE), t('Page two exists. %s')); $this->setCommentsPerPage(50); @@ -1137,13 +1137,13 @@ class CommentPagerTest extends CommentHelperCase { $this->assertFalse($this->commentExists($comments[2]), t('Comment 3 does not appear on page 1.')); // Check the second page. - $this->drupalGet('node/' . $node->nid, array('query' => array('page' => 1))); + $this->drupalGet('node/' . $node->nid, array('query' => array('page' => 2))); $this->assertTrue($this->commentExists($comments[1]), t('Comment 2 appears on page 2.')); $this->assertFalse($this->commentExists($comments[0]), t('Comment 1 does not appear on page 2.')); $this->assertFalse($this->commentExists($comments[2]), t('Comment 3 does not appear on page 2.')); // Check the third page. - $this->drupalGet('node/' . $node->nid, array('query' => array('page' => 2))); + $this->drupalGet('node/' . $node->nid, array('query' => array('page' => 3))); $this->assertTrue($this->commentExists($comments[2]), t('Comment 3 appears on page 3.')); $this->assertFalse($this->commentExists($comments[0]), t('Comment 1 does not appear on page 3.')); $this->assertFalse($this->commentExists($comments[1]), t('Comment 2 does not appear on page 3.')); diff --git a/modules/entity/tests/entity_query.test b/modules/entity/tests/entity_query.test index 49cf7b8..2705f3c 100644 --- a/modules/entity/tests/entity_query.test +++ b/modules/entity/tests/entity_query.test @@ -1274,7 +1274,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase { */ function testEntityFieldQueryPager() { // Test pager in propertyQuery - $_GET['page'] = '0,1'; + $_GET['page'] = '1,2'; $query = new EntityFieldQuery(); $query ->entityCondition('entity_type', 'test_entity_bundle_key') @@ -1298,7 +1298,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase { ), t('Test pager integration in propertyQuery: page 2.'), TRUE); // Test pager in field storage - $_GET['page'] = '0,1'; + $_GET['page'] = '1,2'; $query = new EntityFieldQuery(); $query ->entityCondition('entity_type', 'test_entity_bundle_key') diff --git a/modules/search/search.test b/modules/search/search.test index a6ed0df..b908df8 100644 --- a/modules/search/search.test +++ b/modules/search/search.test @@ -450,7 +450,7 @@ class SearchRankingTestCase extends DrupalWebTestCase { function testHTMLRankings() { // Login with sufficient privileges. $this->drupalLogin($this->drupalCreateUser(array('create page content'))); - + // Test HTML tags with different weights. $sorted_tags = array('h1', 'h2', 'h3', 'h4', 'a', 'h5', 'h6', 'notag'); $shuffled_tags = $sorted_tags; @@ -482,7 +482,7 @@ class SearchRankingTestCase extends DrupalWebTestCase { // Refresh variables after the treatment. $this->refreshVariables(); - + // Disable all other rankings. $node_ranks = array('sticky', 'promote', 'recent', 'comments', 'views'); foreach ($node_ranks as $node_rank) { @@ -520,7 +520,7 @@ class SearchRankingTestCase extends DrupalWebTestCase { // Assert the results. $this->assertEqual($set[0]['node']->nid, $node->nid, 'Search tag ranking for "<' . $tag . '>" order.'); - + // Delete node so it doesn't show up in subsequent search results. node_delete($node->nid); } @@ -691,16 +691,16 @@ class SearchExactTestCase extends DrupalWebTestCase { // Test that the correct number of pager links are found for keyword search. $edit = array('keys' => 'love pizza'); $this->drupalPost('search/node', $edit, t('Search')); - $this->assertLinkByHref('page=1', 0, '2nd page link is found for keyword search.'); - $this->assertLinkByHref('page=2', 0, '3rd page link is found for keyword search.'); - $this->assertLinkByHref('page=3', 0, '4th page link is found for keyword search.'); - $this->assertNoLinkByHref('page=4', '5th page link is not found for keyword search.'); + $this->assertLinkByHref('page=2', 0, '2nd page link is found for keyword search.'); + $this->assertLinkByHref('page=3', 0, '3rd page link is found for keyword search.'); + $this->assertLinkByHref('page=4', 0, '4th page link is found for keyword search.'); + $this->assertNoLinkByHref('page=5', '5th page link is not found for keyword search.'); // Test that the correct number of pager links are found for exact phrase search. $edit = array('keys' => '"love pizza"'); $this->drupalPost('search/node', $edit, t('Search')); - $this->assertLinkByHref('page=1', 0, '2nd page link is found for exact phrase search.'); - $this->assertNoLinkByHref('page=2', '3rd page link is not found for exact phrase search.'); + $this->assertLinkByHref('page=2', 0, '2nd page link is found for exact phrase search.'); + $this->assertNoLinkByHref('page=3', '3rd page link is not found for exact phrase search.'); } } @@ -861,7 +861,7 @@ class SearchCommentTestCase extends DrupalWebTestCase { $this->setRolePermissions(DRUPAL_AUTHENTICATED_RID, TRUE, TRUE); $this->setRolePermissions($this->admin_role, TRUE, FALSE); $this->checkCommentAccess('Admin user has access comments permission and no search permission, but comments should be indexed because admin user inherits authenticated user\'s permission to search', TRUE); - + } /** diff --git a/modules/simpletest/tests/database_test.test b/modules/simpletest/tests/database_test.test index 87d386a..e234ab5 100644 --- a/modules/simpletest/tests/database_test.test +++ b/modules/simpletest/tests/database_test.test @@ -2303,19 +2303,14 @@ class DatabaseSelectPagerDefaultTestCase extends DatabaseTestCase { $count = db_query('SELECT COUNT(*) FROM {test_task}')->fetchField(); $correct_number = $limit; - $num_pages = floor($count / $limit); - - // If there is no remainder from rounding, subtract 1 since we index from 0. - if (!($num_pages * $limit < $count)) { - $num_pages--; - } + $num_pages = ceil($count / $limit); - for ($page = 0; $page <= $num_pages; ++$page) { + for ($page = 1; $page <= $num_pages; ++$page) { $this->drupalGet('database_test/pager_query_odd/' . $limit, array('query' => array('page' => $page))); $data = json_decode($this->drupalGetContent()); if ($page == $num_pages) { - $correct_number = $count - ($limit * $page); + $correct_number = $count - ($limit * ($page - 1)); } $this->assertEqual(count($data->names), $correct_number, t('Correct number of records returned by pager: @number', array('@number' => $correct_number))); @@ -2367,7 +2362,7 @@ class DatabaseSelectPagerDefaultTestCase extends DatabaseTestCase { * Confirm that every pager gets a valid non-overlaping element ID. */ function testElementNumbers() { - $_GET['page'] = '3, 2, 1, 0'; + $_GET['page'] = '4, 3, 2, 1'; $name = db_select('test', 't')->extend('PagerDefault') ->element(2)