From e8cc3567862899cfd0f53784cf3da0b0120f7772 Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Thu, 5 Apr 2018 11:10:58 -0700 Subject: [PATCH] ChangesListSpecialPageTest: Use Database::makeList() instead of makeshift DIY code Otherwise these tests break completely when you add conditions like $conds['rc_patrolled'] = [ 1, 2 ]; That maps to 'rc_patrolled IN (1,2)', but the DIY code in normalizeCondition() was too simplistic to generate that. Change-Id: I449317185f98e20b3e17f1b13610d872ae828171 --- includes/specialpage/ChangesListSpecialPage.php | 4 ++-- .../specialpage/ChangesListSpecialPageTest.php | 17 +++++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/includes/specialpage/ChangesListSpecialPage.php b/includes/specialpage/ChangesListSpecialPage.php index b9d20bea16..14b824f7d9 100644 --- a/includes/specialpage/ChangesListSpecialPage.php +++ b/includes/specialpage/ChangesListSpecialPage.php @@ -276,7 +276,7 @@ abstract class ChangesListSpecialPage extends SpecialPage { 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds, &$query_options, &$join_conds ) { - $conds[] = 'rc_bot = 0'; + $conds['rc_bot'] = 0; }, 'cssClassSuffix' => 'bot', 'isRowApplicableCallable' => function ( $ctx, $rc ) { @@ -291,7 +291,7 @@ abstract class ChangesListSpecialPage extends SpecialPage { 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds, &$query_options, &$join_conds ) { - $conds[] = 'rc_bot = 1'; + $conds['rc_bot'] = 1; }, 'cssClassSuffix' => 'human', 'isRowApplicableCallable' => function ( $ctx, $rc ) { diff --git a/tests/phpunit/includes/specialpage/ChangesListSpecialPageTest.php b/tests/phpunit/includes/specialpage/ChangesListSpecialPageTest.php index d612b538d0..51182180a9 100644 --- a/tests/phpunit/includes/specialpage/ChangesListSpecialPageTest.php +++ b/tests/phpunit/includes/specialpage/ChangesListSpecialPageTest.php @@ -105,9 +105,14 @@ class ChangesListSpecialPageTest extends AbstractChangesListSpecialPageTestCase } private static function normalizeCondition( $conds ) { + $dbr = wfGetDB( DB_REPLICA ); $normalized = array_map( - function ( $k, $v ) { - return is_numeric( $k ) ? $v : "$k = $v"; + function ( $k, $v ) use ( $dbr ) { + if ( is_array( $v ) ) { + sort( $v ); + } + // (Ab)use makeList() to format only this entry + return $dbr->makeList( [ $k => $v ], Database::LIST_AND ); }, array_keys( $conds ), $conds @@ -116,9 +121,9 @@ class ChangesListSpecialPageTest extends AbstractChangesListSpecialPageTestCase return $normalized; } - /** return false if condition begin with 'rc_timestamp ' */ + /** return false if condition begins with 'rc_timestamp ' */ private static function filterOutRcTimestampCondition( $var ) { - return ( false === strpos( $var, 'rc_timestamp ' ) ); + return ( is_array( $var ) || false === strpos( $var, 'rc_timestamp ' ) ); } public function testRcNsFilter() { @@ -342,7 +347,7 @@ class ChangesListSpecialPageTest extends AbstractChangesListSpecialPageTestCase $user = $this->getTestSysop()->getUser(); $this->assertConditions( [ # expected - "rc_patrolled = 0", + 'rc_patrolled = 0', ], [ 'hidepatrolled' => 1, @@ -356,7 +361,7 @@ class ChangesListSpecialPageTest extends AbstractChangesListSpecialPageTestCase $user = $this->getTestSysop()->getUser(); $this->assertConditions( [ # expected - "rc_patrolled != 0", + 'rc_patrolled != 0', ], [ 'hideunpatrolled' => 1, -- 2.20.1