[MediaWiki-commits] [Gerrit] mediawiki...ORES[master]: Tests for WatchedItemQueryServiceExtension

2018-01-10 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/403227 )

Change subject: Tests for WatchedItemQueryServiceExtension
..


Tests for WatchedItemQueryServiceExtension

Bug: T184140
Change-Id: I074762b884cd34ae13f2fd71d654f6ddd309c8b3
---
A tests/phpunit/includes/WatchedItemQueryServiceExtensionTest.php
1 file changed, 120 insertions(+), 0 deletions(-)

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



diff --git a/tests/phpunit/includes/WatchedItemQueryServiceExtensionTest.php 
b/tests/phpunit/includes/WatchedItemQueryServiceExtensionTest.php
new file mode 100644
index 000..e988fa9
--- /dev/null
+++ b/tests/phpunit/includes/WatchedItemQueryServiceExtensionTest.php
@@ -0,0 +1,120 @@
+setMwGlobals( [
+   'wgOresFiltersThresholds' => [
+   'damaging' => [
+   'maybebad' => [ 'min' => 0.16, 'max' => 
1 ],
+   'likelybad' => [ 'min' => 0.56, 'max' 
=> 1 ],
+   ]
+   ],
+   'wgOresWikiId' => 'testwiki',
+   ] );
+
+   $this->user = static::getTestUser()->getUser();
+   $this->user->setOption( 'ores-enabled', 1 );
+   $this->user->setOption( 'oresDamagingPref', 'maybebad' );
+   $this->user->setOption( 'oresHighlight', 1 );
+   $this->user->setOption( 'ores-damaging-flag-rc', 1 );
+   $this->user->saveSettings();
+
+   $modelData = [ 'damaging' => [ 'id' => 5, 'version' => '0.0.2' 
] ];
+   $this->setService( 'ORESModelLookup', new HashModelLookup( 
$modelData ) );
+   }
+
+   /**
+* @covers 
ORES\WatchedItemQueryServiceExtension::modifyWatchedItemsWithRCInfoQuery
+*/
+   public function testModifyWatchedItemsWithRCInfoQuery_review() {
+   $options = [
+   'filters' => [ 'oresreview' ],
+   'includeFields' => [ 'oresscores' ],
+   'usedInGenerator' => false,
+   ];
+   $tables = [];
+   $fields = [];
+   $conds = [];
+   $dbOptions = [];
+   $joinConds = [];
+   $db = wfGetDB( DB_REPLICA );
+   $service = new WatchedItemQueryServiceExtension();
+   $service->modifyWatchedItemsWithRCInfoQuery(
+   $this->user, $options, $db, $tables, $fields, $conds,
+   $dbOptions, $joinConds );
+
+   $this->assertEquals( [
+   'rc_this_oldid',
+   'rc_type',
+   ], $fields );
+   $this->assertEquals( [
+   'ores_model',
+   'ores_classification',
+   ], $tables );
+   $this->assertEquals( [
+   'oresc_probability > \'0.16\'',
+   ], $conds );
+   $this->assertEquals( [
+   'ores_classification' => [ 'INNER JOIN', [
+   'rc_this_oldid=oresc_rev',
+   'oresc_model' => 5,
+   'oresc_class' => 1,
+   ], ],
+   ], $joinConds );
+   }
+
+   /**
+* @covers 
ORES\WatchedItemQueryServiceExtension::modifyWatchedItemsWithRCInfoQuery
+*/
+   public function testModifyWatchedItemsWithRCInfoQuery_not_review() {
+   $options = [
+   'filters' => [ '!oresreview' ],
+   'includeFields' => [ 'oresscores' ],
+   'usedInGenerator' => false,
+   ];
+   $tables = [];
+   $fields = [];
+   $conds = [];
+   $dbOptions = [];
+   $joinConds = [];
+   $db = wfGetDB( DB_REPLICA );
+   $service = new WatchedItemQueryServiceExtension();
+   $service->modifyWatchedItemsWithRCInfoQuery(
+   $this->user, $options, $db, $tables, $fields, $conds,
+   $dbOptions, $joinConds );
+
+   $this->assertEquals( [
+   'rc_this_oldid',
+   'rc_type',
+   ], $fields );
+   $this->assertEquals( [
+   'ores_model',
+   'ores_classification',
+   ], $tables );
+   $this->assertEquals( [
+   '(oresc_probability <= \'0.16\') OR (oresc_probability 
IS NULL)',
+   ], $conds );
+   $this->assertEquals( [
+   'ores_classification' => [ 'LEFT JOIN', [
+   'rc_this_oldid=oresc_rev',
+   'oresc_model' 

[MediaWiki-commits] [Gerrit] mediawiki...ORES[master]: Tests for WatchedItemQueryServiceExtension

2018-01-09 Thread Awight (Code Review)
Awight has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/403227 )

Change subject: Tests for WatchedItemQueryServiceExtension
..

Tests for WatchedItemQueryServiceExtension

Bug: T184140
Change-Id: I074762b884cd34ae13f2fd71d654f6ddd309c8b3
---
A tests/phpunit/includes/WatchedItemQueryServiceExtensionTest.php
1 file changed, 119 insertions(+), 0 deletions(-)


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

diff --git a/tests/phpunit/includes/WatchedItemQueryServiceExtensionTest.php 
b/tests/phpunit/includes/WatchedItemQueryServiceExtensionTest.php
new file mode 100644
index 000..11523e3
--- /dev/null
+++ b/tests/phpunit/includes/WatchedItemQueryServiceExtensionTest.php
@@ -0,0 +1,119 @@
+setMwGlobals( [
+   'wgOresFiltersThresholds' => [
+   'damaging' => [
+   'maybebad' => [ 'min' => 0.16, 'max' => 
1 ],
+   'likelybad' => [ 'min' => 0.56, 'max' 
=> 1 ],
+   ]
+   ],
+   'wgOresWikiId' => 'testwiki',
+   ] );
+
+   $this->user = static::getTestUser()->getUser();
+   $this->user->setOption( 'ores-enabled', 1 );
+   $this->user->setOption( 'oresDamagingPref', 'maybebad' );
+   $this->user->setOption( 'oresHighlight', 1 );
+   $this->user->setOption( 'ores-damaging-flag-rc', 1 );
+   $this->user->saveSettings();
+
+   $modelData = [ 'damaging' => [ 'id' => 5, 'version' => '0.0.2' 
] ];
+   $this->setService( 'ORESModelLookup', new HashModelLookup( 
$modelData ) );
+   }
+
+   /**
+* @covers 
ORES\WatchedItemQueryServiceExtensionTest::modifyWatchedItemsWithRCInfoQuery
+*/
+   public function testModifyWatchedItemsWithRCInfoQuery_review() {
+   $options = [
+   'filters' => [ 'oresreview' ],
+   'includeFields' => [ 'oresscores' ],
+   'usedInGenerator' => false,
+   ];
+   $tables = [];
+   $fields = [];
+   $conds = [];
+   $dbOptions = [];
+   $joinConds = [];
+   $db = wfGetDB( DB_MASTER );
+   $service = new WatchedItemQueryServiceExtension();
+   $service->modifyWatchedItemsWithRCInfoQuery(
+   $this->user, $options, $db, $tables, $fields, $conds,
+   $dbOptions, $joinConds );
+
+   $this->assertEquals( [
+   'rc_this_oldid',
+   'rc_type',
+   ], $fields );
+   $this->assertEquals( [
+   'ores_model',
+   'ores_classification',
+   ], $tables );
+   $this->assertEquals( [
+   'oresc_probability > \'0.16\'',
+   ], $conds );
+   $this->assertEquals( [
+   'ores_classification' => [ 'INNER JOIN', [
+   'rc_this_oldid=oresc_rev',
+   'oresc_model' => 5,
+   'oresc_class' => 1,
+   ], ],
+   ], $joinConds );
+   }
+
+   /**
+* @covers 
ORES\WatchedItemQueryServiceExtensionTest::modifyWatchedItemsWithRCInfoQuery
+*/
+   public function testModifyWatchedItemsWithRCInfoQuery_not_review() {
+   $options = [
+   'filters' => [ '!oresreview' ],
+   'includeFields' => [ 'oresscores' ],
+   'usedInGenerator' => false,
+   ];
+   $tables = [];
+   $fields = [];
+   $conds = [];
+   $dbOptions = [];
+   $joinConds = [];
+   $db = wfGetDB( DB_MASTER );
+   $service = new WatchedItemQueryServiceExtension();
+   $service->modifyWatchedItemsWithRCInfoQuery(
+   $this->user, $options, $db, $tables, $fields, $conds,
+   $dbOptions, $joinConds );
+
+   $this->assertEquals( [
+   'rc_this_oldid',
+   'rc_type',
+   ], $fields );
+   $this->assertEquals( [
+   'ores_model',
+   'ores_classification',
+   ], $tables );
+   $this->assertEquals( [
+   '(oresc_probability <= \'0.16\') OR (oresc_probability 
IS NULL)',
+   ], $conds );
+   $this->assertEquals( [
+   'ores_classification' => [ 'LEFT JOIN', [
+   'rc_this_oldid=oresc_rev',
+