mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-11-17 20:52:14 +00:00
ee6974ad35
Please note I7e06a4cc226f3434c0f655212a464b8b98bcc7f4 should be merged at the same time as this patch. == The background == All extensions have been weaned of BaseTemplate hooks in Wikimedia projects. This change now means that Vector will no longer run any BaseTemplate hooks. See the epic T253809 for the implementation details. == The change == BaseTemplate will now have nothing to do with the rendering of Vector. The skin version is added to express the significance of breaking compatibility with 3rd party extensions. We TEMPORARILY remove SkinVector to retain git blame. SkinTemplateVector will be renamed SkinVector in the follow up (see 2/2) Update skin.json to use SkinTemplateVector for the skin (this will be fixed in a follow up). The isLegacy method is moved to SkinTemplateVector. Changes of note: * html-debuglog is no longer needed. SkinMustache includes this information on the skins behalf * html-printtail and html-headelement are now not needed in the master template and added by SkinMustache * Skin::getAfterPortlet does not provide the `after-portlet` wrapping element provided by BaseTemplate::getAfterPortlet so this is added * SkinTemplate::getFooterIcons does not support the options that BaseTemplate::getFooterIcons does so any icons which do not have an image must be manually checked for and unset Known changes to HTML output as a result of intentionally delegating their output to the core SkinMustache class: * A new line is removed between the body element and #mw-page-base * #mw-html-debug-log now appears at the end of the body element * #printfooter is now a child of #mw-content-text rather than sibling. Bug: T251212 Change-Id: I4e89beb96f6401ed7e51bafdf0aac408f5a2c42f
327 lines
8.4 KiB
PHP
327 lines
8.4 KiB
PHP
<?php
|
|
/*
|
|
* @file
|
|
* @ingroup skins
|
|
*/
|
|
|
|
use Vector\Hooks;
|
|
|
|
const SKIN_PREFS_SECTION = 'rendering/skin/skin-prefs';
|
|
|
|
/**
|
|
* Integration tests for Vector Hooks.
|
|
*
|
|
* @group Vector
|
|
* @coversDefaultClass \Vector\Hooks
|
|
*/
|
|
class VectorHooksTest extends \MediaWikiTestCase {
|
|
/**
|
|
* @covers ::onGetPreferences
|
|
*/
|
|
public function testOnGetPreferencesShowPreferencesDisabled() {
|
|
$config = new HashConfig( [
|
|
'VectorShowSkinPreferences' => false,
|
|
] );
|
|
$this->setService( 'Vector.Config', $config );
|
|
|
|
$prefs = [];
|
|
Hooks::onGetPreferences( $this->getTestUser()->getUser(), $prefs );
|
|
$this->assertSame( $prefs, [], 'No preferences are added.' );
|
|
}
|
|
|
|
/**
|
|
* @covers ::onGetPreferences
|
|
*/
|
|
public function testOnGetPreferencesShowPreferencesEnabledSkinSectionFoundLegacy() {
|
|
$config = new HashConfig( [
|
|
'VectorShowSkinPreferences' => true,
|
|
// '1' is Legacy.
|
|
'VectorDefaultSkinVersionForExistingAccounts' => '1',
|
|
'VectorDefaultSidebarVisibleForAuthorisedUser' => true
|
|
] );
|
|
$this->setService( 'Vector.Config', $config );
|
|
|
|
$prefs = [
|
|
'foo' => [],
|
|
'skin' => [],
|
|
'bar' => []
|
|
];
|
|
Hooks::onGetPreferences( $this->getTestUser()->getUser(), $prefs );
|
|
$this->assertSame(
|
|
$prefs,
|
|
[
|
|
'foo' => [],
|
|
'skin' => [],
|
|
'VectorSkinVersion' => [
|
|
'type' => 'toggle',
|
|
'label-message' => 'prefs-vector-enable-vector-1-label',
|
|
'help-message' => 'prefs-vector-enable-vector-1-help',
|
|
'section' => SKIN_PREFS_SECTION,
|
|
// '1' is enabled which means Legacy.
|
|
'default' => '1',
|
|
'hide-if' => [ '!==', 'wpskin', 'vector' ]
|
|
],
|
|
'VectorSidebarVisible' => [
|
|
'type' => 'api',
|
|
'default' => true
|
|
],
|
|
'bar' => []
|
|
],
|
|
'Preferences are inserted directly after skin.'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @covers ::onGetPreferences
|
|
*/
|
|
public function testOnGetPreferencesShowPreferencesEnabledSkinSectionMissingLegacy() {
|
|
$config = new HashConfig( [
|
|
'VectorShowSkinPreferences' => true,
|
|
// '1' is Legacy.
|
|
'VectorDefaultSkinVersionForExistingAccounts' => '1',
|
|
'VectorDefaultSidebarVisibleForAuthorisedUser' => true
|
|
] );
|
|
$this->setService( 'Vector.Config', $config );
|
|
|
|
$prefs = [
|
|
'foo' => [],
|
|
'bar' => []
|
|
];
|
|
Hooks::onGetPreferences( $this->getTestUser()->getUser(), $prefs );
|
|
$this->assertSame(
|
|
$prefs,
|
|
[
|
|
'foo' => [],
|
|
'bar' => [],
|
|
'VectorSkinVersion' => [
|
|
'type' => 'toggle',
|
|
'label-message' => 'prefs-vector-enable-vector-1-label',
|
|
'help-message' => 'prefs-vector-enable-vector-1-help',
|
|
'section' => SKIN_PREFS_SECTION,
|
|
// '1' is enabled which means Legacy.
|
|
'default' => '1',
|
|
'hide-if' => [ '!==', 'wpskin', 'vector' ]
|
|
],
|
|
'VectorSidebarVisible' => [
|
|
'type' => 'api',
|
|
'default' => true
|
|
],
|
|
],
|
|
'Preferences are appended.'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @covers ::onGetPreferences
|
|
*/
|
|
public function testOnGetPreferencesShowPreferencesEnabledSkinSectionMissingLatest() {
|
|
$config = new HashConfig( [
|
|
'VectorShowSkinPreferences' => true,
|
|
// '2' is latest.
|
|
'VectorDefaultSkinVersionForExistingAccounts' => '2',
|
|
'VectorDefaultSidebarVisibleForAuthorisedUser' => true
|
|
] );
|
|
$this->setService( 'Vector.Config', $config );
|
|
|
|
$prefs = [
|
|
'foo' => [],
|
|
'bar' => [],
|
|
];
|
|
Hooks::onGetPreferences( $this->getTestUser()->getUser(), $prefs );
|
|
$this->assertSame(
|
|
$prefs,
|
|
[
|
|
'foo' => [],
|
|
'bar' => [],
|
|
'VectorSkinVersion' => [
|
|
'type' => 'toggle',
|
|
'label-message' => 'prefs-vector-enable-vector-1-label',
|
|
'help-message' => 'prefs-vector-enable-vector-1-help',
|
|
'section' => SKIN_PREFS_SECTION,
|
|
// '0' is disabled (which means latest).
|
|
'default' => '0',
|
|
'hide-if' => [ '!==', 'wpskin', 'vector' ]
|
|
],
|
|
'VectorSidebarVisible' => [
|
|
'type' => 'api',
|
|
'default' => true
|
|
],
|
|
],
|
|
'Legacy skin version is disabled.'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @covers ::onPreferencesFormPreSave
|
|
*/
|
|
public function testOnPreferencesFormPreSaveVectorEnabledLegacyNewPreference() {
|
|
$formData = [
|
|
'skin' => 'vector',
|
|
// True is Legacy.
|
|
'VectorSkinVersion' => true,
|
|
];
|
|
$form = $this->createMock( HTMLForm::class );
|
|
$user = $this->createMock( \User::class );
|
|
$user->expects( $this->once() )
|
|
->method( 'setOption' )
|
|
// '1' is Legacy.
|
|
->with( 'VectorSkinVersion', '1' );
|
|
$result = true;
|
|
$oldPreferences = [];
|
|
|
|
Hooks::onPreferencesFormPreSave( $formData, $form, $user, $result, $oldPreferences );
|
|
}
|
|
|
|
/**
|
|
* @covers ::onPreferencesFormPreSave
|
|
*/
|
|
public function testOnPreferencesFormPreSaveVectorEnabledLatestNewPreference() {
|
|
$formData = [
|
|
'skin' => 'vector',
|
|
// False is latest.
|
|
'VectorSkinVersion' => false,
|
|
];
|
|
$form = $this->createMock( HTMLForm::class );
|
|
$user = $this->createMock( \User::class );
|
|
$user->expects( $this->once() )
|
|
->method( 'setOption' )
|
|
// '2' is latest.
|
|
->with( 'VectorSkinVersion', '2' );
|
|
$result = true;
|
|
$oldPreferences = [];
|
|
|
|
Hooks::onPreferencesFormPreSave( $formData, $form, $user, $result, $oldPreferences );
|
|
}
|
|
|
|
/**
|
|
* @covers ::onPreferencesFormPreSave
|
|
*/
|
|
public function testOnPreferencesFormPreSaveVectorEnabledNoNewPreference() {
|
|
$formData = [
|
|
'skin' => 'vector',
|
|
];
|
|
$form = $this->createMock( HTMLForm::class );
|
|
$user = $this->createMock( \User::class );
|
|
$user->expects( $this->never() )
|
|
->method( 'setOption' );
|
|
$result = true;
|
|
$oldPreferences = [];
|
|
|
|
Hooks::onPreferencesFormPreSave( $formData, $form, $user, $result, $oldPreferences );
|
|
}
|
|
|
|
/**
|
|
* @covers ::onPreferencesFormPreSave
|
|
*/
|
|
public function testOnPreferencesFormPreSaveVectorDisabledNoOldPreference() {
|
|
$formData = [
|
|
// False is latest.
|
|
'VectorSkinVersion' => false,
|
|
];
|
|
$form = $this->createMock( HTMLForm::class );
|
|
$user = $this->createMock( \User::class );
|
|
$user->expects( $this->never() )
|
|
->method( 'setOption' );
|
|
$result = true;
|
|
$oldPreferences = [];
|
|
|
|
Hooks::onPreferencesFormPreSave( $formData, $form, $user, $result, $oldPreferences );
|
|
}
|
|
|
|
/**
|
|
* @covers ::onPreferencesFormPreSave
|
|
*/
|
|
public function testOnPreferencesFormPreSaveVectorDisabledOldPreference() {
|
|
$formData = [
|
|
// False is latest.
|
|
'VectorSkinVersion' => false,
|
|
];
|
|
$form = $this->createMock( HTMLForm::class );
|
|
$user = $this->createMock( \User::class );
|
|
$user->expects( $this->once() )
|
|
->method( 'setOption' )
|
|
->with( 'VectorSkinVersion', 'old' );
|
|
$result = true;
|
|
$oldPreferences = [
|
|
'VectorSkinVersion' => 'old',
|
|
];
|
|
|
|
Hooks::onPreferencesFormPreSave( $formData, $form, $user, $result, $oldPreferences );
|
|
}
|
|
|
|
/**
|
|
* @covers ::onLocalUserCreated
|
|
*/
|
|
public function testOnLocalUserCreatedLegacy() {
|
|
$config = new HashConfig( [
|
|
// '1' is Legacy.
|
|
'VectorDefaultSkinVersionForNewAccounts' => '1',
|
|
] );
|
|
$this->setService( 'Vector.Config', $config );
|
|
|
|
$user = $this->createMock( \User::class );
|
|
$user->expects( $this->once() )
|
|
->method( 'setOption' )
|
|
// '1' is Legacy.
|
|
->with( 'VectorSkinVersion', '1' );
|
|
$isAutoCreated = false;
|
|
Hooks::onLocalUserCreated( $user, $isAutoCreated );
|
|
}
|
|
|
|
/**
|
|
* @covers ::onLocalUserCreated
|
|
*/
|
|
public function testOnLocalUserCreatedLatest() {
|
|
$config = new HashConfig( [
|
|
// '2' is latest.
|
|
'VectorDefaultSkinVersionForNewAccounts' => '2',
|
|
] );
|
|
$this->setService( 'Vector.Config', $config );
|
|
|
|
$user = $this->createMock( \User::class );
|
|
$user->expects( $this->once() )
|
|
->method( 'setOption' )
|
|
// '2' is latest.
|
|
->with( 'VectorSkinVersion', '2' );
|
|
$isAutoCreated = false;
|
|
Hooks::onLocalUserCreated( $user, $isAutoCreated );
|
|
}
|
|
|
|
/**
|
|
* @covers ::onSkinTemplateNavigation
|
|
*/
|
|
public function testOnSkinTemplateNavigation() {
|
|
$this->setMwGlobals( [
|
|
'wgVectorUseIconWatch' => true
|
|
] );
|
|
$skin = new SkinTemplateVector( [ 'name' => 'vector' ] );
|
|
$contentNavWatch = [
|
|
'actions' => [
|
|
'watch' => [ 'class' => 'watch' ],
|
|
]
|
|
];
|
|
$contentNavUnWatch = [
|
|
'actions' => [
|
|
'move' => [ 'class' => 'move' ],
|
|
'unwatch' => [],
|
|
],
|
|
];
|
|
|
|
Hooks::onSkinTemplateNavigation( $skin, $contentNavUnWatch );
|
|
Hooks::onSkinTemplateNavigation( $skin, $contentNavWatch );
|
|
|
|
$this->assertTrue(
|
|
strpos( $contentNavWatch['views']['watch']['class'], 'icon' ) !== false,
|
|
'Watch list items require an "icon" class'
|
|
);
|
|
$this->assertTrue(
|
|
strpos( $contentNavUnWatch['views']['unwatch']['class'], 'icon' ) !== false,
|
|
'Unwatch list items require an "icon" class'
|
|
);
|
|
$this->assertFalse(
|
|
strpos( $contentNavUnWatch['actions']['move']['class'], 'icon' ) !== false,
|
|
'List item other than watch or unwatch should not have an "icon" class'
|
|
);
|
|
}
|
|
}
|