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 0000000..11523e3
--- /dev/null
+++ b/tests/phpunit/includes/WatchedItemQueryServiceExtensionTest.php
@@ -0,0 +1,119 @@
+<?php
+
+namespace ORES\Tests;
+
+use ORES\Storage\HashModelLookup;
+use ORES\WatchedItemQueryServiceExtension;
+
+/**
+ * @group ORES
+ * @covers ORES\WatchedItemQueryServiceExtension
+ */
+class WatchedItemQueryServiceExtensionTest extends \MediaWikiTestCase {
+
+ protected $user;
+
+ protected function setUp() {
+ parent::setUp();
+
+ $this->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',
+ 'oresc_model' => 5,
+ 'oresc_class' => 1,
+ ], ],
+ ], $joinConds );
+ }
+}
--
To view, visit https://gerrit.wikimedia.org/r/403227
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I074762b884cd34ae13f2fd71d654f6ddd309c8b3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ORES
Gerrit-Branch: master
Gerrit-Owner: Awight <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits