Ladsgroup has uploaded a new change for review.

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

Change subject: Extensive CI tests, part II
......................................................................

Extensive CI tests, part II

Bug: T146560
Change-Id: I164f3fa13e914a17dfed1a65862c45f154489c94
---
M tests/phpunit/includes/HooksTest.php
1 file changed, 273 insertions(+), 9 deletions(-)


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

diff --git a/tests/phpunit/includes/HooksTest.php 
b/tests/phpunit/includes/HooksTest.php
index 77353fa..fc788c0 100644
--- a/tests/phpunit/includes/HooksTest.php
+++ b/tests/phpunit/includes/HooksTest.php
@@ -1,12 +1,17 @@
 <?php
 namespace ORES\Tests;
 
+use ChangesList;
 use ChangesListSpecialPage;
+use ContribsPager;
 use EnhancedChangesList;
 use FormOptions;
+use IContextSource;
+use ORES;
 use RCCacheEntry;
 use RecentChange;
-use ORES;
+use RequestContext;
+use SpecialContributions;
 
 /**
  * @group ORES
@@ -15,6 +20,8 @@
 class OresHooksTest extends \MediaWikiTestCase {
        protected $user;
 
+       protected $context;
+
        protected function setUp() {
                parent::setUp();
 
@@ -22,13 +29,8 @@
                $this->user->setOption( 'ores-enabled', "1" );
                $this->user->setOption( 'oresDamagingPref', 'soft' );
                $this->user->saveSettings();
-       }
 
-       public function testOresEnabled() {
-               $prefs = [];
-               ORES\Hooks::onGetBetaFeaturePreferences( $this->user, $prefs );
-               $this->assertArrayHasKey( 'ores-enabled', $prefs );
-
+               $this->context = self::getContext( $this->user );
        }
 
        public function testOresPrefs() {
@@ -48,11 +50,11 @@
                $row->rc_deleted = 0;
 
                $rc = RecentChange::newFromRow( $row );
-               $this->assertTrue( ORES\Hooks::getScoreRecentChangesList( $rc ) 
);
+               $this->assertTrue( ORES\Hooks::getScoreRecentChangesList( $rc, 
$this->context ) );
 
                $row->ores_damaging_threshold = 0.4;
                $rc = RecentChange::newFromRow( $row );
-               $this->assertFalse( ORES\Hooks::getScoreRecentChangesList( $rc 
) );
+               $this->assertFalse( ORES\Hooks::getScoreRecentChangesList( $rc, 
$this->context ) );
        }
 
        public function testOnChangesListSpecialPageFilters() {
@@ -62,6 +64,10 @@
                $clsp->expects( $this->any() )
                        ->method( 'getUser' )
                        ->will( $this->returnValue( $this->user ) );
+
+               $clsp->expects( $this->any() )
+                       ->method( 'getContext' )
+                       ->will( $this->returnValue( $this->context ) );
 
                ORES\Hooks::onChangesListSpecialPageFilters( $clsp, $filters );
                $expected = [
@@ -146,6 +152,10 @@
                        ->method( 'getUser' )
                        ->will( $this->returnValue( $this->user ) );
 
+               $ecl->expects( $this->any() )
+                       ->method( 'getContext' )
+                       ->will( $this->returnValue( $this->context ) );
+
                $data = [];
                $block = [];
                $classes = [];
@@ -175,6 +185,10 @@
                        ->method( 'getUser' )
                        ->will( $this->returnValue( $this->user ) );
 
+               $ecl->expects( $this->any() )
+                       ->method( 'getContext' )
+                       ->will( $this->returnValue( $this->context ) );
+
                $data = [];
                $block = [];
                $classes = [];
@@ -185,4 +199,254 @@
                $this->assertSame( [], $block );
                $this->assertSame( [], $classes );
        }
+
+       public function testOnOldChangesListModifyLineDataDamaging() {
+               $row = new \stdClass();
+               $row->ores_damaging_threshold = 0.2;
+               $row->ores_damaging_score = 0.3;
+               $row->rc_patrolled = 0;
+               $row->rc_timestamp = '20150921134808';
+               $row->rc_deleted = 0;
+               $rc = RecentChange::newFromRow( $row );
+               $rc = RCCacheEntry::newFromParent( $rc );
+
+               $cl = $this->getMockBuilder( ChangesList::class )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+
+               $cl->expects( $this->any() )
+                       ->method( 'getUser' )
+                       ->will( $this->returnValue( $this->user ) );
+
+               $cl->expects( $this->any() )
+                       ->method( 'getContext' )
+                       ->will( $this->returnValue( $this->context ) );
+
+               $classes = [];
+
+               $s = ' <span class="mw-changeslist-separator">. .</span> ';
+               ORES\Hooks::onOldChangesListRecentChangesLine( $cl, $s, $rc, 
$classes );
+
+               $this->assertSame(
+                       ' <span class="mw-changeslist-separator">. .</span>' .
+                       ' <abbr class="ores-damaging" title="This edit needs 
review">r</abbr>',
+                       $s
+               );
+               $this->assertSame( [ 'damaging' ], $classes );
+       }
+
+       public function testOnOldChangesListModifyLineDataNonDamaging() {
+               $row = new \stdClass();
+               $row->ores_damaging_threshold = 0.4;
+               $row->ores_damaging_score = 0.3;
+               $row->rc_patrolled = 0;
+               $row->rc_timestamp = '20150921134808';
+               $row->rc_deleted = 0;
+               $rc = RecentChange::newFromRow( $row );
+               $rc = RCCacheEntry::newFromParent( $rc );
+
+               $cl = $this->getMockBuilder( ChangesList::class )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+
+               $cl->expects( $this->any() )
+                       ->method( 'getUser' )
+                       ->will( $this->returnValue( $this->user ) );
+
+               $cl->expects( $this->any() )
+                       ->method( 'getContext' )
+                       ->will( $this->returnValue( $this->context ) );
+
+               $classes = [];
+
+               $s = ' <span class="mw-changeslist-separator">. .</span> ';
+               ORES\Hooks::onOldChangesListRecentChangesLine( $cl, $s, $rc, 
$classes );
+
+               $this->assertSame( ' <span class="mw-changeslist-separator">. 
.</span> ', $s );
+               $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' => [],
+                       'join_conds' => []
+               ];
+               ORES\Hooks::onContribsGetQueryInfo(
+                       $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' => [],
+                       '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'] );
+               $this->assertSame( $expected['join_conds'], 
$query['join_conds'] );
+       }
+
+       public function testOnSpecialContributionsFormatRowFlagsDamaging() {
+               $row = new \stdClass();
+               $row->ores_damaging_threshold = 0.2;
+               $row->ores_damaging_score = 0.3;
+               $row->rev_id = 0;
+
+               $flags = [];
+
+               ORES\Hooks::onSpecialContributionsFormatRowFlags( 
$this->context, $row, $flags );
+
+               $this->assertSame(
+                       [ '<abbr class="ores-damaging" title="This edit needs 
review">r</abbr>' ],
+                       $flags
+               );
+       }
+
+       public function testOnSpecialContributionsFormatRowFlagsNonDamaging() {
+               $row = new \stdClass();
+               $row->ores_damaging_threshold = 0.4;
+               $row->ores_damaging_score = 0.3;
+               $row->rev_id = 0;
+
+               $flags = [];
+
+               ORES\Hooks::onSpecialContributionsFormatRowFlags( 
$this->context, $row, $flags );
+
+               $this->assertSame( [], $flags );
+       }
+
+       public function testOnContributionsLineEndingDamaging() {
+               $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 ) );
+
+               $row = new \stdClass();
+               $row->ores_damaging_threshold = 0.2;
+               $row->ores_damaging_score = 0.3;
+               $row->rev_id = 0;
+
+               $ret = [];
+               $classes = [];
+
+               ORES\Hooks::onContributionsLineEnding( $cp, $ret, $row, 
$classes );
+
+               $this->assertSame( [ 'damaging' ], $classes );
+               $this->assertSame( [], $ret );
+       }
+
+       public function testOnContributionsLineEndingNonDamaging() {
+               $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 ) );
+
+               $row = new \stdClass();
+               $row->ores_damaging_threshold = 0.4;
+               $row->ores_damaging_score = 0.3;
+               $row->rev_id = 0;
+
+               $ret = [];
+               $classes = [];
+
+               ORES\Hooks::onContributionsLineEnding( $cp, $ret, $row, 
$classes );
+
+               $this->assertSame( [], $classes );
+               $this->assertSame( [], $ret );
+       }
+
+       public function testOnGetPreferencesEnabled() {
+               $prefs = [];
+               ORES\Hooks::onGetPreferences( $this->user, $prefs );
+
+               $this->assertSame( 3, count( $prefs ) );
+       }
+
+       public function testOnGetPreferencesDisabled() {
+               $user = static::getTestUser()->getUser();
+               $user->setOption( 'ores-enabled', "0" );
+               $user->saveSettings();
+
+               $prefs = [];
+               ORES\Hooks::onGetPreferences( $this->user, $prefs );
+
+               $this->assertSame( [], $prefs );
+       }
+
+       public function testOnGetBetaFeaturePreferences() {
+               $prefs = [];
+               ORES\Hooks::onGetBetaFeaturePreferences( $this->user, $prefs );
+
+               $this->assertSame( 1, count( $prefs ) );
+               $this->assertArrayHasKey( 'ores-enabled', $prefs );
+       }
+
+       public function testOresEnabled() {
+               $prefs = [];
+               ORES\Hooks::onGetBetaFeaturePreferences( $this->user, $prefs );
+               $this->assertArrayHasKey( 'ores-enabled', $prefs );
+
+       }
+
+       /**
+        * @return IContextSource
+        */
+       private static function getContext( $user ) {
+
+               $context = new RequestContext();
+
+               $context->setLanguage( 'en' );
+               $context->setUser( $user );
+
+               return $context;
+       }
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I164f3fa13e914a17dfed1a65862c45f154489c94
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