jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/334880 )

Change subject: Refactor DB query tests for SpecialContribs
......................................................................


Refactor DB query tests for SpecialContribs

Change-Id: I50b8a196388bab654ee3e7477e7829238bcfb7b0
---
M tests/phpunit/includes/HooksTest.php
1 file changed, 31 insertions(+), 68 deletions(-)

Approvals:
  Gergő Tisza: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/tests/phpunit/includes/HooksTest.php 
b/tests/phpunit/includes/HooksTest.php
index cc455e8..f14dd77 100644
--- a/tests/phpunit/includes/HooksTest.php
+++ b/tests/phpunit/includes/HooksTest.php
@@ -480,30 +480,7 @@
                $this->assertSame( [], $classes );
        }
 
-       public function testOnContribsGetQueryInfo() {
-               $cp = $this->getMockBuilder( ContribsPager::class )
-                       ->disableOriginalConstructor()
-                       ->getMock();
-
-               $cp->expects( $this->any() )
-                       ->method( 'getUser' )
-                       ->will( $this->returnValue( $this->user ) );
-
-               $cp->expects( $this->any() )
-                       ->method( 'getContext' )
-                       ->will( $this->returnValue( $this->context ) );
-
-               $query = [
-                       'tables' => [],
-                       'fields' => [],
-                       'conds' => [],
-                       'options' => [],
-                       'join_conds' => [],
-               ];
-               ORES\Hooks::onContribsGetQueryInfo(
-                       $cp,
-                       $query
-               );
+       public function provideOnContribsGetQueryInfo() {
                $expected = [
                        'tables' => [
                                'ores_damaging_mdl' => 'ores_model',
@@ -515,28 +492,37 @@
                        ],
                        'conds' => [],
                        'join_conds' => [
-                               'ores_damaging_mdl' => [ 'LEFT JOIN',
-                                                        [
-                                                                
'ores_damaging_mdl.oresm_is_current' => 1,
-                                                                
'ores_damaging_mdl.oresm_name' => 'damaging'
-                                                        ]
+                               'ores_damaging_mdl' => [
+                                       'LEFT JOIN',
+                                       [
+                                               
'ores_damaging_mdl.oresm_is_current' => 1,
+                                               'ores_damaging_mdl.oresm_name' 
=> 'damaging'
+                                       ]
                                ],
-                               'ores_damaging_cls' => [ 'LEFT JOIN',
-                                                        [
-                                                                
'ores_damaging_cls.oresc_model = ores_damaging_mdl.oresm_id',
-                                                                'rev_id = 
ores_damaging_cls.oresc_rev',
-                                                                
'ores_damaging_cls.oresc_class' => 1
-                                                        ]
+                               'ores_damaging_cls' => [
+                                       'LEFT JOIN',
+                                       [
+                                               'ores_damaging_cls.oresc_model 
= ores_damaging_mdl.oresm_id',
+                                               'rev_id = 
ores_damaging_cls.oresc_rev',
+                                               'ores_damaging_cls.oresc_class' 
=> 1
+                                       ]
                                ]
                        ],
                ];
-               $this->assertSame( $expected['tables'], $query['tables'] );
-               $this->assertSame( $expected['fields'], $query['fields'] );
-               $this->assertSame( $expected['conds'], $query['conds'] );
-               $this->assertSame( $expected['join_conds'], 
$query['join_conds'] );
+
+               $expectedDamaging = $expected;
+               $expectedDamaging['conds'] = [ 
'ores_damaging_cls.oresc_probability > \'0.7\'' ];
+
+               return [
+                       'all' => [ $expected, false ],
+                       'damaging only' => [ $expectedDamaging, true ]
+               ];
        }
 
-       public function testOnContribsGetQueryInfoOnlyDamaging() {
+       /**
+        * @dataProvider provideOnContribsGetQueryInfo
+        */
+       public function testOnContribsGetQueryInfo( array $expected, 
$nonDamaging ) {
                $cp = $this->getMockBuilder( ContribsPager::class )
                        ->disableOriginalConstructor()
                        ->getMock();
@@ -545,11 +531,13 @@
                        ->method( 'getUser' )
                        ->will( $this->returnValue( $this->user ) );
 
-               $this->context->getRequest()->setVal( 'hidenondamaging', true );
-
                $cp->expects( $this->any() )
                        ->method( 'getContext' )
                        ->will( $this->returnValue( $this->context ) );
+
+               if ( $nonDamaging === true ) {
+                       $this->context->getRequest()->setVal( 
'hidenondamaging', true );
+               }
 
                $query = [
                        'tables' => [],
@@ -562,32 +550,7 @@
                        $cp,
                        $query
                );
-               $expected = [
-                       'tables' => [
-                               'ores_damaging_mdl' => 'ores_model',
-                               'ores_damaging_cls' => 'ores_classification'
-                       ],
-                       'fields' => [
-                               'ores_damaging_score' => 
'ores_damaging_cls.oresc_probability',
-                               'ores_damaging_threshold' => "'0.7'"
-                       ],
-                       'conds' => [ "ores_damaging_cls.oresc_probability > 
'0.7'" ],
-                       'join_conds' => [
-                               'ores_damaging_mdl' => [ 'LEFT JOIN',
-                                                        [
-                                                                
'ores_damaging_mdl.oresm_is_current' => 1,
-                                                                
'ores_damaging_mdl.oresm_name' => 'damaging'
-                                                        ]
-                               ],
-                               'ores_damaging_cls' => [ 'LEFT JOIN',
-                                                        [
-                                                                
'ores_damaging_cls.oresc_model = ores_damaging_mdl.oresm_id',
-                                                                'rev_id = 
ores_damaging_cls.oresc_rev',
-                                                                
'ores_damaging_cls.oresc_class' => 1
-                                                        ]
-                               ]
-                       ],
-               ];
+
                $this->assertSame( $expected['tables'], $query['tables'] );
                $this->assertSame( $expected['fields'], $query['fields'] );
                $this->assertSame( $expected['conds'], $query['conds'] );

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I50b8a196388bab654ee3e7477e7829238bcfb7b0
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/ORES
Gerrit-Branch: master
Gerrit-Owner: Ladsgroup <ladsgr...@gmail.com>
Gerrit-Reviewer: Gergő Tisza <gti...@wikimedia.org>
Gerrit-Reviewer: Ladsgroup <ladsgr...@gmail.com>
Gerrit-Reviewer: Legoktm <lego...@member.fsf.org>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to