Legoktm has uploaded a new change for review. https://gerrit.wikimedia.org/r/149790
Change subject: Add tests for GlobalCssJsHooks::loadForUser ...................................................................... Add tests for GlobalCssJsHooks::loadForUser Change-Id: I2fb880ea9a051ad422194b925a56422a6ad367c0 --- M GlobalCssJs.hooks.php M GlobalCssJs.php A tests/GlobalCssJsHooksTest.php 3 files changed, 53 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/GlobalCssJs refs/changes/90/149790/1 diff --git a/GlobalCssJs.hooks.php b/GlobalCssJs.hooks.php index 95acfd2..3e837be 100644 --- a/GlobalCssJs.hooks.php +++ b/GlobalCssJs.hooks.php @@ -137,4 +137,13 @@ ); return true; } + + /** + * Load our unit tests + */ + public static function onUnitTestsList( array &$files ) { + $files += glob( __DIR__ . '/tests/*Test.php' ); + + return true; + } } diff --git a/GlobalCssJs.php b/GlobalCssJs.php index f03faa1..562f6af 100644 --- a/GlobalCssJs.php +++ b/GlobalCssJs.php @@ -68,3 +68,4 @@ $wgHooks['ResourceLoaderRegisterModules'][] = 'GlobalCssJsHooks::onResourceLoaderRegisterModules'; $wgHooks['EditPage::showEditForm:initial'][] = 'GlobalCssJsHooks::onEditPageshowEditForminitial'; $wgHooks['GetPreferences'][] = 'GlobalCssJsHooks::onGetPreferences'; +$wgHooks['UnitTestsList'][] = 'GlobalCssJsHooks::onUnitTestsList'; diff --git a/tests/GlobalCssJsHooksTest.php b/tests/GlobalCssJsHooksTest.php new file mode 100644 index 0000000..4f57d17 --- /dev/null +++ b/tests/GlobalCssJsHooksTest.php @@ -0,0 +1,43 @@ +<?php + +class GlobalCssJsHooksTest extends MediaWikiTestCase { + + public static function provideLoadForUser() { + return array( + array( false, false, 'Hook not called if "wiki" set to false' ), + array( 'wikiid', false, 'Hook not called if "wiki" set to wfWikiId()' ), + array( 'somewiki', true, 'Hook called if "wiki" set to "somewiki"' ), + ); + } + + /** + * @covers GlobalCssJsHooks::loadForUser + * @dataProvider provideLoadForUser + */ + public function testLoadForUser( $wiki, $assert, $desc ) { + $wiki = $wiki === 'wikiid' ? wfWikiID() : $wiki; + $us = $this; + + $this->setMwGlobals( array( + 'wgGlobalCssJsConfig' => array( + 'wiki' => $wiki, + 'source' => 'fakesource' + ), + 'wgHooks' => array( + 'LoadGlobalCssJs' => array( + function( $user, $wiki ) use ( $us, $assert, $desc ) { + // Check whether the hook was run, and whether we wanted it to be. + $us->assertTrue( $assert, $desc ); + return true; + }, + ) + ) // clear any existing hooks + ) ); + + GlobalCssJsHooks::loadForUser( new User ); + + if ( $assert === false ) { + $this->assertTrue( true ); // So the test isn't marked as risky. + } + } +} -- To view, visit https://gerrit.wikimedia.org/r/149790 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I2fb880ea9a051ad422194b925a56422a6ad367c0 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/GlobalCssJs Gerrit-Branch: master Gerrit-Owner: Legoktm <legoktm.wikipe...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits