Ladsgroup has uploaded a new change for review. ( 
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, 39 insertions(+), 68 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ORES 
refs/changes/80/334880/1

diff --git a/tests/phpunit/includes/HooksTest.php 
b/tests/phpunit/includes/HooksTest.php
index cc455e8..e37887c 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 onContribsGetQueryInfoProvider() {
                $expected = [
                        'tables' => [
                                'ores_damaging_mdl' => 'ores_model',
@@ -515,28 +492,45 @@
                        ],
                        '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\'' ];
+
+               $res = [
+                       'all' => [
+                               $expected,
+                           false
+                       ],
+                   'damaging only' => [
+                           $expectedDamaging,
+                       true,
+                   ]
+               ];
+
+               return $res;
        }
 
-       public function testOnContribsGetQueryInfoOnlyDamaging() {
+       /**
+        * @dataProvider onContribsGetQueryInfoProvider
+        */
+       public function testOnContribsGetQueryInfo( array $expected, 
$nonDamging ) {
                $cp = $this->getMockBuilder( ContribsPager::class )
                        ->disableOriginalConstructor()
                        ->getMock();
@@ -545,11 +539,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 ( $nonDamging === true ) {
+                       $this->context->getRequest()->setVal( 
'hidenondamaging', true );
+               }
 
                $query = [
                        'tables' => [],
@@ -562,32 +558,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: newchange
Gerrit-Change-Id: I50b8a196388bab654ee3e7477e7829238bcfb7b0
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ORES
Gerrit-Branch: master
Gerrit-Owner: Ladsgroup <ladsgr...@gmail.com>

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

Reply via email to