EBernhardson has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/179178

Change subject: Bug: Incorrectly slicing on reverse pagination
......................................................................

Bug: Incorrectly slicing on reverse pagination

While looking into another issue with reverse pagination i wrote
this test for reverse paging with a filter and it failed. This test
is almost certainly the desired behavior, so adjusted the related
array_slice in the pager.

Change-Id: Iac30ba23c5c099a5c0165bd8bb9a50d771f52658
---
M includes/Data/Pager/Pager.php
M tests/phpunit/Data/Pager/PagerTest.php
2 files changed, 21 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow 
refs/changes/78/179178/1

diff --git a/includes/Data/Pager/Pager.php b/includes/Data/Pager/Pager.php
index fddec20..b67acaf 100644
--- a/includes/Data/Pager/Pager.php
+++ b/includes/Data/Pager/Pager.php
@@ -180,7 +180,7 @@
                } elseif ( $this->options['pager-dir'] === 'rev' ) {
                        if ( count( $results ) > $this->options['pager-limit'] 
) {
                                // We got extra, another page exists
-                               $results = array_slice( $results, 
-$this->options['pager-limit'] );
+                               $results = array_slice( $results, 0, 
$this->options['pager-limit'] );
                                $pagingLinks['rev'] = $this->makePagingLink(
                                        'rev',
                                        reset( $results ),
diff --git a/tests/phpunit/Data/Pager/PagerTest.php 
b/tests/phpunit/Data/Pager/PagerTest.php
index 70b50b3..8e7b4bb 100644
--- a/tests/phpunit/Data/Pager/PagerTest.php
+++ b/tests/phpunit/Data/Pager/PagerTest.php
@@ -75,7 +75,26 @@
                                        return array_filter( $found, function( 
$obj ) {
                                                return $obj->foo !== 'B' && 
$obj->foo !== 'C';
                                        } );
-                               }
+                               },
+                       ),
+
+                       array(
+                               'Reverse pagination with filter',
+                               // expect
+                               array( $objs['D'], $objs['B'] ),
+                               // find results
+                               array(
+                                       array( $objs['E'], $objs['D'], 
$objs['C'] ),
+                                       array( $objs['B'], $objs['A'] ),
+                               ),
+                               // query options
+                               array( 'pager-limit' => 2, 'pager-dir' => 'rev' 
),
+                               // query filter
+                               function( $found ) {
+                                       return array_filter( $found, function( 
$obj ) {
+                                               return $obj->foo !== 'E' && 
$obj->foo !== 'C';
+                                       } );
+                               },
                        ),
                );
        }

-- 
To view, visit https://gerrit.wikimedia.org/r/179178
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iac30ba23c5c099a5c0165bd8bb9a50d771f52658
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to