Pmiazga has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/328430 )
Change subject: Inject preference option directly after skin select
......................................................................
Inject preference option directly after skin select
Changes:
- onGetPreferences will try to inject PagePreviews option after
skin select or on the end of section when skin select is not available
- unit tests for new behaviour
Bug: T146889
Change-Id: Id14c0774aee917b7e949ab3ba5968a038b3ca933
---
M Popups.hooks.php
M tests/phpunit/PopupsHooksTest.php
2 files changed, 44 insertions(+), 5 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Popups
refs/changes/30/328430/1
diff --git a/Popups.hooks.php b/Popups.hooks.php
index e9d1b29..198a074 100644
--- a/Popups.hooks.php
+++ b/Popups.hooks.php
@@ -55,17 +55,27 @@
if ( !$module->showPreviewsOptInOnPreferencesPage() ) {
return;
}
- $prefs[PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME] = [
+ $option = [
'type' => 'radio',
'label-message' => 'popups-prefs-optin-title',
'options' => [
wfMessage( 'popups-prefs-optin-enabled-label'
)->text()
- => PopupsContext::PREVIEWS_ENABLED,
+ => PopupsContext::PREVIEWS_ENABLED,
wfMessage( 'popups-prefs-optin-disabled-label'
)->text()
- => PopupsContext::PREVIEWS_DISABLED
+ => PopupsContext::PREVIEWS_DISABLED
],
'section' => self::PREVIEWS_PREFERENCES_SECTION
];
+ $skinPosition = array_search( 'skin', array_keys( $prefs ) );
+
+ if ( $skinPosition !== false ) {
+ $injectIntoIndex = $skinPosition + 1;
+ $prefs = array_slice( $prefs, 0, $injectIntoIndex, true
)
+ + [
PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME => $option ]
+ + array_slice( $prefs, $injectIntoIndex, count(
$prefs ) - 1, true );
+ } else {
+ $prefs[ PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME ]
= $option;
+ }
}
public static function onBeforePageDisplay( OutputPage &$out, Skin
&$skin ) {
diff --git a/tests/phpunit/PopupsHooksTest.php
b/tests/phpunit/PopupsHooksTest.php
index a2dd1e3..8825233 100644
--- a/tests/phpunit/PopupsHooksTest.php
+++ b/tests/phpunit/PopupsHooksTest.php
@@ -86,12 +86,41 @@
->will( $this->returnValue( true ) );
PopupsContextTestWrapper::injectTestInstance( $contextMock );
- $prefs = [ 'someNotEmptyValue' => 'notEmpty' ];
+ $prefs = [
+ 'someNotEmptyValue' => 'notEmpty',
+ 'skin' => 'skin stuff',
+ 'other' => 'notEmpty'
+ ];
PopupsHooks::onGetPreferences( $this->getTestUser()->getUser(),
$prefs );
- $this->assertCount( 2, $prefs );
+ $this->assertCount( 4, $prefs );
$this->assertEquals( 'notEmpty', $prefs[ 'someNotEmptyValue'] );
$this->assertArrayHasKey(
\Popups\PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME, $prefs );
+ $this->assertEquals( 2, array_search(
\Popups\PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME,
+ array_keys( $prefs ) ), ' PagePreviews preferences
should be injected after Skin select' );
+ }
+
+ /**
+ * @covers ::onGetPreferences
+ */
+ public function
testOnGetPreferencesPreviewsEnabledWhenSkinIsNotAvailable() {
+ $contextMock = $this->getMock( PopupsContextTestWrapper::class,
+ [ 'showPreviewsOptInOnPreferencesPage' ], [
ExtensionRegistry::getInstance() ] );
+ $contextMock->expects( $this->once() )
+ ->method( 'showPreviewsOptInOnPreferencesPage' )
+ ->will( $this->returnValue( true ) );
+
+ PopupsContextTestWrapper::injectTestInstance( $contextMock );
+ $prefs = [
+ 'someNotEmptyValue' => 'notEmpty',
+ 'other' => 'notEmpty'
+ ];
+
+ PopupsHooks::onGetPreferences( $this->getTestUser()->getUser(),
$prefs );
+ $this->assertCount( 3, $prefs );
+ $this->assertArrayHasKey(
\Popups\PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME, $prefs );
+ $this->assertEquals( 2, array_search(
\Popups\PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME,
+ array_keys( $prefs ) ), ' PagePreviews should be
injected at end of array' );
}
/**
--
To view, visit https://gerrit.wikimedia.org/r/328430
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Id14c0774aee917b7e949ab3ba5968a038b3ca933
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Popups
Gerrit-Branch: mpga
Gerrit-Owner: Pmiazga <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits