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

Change subject: Mostly cover ORES\Hooks
......................................................................


Mostly cover ORES\Hooks

Bug: T184140
Change-Id: I49fc3c3601a91758ca7d44c5f4415bfce7c71903
---
M tests/phpunit/includes/HooksTest.php
1 file changed, 170 insertions(+), 0 deletions(-)

Approvals:
  Ladsgroup: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/tests/phpunit/includes/HooksTest.php 
b/tests/phpunit/includes/HooksTest.php
index b770b9b..e961065 100644
--- a/tests/phpunit/includes/HooksTest.php
+++ b/tests/phpunit/includes/HooksTest.php
@@ -3,12 +3,19 @@
 namespace ORES\Tests;
 
 use IContextSource;
+use JobQueueGroup;
 use ORES\Hooks;
 use ORES\Hooks\PreferencesHookHandler;
 use ORES\Storage\HashModelLookup;
+use ORES\Storage\ScoreStorage;
+use ORES\ThresholdLookup;
+use OutputPage;
+use RecentChange;
 use RequestContext;
+use SkinFactory;
 use SpecialPage;
 use User;
+use Title;
 
 /**
  * @group ORES
@@ -41,6 +48,122 @@
                $this->user->saveSettings();
 
                $this->context = self::getContext( $this->user );
+       }
+
+       /**
+        * @covers ORES\Hooks::onRecentChange_save
+        */
+       public function testOnRecentChange_save() {
+               JobQueueGroup::singleton()->get( 'ORESFetchScoreJob' 
)->delete();
+
+               $rc = RecentChange::newFromRow( (object)[
+                       'rc_namespace' => NS_MAIN,
+                       'rc_title' => 'Test123',
+                       'rc_patrolled' => 0,
+                       'rc_timestamp' => '20150921134808',
+                       'rc_deleted' => 0,
+                       'rc_comment' => '',
+                       'rc_comment_text' => '',
+                       'rc_comment_data' => null,
+                       'rc_type' => RC_EDIT,
+                       'rc_this_oldid' => mt_rand( 1000, 9999 ),
+               ] );
+               Hooks::onRecentChange_save( $rc );
+
+               $this->assertFalse( JobQueueGroup::singleton()->get( 
'ORESFetchScoreJob' )->isEmpty() );
+       }
+
+       /**
+        * @covers ORES\Hooks::onRecentChangesPurgeRows
+        */
+       public function testOnRecentChangesPurgeRows() {
+               $revIds = [ 1, 5, 8, 13 ];
+               $rows = array_map( function ( $id ) {
+                       return (object)[ 'rc_this_oldid' => $id ];
+               }, $revIds );
+
+               $mock = $this->createMock( ScoreStorage::class );
+               $mock->expects( $this->once() )
+                       ->method( 'purgeRows' )
+                       ->with( $this->equalTo( $revIds ) );
+
+               $this->setService( 'ORESScoreStorage', $mock );
+
+               Hooks::onRecentChangesPurgeRows( $rows );
+       }
+
+       /**
+        * @covers ORES\Hooks::getDamagingLevelPreference
+        */
+       public function testGetDamagingLevelPreference_Watchlist() {
+               $level = Hooks::getDamagingLevelPreference( $this->user,
+                       Title::newFromText( 'Watchlist', NS_SPECIAL ) );
+
+               $this->assertEquals( 'maybebad', $level );
+       }
+
+       /**
+        * @covers ORES\Hooks::getThreshold
+        */
+       public function testGetThreshold_null() {
+               $mock = $this->createMock( ThresholdLookup::class );
+               $mock->method( 'getThresholds' )
+                       ->willReturn( [] );
+
+               $this->setService( 'ORESThresholdLookup', $mock );
+               $threshold = Hooks::getThreshold( 'damaging', $this->user );
+
+               $this->assertNull( $threshold );
+       }
+
+       /**
+        * @covers ORES\Hooks::getThreshold
+        *
+        * @expectedException Exception
+        * @expectedExceptionMessageRegExp "Unknown ORES test: 'not_a_thing'"
+        */
+       public function testGetThreshold_invalid() {
+               $threshold = Hooks::getThreshold( 'not_a_thing', $this->user );
+       }
+
+       /**
+        * @covers ORES\Hooks::onBeforePageDisplay
+        */
+       public function testOnBeforePageDisplay() {
+               $modelData = [ 'damaging' => [ 'id' => 5, 'version' => '0.0.2' 
] ];
+               $this->setService( 'ORESModelLookup', new HashModelLookup( 
$modelData ) );
+
+               $oresData = [
+                       123 => [
+                               'damaging' => 0.4,
+                       ]
+               ];
+               $thresholds = [
+                       'damaging' => [
+                               'maybebad' => 0.16,
+                               'likelybad' => 0.56,
+                       ],
+               ];
+
+               $skin = SkinFactory::getDefaultInstance()->makeSkin( 'fallback' 
);
+               $outputPage = new OutputPage( $this->context );
+               $outputPage->setProperty( 'oresData', $oresData );
+
+               Hooks::onBeforePageDisplay( $outputPage, $skin );
+
+               $vars = $outputPage->getJsConfigVars();
+               $this->assertEquals( [
+                       'oresData' => $oresData,
+                       'oresThresholds' => $thresholds,
+               ], $vars );
+               $styles = $outputPage->getModuleStyles();
+               $this->assertEquals( [
+                       'ext.ores.styles',
+               ], $styles );
+               $modules = $outputPage->getModules();
+               $this->assertEquals( [
+                       'ext.ores.highlighter',
+               ], $modules );
        }
 
        /**
@@ -137,4 +260,51 @@
                return $context;
        }
 
+       /**
+        * @covers ORES\Hooks::joinWithOresTables
+        */
+       public function testJoinWithOresTables() {
+               $modelData = [ 'damaging' => [ 'id' => 5, 'version' => '0.0.2' 
] ];
+               $this->setService( 'ORESModelLookup', new HashModelLookup( 
$modelData ) );
+
+               $tables = [];
+               $fields = [];
+               $join_conds = [];
+               Hooks::joinWithOresTables( 'damaging', 'rc_this_oldid',
+                       $tables, $fields, $join_conds );
+
+               $this->assertEquals( [
+                       'ores_damaging_cls' => 'ores_classification',
+               ], $tables );
+               $this->assertEquals( [
+                       'ores_damaging_score' => 
'ores_damaging_cls.oresc_probability',
+               ], $fields );
+               $this->assertEquals( [
+                       'ores_damaging_cls' => [ 'LEFT JOIN', [
+                               'ores_damaging_cls.oresc_model' => 5,
+                               'ores_damaging_cls.oresc_rev=rc_this_oldid',
+                               'ores_damaging_cls.oresc_class' => 1,
+                       ], ],
+               ], $join_conds );
+       }
+
+       /**
+        * @covers ORES\Hooks::hideNonDamagingFilter
+        */
+       public function testHideNonDamagingFilter() {
+               $modelData = [ 'damaging' => [ 'id' => 5, 'version' => '0.0.2' 
] ];
+               $this->setService( 'ORESModelLookup', new HashModelLookup( 
$modelData ) );
+
+               $fields = [];
+               $conds = [];
+               Hooks::hideNonDamagingFilter( $fields, $conds, true, 
$this->user );
+
+               $this->assertEquals( [
+                       'ores_damaging_threshold' => 0.16,
+               ], $fields );
+               $this->assertEquals( [
+                       'ores_damaging_cls.oresc_probability > \'0.16\'',
+               ], $conds );
+       }
+
 }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I49fc3c3601a91758ca7d44c5f4415bfce7c71903
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/ORES
Gerrit-Branch: master
Gerrit-Owner: Awight <awi...@wikimedia.org>
Gerrit-Reviewer: Ladsgroup <ladsgr...@gmail.com>
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