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 0000000..e988fa9 --- /dev/null +++ b/tests/phpunit/includes/WatchedItemQueryServiceExtensionTest.php @@ -0,0 +1,120 @@ +<?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\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' => 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: merged Gerrit-Change-Id: I074762b884cd34ae13f2fd71d654f6ddd309c8b3 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