VectorGOLEM/tests/phpunit/integration/VectorHooksTest.php

383 lines
9.5 KiB
PHP
Raw Normal View History

[Special:Preferences] [PHP] Add skin version user preference and configs Add a Vector-specific user preference to Special:Preferences for toggling skin version, either Legacy Vector or the latest Vector. The presentation of the new preference section and the default values for anonymous, new, and existing accounts are configurable via $wgVectorShowSkinPreferences, $wgVectorDefaultSkinVersion (to be used by the feature manager in T244481), $wgVectorDefaultSkinVersionForExistingAccounts, and $wgVectorDefaultSkinVersionForNewAccounts. These configurations default to the fullest experience so that third-party configuration is minimal. See skin.json for details. The configurations are each tested in VectorHooksTest.php. When presentation is enabled, the new preference appears as a checkbox; enabled is Legacy mode and disable is latest. There are a number of unfortunate details: - Showing and hiding a checkbox is supported by OOUI. Showing and hiding a whole section (Vector skin preferences, in this case) is not so this additional client JavaScript functionality is added in Core (see Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377). - Stylization as a checkbox is wanted. However, the implied storage type for OOUI checkboxes is a boolean. This is not wanted in the event that another skin version is added (e.g., '3' or 'alpha'). As a workaround, the preference is converted from a boolean to a version string ('1' or '2') on save in Hooks::onPreferencesFormPreSave() and from a version string to a checkbox enable / disable string ('1' or '0') in onGetPreferences(). There a number of test cases to help cover these concerning details. Documentation for overriding the skin version as a URL query parameter is provided in anticipation of T244481. Bug: T242381 Bug: T245793 Depends-On: Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377 Depends-On: Ifc2863fca9cd9efd11ac30c780420e8d89e8cb22 Change-Id: I177dad88fc982170641059b6a4f53fbb38eefad6
2020-01-23 21:53:09 +00:00
<?php
/*
* @file
* @ingroup skins
*/
use Vector\Constants;
use Vector\FeatureManagement\FeatureManager;
[Special:Preferences] [PHP] Add skin version user preference and configs Add a Vector-specific user preference to Special:Preferences for toggling skin version, either Legacy Vector or the latest Vector. The presentation of the new preference section and the default values for anonymous, new, and existing accounts are configurable via $wgVectorShowSkinPreferences, $wgVectorDefaultSkinVersion (to be used by the feature manager in T244481), $wgVectorDefaultSkinVersionForExistingAccounts, and $wgVectorDefaultSkinVersionForNewAccounts. These configurations default to the fullest experience so that third-party configuration is minimal. See skin.json for details. The configurations are each tested in VectorHooksTest.php. When presentation is enabled, the new preference appears as a checkbox; enabled is Legacy mode and disable is latest. There are a number of unfortunate details: - Showing and hiding a checkbox is supported by OOUI. Showing and hiding a whole section (Vector skin preferences, in this case) is not so this additional client JavaScript functionality is added in Core (see Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377). - Stylization as a checkbox is wanted. However, the implied storage type for OOUI checkboxes is a boolean. This is not wanted in the event that another skin version is added (e.g., '3' or 'alpha'). As a workaround, the preference is converted from a boolean to a version string ('1' or '2') on save in Hooks::onPreferencesFormPreSave() and from a version string to a checkbox enable / disable string ('1' or '0') in onGetPreferences(). There a number of test cases to help cover these concerning details. Documentation for overriding the skin version as a URL query parameter is provided in anticipation of T244481. Bug: T242381 Bug: T245793 Depends-On: Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377 Depends-On: Ifc2863fca9cd9efd11ac30c780420e8d89e8cb22 Change-Id: I177dad88fc982170641059b6a4f53fbb38eefad6
2020-01-23 21:53:09 +00:00
use Vector\Hooks;
use Vector\HTMLForm\Fields\HTMLLegacySkinVersionField;
[Special:Preferences] [PHP] Add skin version user preference and configs Add a Vector-specific user preference to Special:Preferences for toggling skin version, either Legacy Vector or the latest Vector. The presentation of the new preference section and the default values for anonymous, new, and existing accounts are configurable via $wgVectorShowSkinPreferences, $wgVectorDefaultSkinVersion (to be used by the feature manager in T244481), $wgVectorDefaultSkinVersionForExistingAccounts, and $wgVectorDefaultSkinVersionForNewAccounts. These configurations default to the fullest experience so that third-party configuration is minimal. See skin.json for details. The configurations are each tested in VectorHooksTest.php. When presentation is enabled, the new preference appears as a checkbox; enabled is Legacy mode and disable is latest. There are a number of unfortunate details: - Showing and hiding a checkbox is supported by OOUI. Showing and hiding a whole section (Vector skin preferences, in this case) is not so this additional client JavaScript functionality is added in Core (see Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377). - Stylization as a checkbox is wanted. However, the implied storage type for OOUI checkboxes is a boolean. This is not wanted in the event that another skin version is added (e.g., '3' or 'alpha'). As a workaround, the preference is converted from a boolean to a version string ('1' or '2') on save in Hooks::onPreferencesFormPreSave() and from a version string to a checkbox enable / disable string ('1' or '0') in onGetPreferences(). There a number of test cases to help cover these concerning details. Documentation for overriding the skin version as a URL query parameter is provided in anticipation of T244481. Bug: T242381 Bug: T245793 Depends-On: Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377 Depends-On: Ifc2863fca9cd9efd11ac30c780420e8d89e8cb22 Change-Id: I177dad88fc982170641059b6a4f53fbb38eefad6
2020-01-23 21:53:09 +00:00
/**
* Integration tests for Vector Hooks.
*
* @group Vector
* @coversDefaultClass \Vector\Hooks
*/
class VectorHooksTest extends MediaWikiIntegrationTestCase {
private const SKIN_PREFS_SECTION = 'rendering/skin/skin-prefs';
/**
* @param bool $excludeMainPage
* @param array $excludeNamespaces
* @param array $include
* @param array $querystring
* @return array
*/
private static function makeMaxWidthConfig(
$excludeMainPage,
$excludeNamespaces = [],
$include = [],
$querystring = []
) {
return [
'exclude' => [
'mainpage' => $excludeMainPage,
'namespaces' => $excludeNamespaces,
'querystring' => $querystring,
],
'include' => $include
];
}
/**
* @covers ::shouldDisableMaxWidth
*/
public function providerShouldDisableMaxWidth() {
$excludeTalkFooConfig = self::makeMaxWidthConfig(
false,
[ NS_TALK ],
[ 'Talk:Foo' ],
[]
);
return [
[
'No options, nothing disables max width',
[],
Title::makeTitle( NS_MAIN, 'Foo' ),
[],
false
],
[
'Main page disables max width if exclude.mainpage set',
self::makeMaxWidthConfig( true ),
Title::newMainPage(),
[],
true
],
[
'Namespaces can be excluded',
self::makeMaxWidthConfig( false, [ NS_CATEGORY ] ),
Title::makeTitle( NS_CATEGORY, 'Category' ),
[],
true
],
[
'Namespaces are included if not excluded',
self::makeMaxWidthConfig( false, [ NS_CATEGORY ] ),
Title::makeTitle( NS_SPECIAL, 'SpecialPages' ),
[],
false
],
[
'More than one namespace can be included',
self::makeMaxWidthConfig( false, [ NS_CATEGORY, NS_SPECIAL ] ),
Title::makeTitle( NS_SPECIAL, 'Specialpages' ),
[],
true
],
[
'Can be disabled on history page',
self::makeMaxWidthConfig(
false,
[
/* no namespaces excluded */
],
[
/* no includes */
],
[ 'action' => 'history' ]
),
Title::makeTitle( NS_MAIN, 'History page' ),
[ 'action' => 'history' ],
true
],
[
'Include can override exclusions',
self::makeMaxWidthConfig(
false,
[ NS_CATEGORY, NS_SPECIAL ],
[ 'Special:Specialpages' ],
[ 'action' => 'history' ]
),
Title::makeTitle( NS_SPECIAL, 'Specialpages' ),
[ 'action' => 'history' ],
false
],
[
'Max width can be disabled on talk pages',
$excludeTalkFooConfig,
Title::makeTitle( NS_TALK, 'A talk page' ),
[],
true
],
[
'includes can be used to override any page in a disabled namespace',
$excludeTalkFooConfig,
Title::makeTitle( NS_TALK, 'Foo' ),
[],
false
],
[
'Excludes/includes are based on root title so should apply to subpages',
$excludeTalkFooConfig,
Title::makeTitle( NS_TALK, 'Foo/subpage' ),
[],
false
]
];
}
/**
* @covers ::shouldDisableMaxWidth
* @dataProvider providerShouldDisableMaxWidth
*/
public function testShouldDisableMaxWidth(
$msg,
$options,
$title,
$requestValues,
$shouldDisableMaxWidth
) {
$this->assertSame(
$shouldDisableMaxWidth,
Hooks::shouldDisableMaxWidth( $options, $title, $requestValues ),
$msg
);
}
[Special:Preferences] [PHP] Add skin version user preference and configs Add a Vector-specific user preference to Special:Preferences for toggling skin version, either Legacy Vector or the latest Vector. The presentation of the new preference section and the default values for anonymous, new, and existing accounts are configurable via $wgVectorShowSkinPreferences, $wgVectorDefaultSkinVersion (to be used by the feature manager in T244481), $wgVectorDefaultSkinVersionForExistingAccounts, and $wgVectorDefaultSkinVersionForNewAccounts. These configurations default to the fullest experience so that third-party configuration is minimal. See skin.json for details. The configurations are each tested in VectorHooksTest.php. When presentation is enabled, the new preference appears as a checkbox; enabled is Legacy mode and disable is latest. There are a number of unfortunate details: - Showing and hiding a checkbox is supported by OOUI. Showing and hiding a whole section (Vector skin preferences, in this case) is not so this additional client JavaScript functionality is added in Core (see Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377). - Stylization as a checkbox is wanted. However, the implied storage type for OOUI checkboxes is a boolean. This is not wanted in the event that another skin version is added (e.g., '3' or 'alpha'). As a workaround, the preference is converted from a boolean to a version string ('1' or '2') on save in Hooks::onPreferencesFormPreSave() and from a version string to a checkbox enable / disable string ('1' or '0') in onGetPreferences(). There a number of test cases to help cover these concerning details. Documentation for overriding the skin version as a URL query parameter is provided in anticipation of T244481. Bug: T242381 Bug: T245793 Depends-On: Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377 Depends-On: Ifc2863fca9cd9efd11ac30c780420e8d89e8cb22 Change-Id: I177dad88fc982170641059b6a4f53fbb38eefad6
2020-01-23 21:53:09 +00:00
/**
* @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.' );
[Special:Preferences] [PHP] Add skin version user preference and configs Add a Vector-specific user preference to Special:Preferences for toggling skin version, either Legacy Vector or the latest Vector. The presentation of the new preference section and the default values for anonymous, new, and existing accounts are configurable via $wgVectorShowSkinPreferences, $wgVectorDefaultSkinVersion (to be used by the feature manager in T244481), $wgVectorDefaultSkinVersionForExistingAccounts, and $wgVectorDefaultSkinVersionForNewAccounts. These configurations default to the fullest experience so that third-party configuration is minimal. See skin.json for details. The configurations are each tested in VectorHooksTest.php. When presentation is enabled, the new preference appears as a checkbox; enabled is Legacy mode and disable is latest. There are a number of unfortunate details: - Showing and hiding a checkbox is supported by OOUI. Showing and hiding a whole section (Vector skin preferences, in this case) is not so this additional client JavaScript functionality is added in Core (see Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377). - Stylization as a checkbox is wanted. However, the implied storage type for OOUI checkboxes is a boolean. This is not wanted in the event that another skin version is added (e.g., '3' or 'alpha'). As a workaround, the preference is converted from a boolean to a version string ('1' or '2') on save in Hooks::onPreferencesFormPreSave() and from a version string to a checkbox enable / disable string ('1' or '0') in onGetPreferences(). There a number of test cases to help cover these concerning details. Documentation for overriding the skin version as a URL query parameter is provided in anticipation of T244481. Bug: T242381 Bug: T245793 Depends-On: Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377 Depends-On: Ifc2863fca9cd9efd11ac30c780420e8d89e8cb22 Change-Id: I177dad88fc982170641059b6a4f53fbb38eefad6
2020-01-23 21:53:09 +00:00
}
private function setFeatureLatestSkinVersionIsEnabled( $isEnabled ) {
$featureManager = new FeatureManager();
$featureManager->registerSimpleRequirement( Constants::REQUIREMENT_LATEST_SKIN_VERSION, $isEnabled );
$featureManager->registerFeature( Constants::FEATURE_LATEST_SKIN, [
Constants::REQUIREMENT_LATEST_SKIN_VERSION
] );
$this->setService( Constants::SERVICE_FEATURE_MANAGER, $featureManager );
}
[Special:Preferences] [PHP] Add skin version user preference and configs Add a Vector-specific user preference to Special:Preferences for toggling skin version, either Legacy Vector or the latest Vector. The presentation of the new preference section and the default values for anonymous, new, and existing accounts are configurable via $wgVectorShowSkinPreferences, $wgVectorDefaultSkinVersion (to be used by the feature manager in T244481), $wgVectorDefaultSkinVersionForExistingAccounts, and $wgVectorDefaultSkinVersionForNewAccounts. These configurations default to the fullest experience so that third-party configuration is minimal. See skin.json for details. The configurations are each tested in VectorHooksTest.php. When presentation is enabled, the new preference appears as a checkbox; enabled is Legacy mode and disable is latest. There are a number of unfortunate details: - Showing and hiding a checkbox is supported by OOUI. Showing and hiding a whole section (Vector skin preferences, in this case) is not so this additional client JavaScript functionality is added in Core (see Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377). - Stylization as a checkbox is wanted. However, the implied storage type for OOUI checkboxes is a boolean. This is not wanted in the event that another skin version is added (e.g., '3' or 'alpha'). As a workaround, the preference is converted from a boolean to a version string ('1' or '2') on save in Hooks::onPreferencesFormPreSave() and from a version string to a checkbox enable / disable string ('1' or '0') in onGetPreferences(). There a number of test cases to help cover these concerning details. Documentation for overriding the skin version as a URL query parameter is provided in anticipation of T244481. Bug: T242381 Bug: T245793 Depends-On: Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377 Depends-On: Ifc2863fca9cd9efd11ac30c780420e8d89e8cb22 Change-Id: I177dad88fc982170641059b6a4f53fbb38eefad6
2020-01-23 21:53:09 +00:00
/**
* @covers ::onGetPreferences
*/
public function testOnGetPreferencesShowPreferencesEnabledSkinSectionFoundLegacy() {
$isLegacy = true;
$this->setFeatureLatestSkinVersionIsEnabled( !$isLegacy );
[Special:Preferences] [PHP] Add skin version user preference and configs Add a Vector-specific user preference to Special:Preferences for toggling skin version, either Legacy Vector or the latest Vector. The presentation of the new preference section and the default values for anonymous, new, and existing accounts are configurable via $wgVectorShowSkinPreferences, $wgVectorDefaultSkinVersion (to be used by the feature manager in T244481), $wgVectorDefaultSkinVersionForExistingAccounts, and $wgVectorDefaultSkinVersionForNewAccounts. These configurations default to the fullest experience so that third-party configuration is minimal. See skin.json for details. The configurations are each tested in VectorHooksTest.php. When presentation is enabled, the new preference appears as a checkbox; enabled is Legacy mode and disable is latest. There are a number of unfortunate details: - Showing and hiding a checkbox is supported by OOUI. Showing and hiding a whole section (Vector skin preferences, in this case) is not so this additional client JavaScript functionality is added in Core (see Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377). - Stylization as a checkbox is wanted. However, the implied storage type for OOUI checkboxes is a boolean. This is not wanted in the event that another skin version is added (e.g., '3' or 'alpha'). As a workaround, the preference is converted from a boolean to a version string ('1' or '2') on save in Hooks::onPreferencesFormPreSave() and from a version string to a checkbox enable / disable string ('1' or '0') in onGetPreferences(). There a number of test cases to help cover these concerning details. Documentation for overriding the skin version as a URL query parameter is provided in anticipation of T244481. Bug: T242381 Bug: T245793 Depends-On: Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377 Depends-On: Ifc2863fca9cd9efd11ac30c780420e8d89e8cb22 Change-Id: I177dad88fc982170641059b6a4f53fbb38eefad6
2020-01-23 21:53:09 +00:00
$prefs = [
'foo' => [],
'skin' => [],
'bar' => []
];
Hooks::onGetPreferences( $this->getTestUser()->getUser(), $prefs );
$this->assertEquals(
[Special:Preferences] [PHP] Add skin version user preference and configs Add a Vector-specific user preference to Special:Preferences for toggling skin version, either Legacy Vector or the latest Vector. The presentation of the new preference section and the default values for anonymous, new, and existing accounts are configurable via $wgVectorShowSkinPreferences, $wgVectorDefaultSkinVersion (to be used by the feature manager in T244481), $wgVectorDefaultSkinVersionForExistingAccounts, and $wgVectorDefaultSkinVersionForNewAccounts. These configurations default to the fullest experience so that third-party configuration is minimal. See skin.json for details. The configurations are each tested in VectorHooksTest.php. When presentation is enabled, the new preference appears as a checkbox; enabled is Legacy mode and disable is latest. There are a number of unfortunate details: - Showing and hiding a checkbox is supported by OOUI. Showing and hiding a whole section (Vector skin preferences, in this case) is not so this additional client JavaScript functionality is added in Core (see Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377). - Stylization as a checkbox is wanted. However, the implied storage type for OOUI checkboxes is a boolean. This is not wanted in the event that another skin version is added (e.g., '3' or 'alpha'). As a workaround, the preference is converted from a boolean to a version string ('1' or '2') on save in Hooks::onPreferencesFormPreSave() and from a version string to a checkbox enable / disable string ('1' or '0') in onGetPreferences(). There a number of test cases to help cover these concerning details. Documentation for overriding the skin version as a URL query parameter is provided in anticipation of T244481. Bug: T242381 Bug: T245793 Depends-On: Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377 Depends-On: Ifc2863fca9cd9efd11ac30c780420e8d89e8cb22 Change-Id: I177dad88fc982170641059b6a4f53fbb38eefad6
2020-01-23 21:53:09 +00:00
[
'foo' => [],
'skin' => [],
'VectorSkinVersion' => [
'class' => HTMLLegacySkinVersionField::class,
[Special:Preferences] [PHP] Add skin version user preference and configs Add a Vector-specific user preference to Special:Preferences for toggling skin version, either Legacy Vector or the latest Vector. The presentation of the new preference section and the default values for anonymous, new, and existing accounts are configurable via $wgVectorShowSkinPreferences, $wgVectorDefaultSkinVersion (to be used by the feature manager in T244481), $wgVectorDefaultSkinVersionForExistingAccounts, and $wgVectorDefaultSkinVersionForNewAccounts. These configurations default to the fullest experience so that third-party configuration is minimal. See skin.json for details. The configurations are each tested in VectorHooksTest.php. When presentation is enabled, the new preference appears as a checkbox; enabled is Legacy mode and disable is latest. There are a number of unfortunate details: - Showing and hiding a checkbox is supported by OOUI. Showing and hiding a whole section (Vector skin preferences, in this case) is not so this additional client JavaScript functionality is added in Core (see Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377). - Stylization as a checkbox is wanted. However, the implied storage type for OOUI checkboxes is a boolean. This is not wanted in the event that another skin version is added (e.g., '3' or 'alpha'). As a workaround, the preference is converted from a boolean to a version string ('1' or '2') on save in Hooks::onPreferencesFormPreSave() and from a version string to a checkbox enable / disable string ('1' or '0') in onGetPreferences(). There a number of test cases to help cover these concerning details. Documentation for overriding the skin version as a URL query parameter is provided in anticipation of T244481. Bug: T242381 Bug: T245793 Depends-On: Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377 Depends-On: Ifc2863fca9cd9efd11ac30c780420e8d89e8cb22 Change-Id: I177dad88fc982170641059b6a4f53fbb38eefad6
2020-01-23 21:53:09 +00:00
'label-message' => 'prefs-vector-enable-vector-1-label',
'help-message' => 'prefs-vector-enable-vector-1-help',
'section' => self::SKIN_PREFS_SECTION,
'default' => $isLegacy,
'hide-if' => [ '!==', 'wpskin', Constants::SKIN_NAME ]
[Special:Preferences] [PHP] Add skin version user preference and configs Add a Vector-specific user preference to Special:Preferences for toggling skin version, either Legacy Vector or the latest Vector. The presentation of the new preference section and the default values for anonymous, new, and existing accounts are configurable via $wgVectorShowSkinPreferences, $wgVectorDefaultSkinVersion (to be used by the feature manager in T244481), $wgVectorDefaultSkinVersionForExistingAccounts, and $wgVectorDefaultSkinVersionForNewAccounts. These configurations default to the fullest experience so that third-party configuration is minimal. See skin.json for details. The configurations are each tested in VectorHooksTest.php. When presentation is enabled, the new preference appears as a checkbox; enabled is Legacy mode and disable is latest. There are a number of unfortunate details: - Showing and hiding a checkbox is supported by OOUI. Showing and hiding a whole section (Vector skin preferences, in this case) is not so this additional client JavaScript functionality is added in Core (see Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377). - Stylization as a checkbox is wanted. However, the implied storage type for OOUI checkboxes is a boolean. This is not wanted in the event that another skin version is added (e.g., '3' or 'alpha'). As a workaround, the preference is converted from a boolean to a version string ('1' or '2') on save in Hooks::onPreferencesFormPreSave() and from a version string to a checkbox enable / disable string ('1' or '0') in onGetPreferences(). There a number of test cases to help cover these concerning details. Documentation for overriding the skin version as a URL query parameter is provided in anticipation of T244481. Bug: T242381 Bug: T245793 Depends-On: Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377 Depends-On: Ifc2863fca9cd9efd11ac30c780420e8d89e8cb22 Change-Id: I177dad88fc982170641059b6a4f53fbb38eefad6
2020-01-23 21:53:09 +00:00
],
'VectorSidebarVisible' => [
'type' => 'api',
'default' => true
],
'bar' => [],
[Special:Preferences] [PHP] Add skin version user preference and configs Add a Vector-specific user preference to Special:Preferences for toggling skin version, either Legacy Vector or the latest Vector. The presentation of the new preference section and the default values for anonymous, new, and existing accounts are configurable via $wgVectorShowSkinPreferences, $wgVectorDefaultSkinVersion (to be used by the feature manager in T244481), $wgVectorDefaultSkinVersionForExistingAccounts, and $wgVectorDefaultSkinVersionForNewAccounts. These configurations default to the fullest experience so that third-party configuration is minimal. See skin.json for details. The configurations are each tested in VectorHooksTest.php. When presentation is enabled, the new preference appears as a checkbox; enabled is Legacy mode and disable is latest. There are a number of unfortunate details: - Showing and hiding a checkbox is supported by OOUI. Showing and hiding a whole section (Vector skin preferences, in this case) is not so this additional client JavaScript functionality is added in Core (see Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377). - Stylization as a checkbox is wanted. However, the implied storage type for OOUI checkboxes is a boolean. This is not wanted in the event that another skin version is added (e.g., '3' or 'alpha'). As a workaround, the preference is converted from a boolean to a version string ('1' or '2') on save in Hooks::onPreferencesFormPreSave() and from a version string to a checkbox enable / disable string ('1' or '0') in onGetPreferences(). There a number of test cases to help cover these concerning details. Documentation for overriding the skin version as a URL query parameter is provided in anticipation of T244481. Bug: T242381 Bug: T245793 Depends-On: Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377 Depends-On: Ifc2863fca9cd9efd11ac30c780420e8d89e8cb22 Change-Id: I177dad88fc982170641059b6a4f53fbb38eefad6
2020-01-23 21:53:09 +00:00
],
$prefs,
[Special:Preferences] [PHP] Add skin version user preference and configs Add a Vector-specific user preference to Special:Preferences for toggling skin version, either Legacy Vector or the latest Vector. The presentation of the new preference section and the default values for anonymous, new, and existing accounts are configurable via $wgVectorShowSkinPreferences, $wgVectorDefaultSkinVersion (to be used by the feature manager in T244481), $wgVectorDefaultSkinVersionForExistingAccounts, and $wgVectorDefaultSkinVersionForNewAccounts. These configurations default to the fullest experience so that third-party configuration is minimal. See skin.json for details. The configurations are each tested in VectorHooksTest.php. When presentation is enabled, the new preference appears as a checkbox; enabled is Legacy mode and disable is latest. There are a number of unfortunate details: - Showing and hiding a checkbox is supported by OOUI. Showing and hiding a whole section (Vector skin preferences, in this case) is not so this additional client JavaScript functionality is added in Core (see Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377). - Stylization as a checkbox is wanted. However, the implied storage type for OOUI checkboxes is a boolean. This is not wanted in the event that another skin version is added (e.g., '3' or 'alpha'). As a workaround, the preference is converted from a boolean to a version string ('1' or '2') on save in Hooks::onPreferencesFormPreSave() and from a version string to a checkbox enable / disable string ('1' or '0') in onGetPreferences(). There a number of test cases to help cover these concerning details. Documentation for overriding the skin version as a URL query parameter is provided in anticipation of T244481. Bug: T242381 Bug: T245793 Depends-On: Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377 Depends-On: Ifc2863fca9cd9efd11ac30c780420e8d89e8cb22 Change-Id: I177dad88fc982170641059b6a4f53fbb38eefad6
2020-01-23 21:53:09 +00:00
'Preferences are inserted directly after skin.'
);
}
/**
* @covers ::onGetPreferences
*/
public function testOnGetPreferencesShowPreferencesEnabledSkinSectionMissingLegacy() {
$isLegacy = false;
$this->setFeatureLatestSkinVersionIsEnabled( !$isLegacy );
[Special:Preferences] [PHP] Add skin version user preference and configs Add a Vector-specific user preference to Special:Preferences for toggling skin version, either Legacy Vector or the latest Vector. The presentation of the new preference section and the default values for anonymous, new, and existing accounts are configurable via $wgVectorShowSkinPreferences, $wgVectorDefaultSkinVersion (to be used by the feature manager in T244481), $wgVectorDefaultSkinVersionForExistingAccounts, and $wgVectorDefaultSkinVersionForNewAccounts. These configurations default to the fullest experience so that third-party configuration is minimal. See skin.json for details. The configurations are each tested in VectorHooksTest.php. When presentation is enabled, the new preference appears as a checkbox; enabled is Legacy mode and disable is latest. There are a number of unfortunate details: - Showing and hiding a checkbox is supported by OOUI. Showing and hiding a whole section (Vector skin preferences, in this case) is not so this additional client JavaScript functionality is added in Core (see Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377). - Stylization as a checkbox is wanted. However, the implied storage type for OOUI checkboxes is a boolean. This is not wanted in the event that another skin version is added (e.g., '3' or 'alpha'). As a workaround, the preference is converted from a boolean to a version string ('1' or '2') on save in Hooks::onPreferencesFormPreSave() and from a version string to a checkbox enable / disable string ('1' or '0') in onGetPreferences(). There a number of test cases to help cover these concerning details. Documentation for overriding the skin version as a URL query parameter is provided in anticipation of T244481. Bug: T242381 Bug: T245793 Depends-On: Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377 Depends-On: Ifc2863fca9cd9efd11ac30c780420e8d89e8cb22 Change-Id: I177dad88fc982170641059b6a4f53fbb38eefad6
2020-01-23 21:53:09 +00:00
$prefs = [
'foo' => [],
'bar' => []
];
Hooks::onGetPreferences( $this->getTestUser()->getUser(), $prefs );
$this->assertEquals(
[Special:Preferences] [PHP] Add skin version user preference and configs Add a Vector-specific user preference to Special:Preferences for toggling skin version, either Legacy Vector or the latest Vector. The presentation of the new preference section and the default values for anonymous, new, and existing accounts are configurable via $wgVectorShowSkinPreferences, $wgVectorDefaultSkinVersion (to be used by the feature manager in T244481), $wgVectorDefaultSkinVersionForExistingAccounts, and $wgVectorDefaultSkinVersionForNewAccounts. These configurations default to the fullest experience so that third-party configuration is minimal. See skin.json for details. The configurations are each tested in VectorHooksTest.php. When presentation is enabled, the new preference appears as a checkbox; enabled is Legacy mode and disable is latest. There are a number of unfortunate details: - Showing and hiding a checkbox is supported by OOUI. Showing and hiding a whole section (Vector skin preferences, in this case) is not so this additional client JavaScript functionality is added in Core (see Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377). - Stylization as a checkbox is wanted. However, the implied storage type for OOUI checkboxes is a boolean. This is not wanted in the event that another skin version is added (e.g., '3' or 'alpha'). As a workaround, the preference is converted from a boolean to a version string ('1' or '2') on save in Hooks::onPreferencesFormPreSave() and from a version string to a checkbox enable / disable string ('1' or '0') in onGetPreferences(). There a number of test cases to help cover these concerning details. Documentation for overriding the skin version as a URL query parameter is provided in anticipation of T244481. Bug: T242381 Bug: T245793 Depends-On: Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377 Depends-On: Ifc2863fca9cd9efd11ac30c780420e8d89e8cb22 Change-Id: I177dad88fc982170641059b6a4f53fbb38eefad6
2020-01-23 21:53:09 +00:00
[
'foo' => [],
'bar' => [],
'VectorSkinVersion' => [
'class' => HTMLLegacySkinVersionField::class,
[Special:Preferences] [PHP] Add skin version user preference and configs Add a Vector-specific user preference to Special:Preferences for toggling skin version, either Legacy Vector or the latest Vector. The presentation of the new preference section and the default values for anonymous, new, and existing accounts are configurable via $wgVectorShowSkinPreferences, $wgVectorDefaultSkinVersion (to be used by the feature manager in T244481), $wgVectorDefaultSkinVersionForExistingAccounts, and $wgVectorDefaultSkinVersionForNewAccounts. These configurations default to the fullest experience so that third-party configuration is minimal. See skin.json for details. The configurations are each tested in VectorHooksTest.php. When presentation is enabled, the new preference appears as a checkbox; enabled is Legacy mode and disable is latest. There are a number of unfortunate details: - Showing and hiding a checkbox is supported by OOUI. Showing and hiding a whole section (Vector skin preferences, in this case) is not so this additional client JavaScript functionality is added in Core (see Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377). - Stylization as a checkbox is wanted. However, the implied storage type for OOUI checkboxes is a boolean. This is not wanted in the event that another skin version is added (e.g., '3' or 'alpha'). As a workaround, the preference is converted from a boolean to a version string ('1' or '2') on save in Hooks::onPreferencesFormPreSave() and from a version string to a checkbox enable / disable string ('1' or '0') in onGetPreferences(). There a number of test cases to help cover these concerning details. Documentation for overriding the skin version as a URL query parameter is provided in anticipation of T244481. Bug: T242381 Bug: T245793 Depends-On: Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377 Depends-On: Ifc2863fca9cd9efd11ac30c780420e8d89e8cb22 Change-Id: I177dad88fc982170641059b6a4f53fbb38eefad6
2020-01-23 21:53:09 +00:00
'label-message' => 'prefs-vector-enable-vector-1-label',
'help-message' => 'prefs-vector-enable-vector-1-help',
'section' => self::SKIN_PREFS_SECTION,
'default' => $isLegacy,
'hide-if' => [ '!==', 'wpskin', Constants::SKIN_NAME ]
[Special:Preferences] [PHP] Add skin version user preference and configs Add a Vector-specific user preference to Special:Preferences for toggling skin version, either Legacy Vector or the latest Vector. The presentation of the new preference section and the default values for anonymous, new, and existing accounts are configurable via $wgVectorShowSkinPreferences, $wgVectorDefaultSkinVersion (to be used by the feature manager in T244481), $wgVectorDefaultSkinVersionForExistingAccounts, and $wgVectorDefaultSkinVersionForNewAccounts. These configurations default to the fullest experience so that third-party configuration is minimal. See skin.json for details. The configurations are each tested in VectorHooksTest.php. When presentation is enabled, the new preference appears as a checkbox; enabled is Legacy mode and disable is latest. There are a number of unfortunate details: - Showing and hiding a checkbox is supported by OOUI. Showing and hiding a whole section (Vector skin preferences, in this case) is not so this additional client JavaScript functionality is added in Core (see Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377). - Stylization as a checkbox is wanted. However, the implied storage type for OOUI checkboxes is a boolean. This is not wanted in the event that another skin version is added (e.g., '3' or 'alpha'). As a workaround, the preference is converted from a boolean to a version string ('1' or '2') on save in Hooks::onPreferencesFormPreSave() and from a version string to a checkbox enable / disable string ('1' or '0') in onGetPreferences(). There a number of test cases to help cover these concerning details. Documentation for overriding the skin version as a URL query parameter is provided in anticipation of T244481. Bug: T242381 Bug: T245793 Depends-On: Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377 Depends-On: Ifc2863fca9cd9efd11ac30c780420e8d89e8cb22 Change-Id: I177dad88fc982170641059b6a4f53fbb38eefad6
2020-01-23 21:53:09 +00:00
],
'VectorSidebarVisible' => [
'type' => 'api',
'default' => true
],
[Special:Preferences] [PHP] Add skin version user preference and configs Add a Vector-specific user preference to Special:Preferences for toggling skin version, either Legacy Vector or the latest Vector. The presentation of the new preference section and the default values for anonymous, new, and existing accounts are configurable via $wgVectorShowSkinPreferences, $wgVectorDefaultSkinVersion (to be used by the feature manager in T244481), $wgVectorDefaultSkinVersionForExistingAccounts, and $wgVectorDefaultSkinVersionForNewAccounts. These configurations default to the fullest experience so that third-party configuration is minimal. See skin.json for details. The configurations are each tested in VectorHooksTest.php. When presentation is enabled, the new preference appears as a checkbox; enabled is Legacy mode and disable is latest. There are a number of unfortunate details: - Showing and hiding a checkbox is supported by OOUI. Showing and hiding a whole section (Vector skin preferences, in this case) is not so this additional client JavaScript functionality is added in Core (see Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377). - Stylization as a checkbox is wanted. However, the implied storage type for OOUI checkboxes is a boolean. This is not wanted in the event that another skin version is added (e.g., '3' or 'alpha'). As a workaround, the preference is converted from a boolean to a version string ('1' or '2') on save in Hooks::onPreferencesFormPreSave() and from a version string to a checkbox enable / disable string ('1' or '0') in onGetPreferences(). There a number of test cases to help cover these concerning details. Documentation for overriding the skin version as a URL query parameter is provided in anticipation of T244481. Bug: T242381 Bug: T245793 Depends-On: Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377 Depends-On: Ifc2863fca9cd9efd11ac30c780420e8d89e8cb22 Change-Id: I177dad88fc982170641059b6a4f53fbb38eefad6
2020-01-23 21:53:09 +00:00
],
$prefs,
[Special:Preferences] [PHP] Add skin version user preference and configs Add a Vector-specific user preference to Special:Preferences for toggling skin version, either Legacy Vector or the latest Vector. The presentation of the new preference section and the default values for anonymous, new, and existing accounts are configurable via $wgVectorShowSkinPreferences, $wgVectorDefaultSkinVersion (to be used by the feature manager in T244481), $wgVectorDefaultSkinVersionForExistingAccounts, and $wgVectorDefaultSkinVersionForNewAccounts. These configurations default to the fullest experience so that third-party configuration is minimal. See skin.json for details. The configurations are each tested in VectorHooksTest.php. When presentation is enabled, the new preference appears as a checkbox; enabled is Legacy mode and disable is latest. There are a number of unfortunate details: - Showing and hiding a checkbox is supported by OOUI. Showing and hiding a whole section (Vector skin preferences, in this case) is not so this additional client JavaScript functionality is added in Core (see Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377). - Stylization as a checkbox is wanted. However, the implied storage type for OOUI checkboxes is a boolean. This is not wanted in the event that another skin version is added (e.g., '3' or 'alpha'). As a workaround, the preference is converted from a boolean to a version string ('1' or '2') on save in Hooks::onPreferencesFormPreSave() and from a version string to a checkbox enable / disable string ('1' or '0') in onGetPreferences(). There a number of test cases to help cover these concerning details. Documentation for overriding the skin version as a URL query parameter is provided in anticipation of T244481. Bug: T242381 Bug: T245793 Depends-On: Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377 Depends-On: Ifc2863fca9cd9efd11ac30c780420e8d89e8cb22 Change-Id: I177dad88fc982170641059b6a4f53fbb38eefad6
2020-01-23 21:53:09 +00:00
'Preferences are appended.'
);
}
/**
* @covers ::onPreferencesFormPreSave
*/
public function testOnPreferencesFormPreSaveVectorEnabledLegacyNewPreference() {
$formData = [
'skin' => 'vector',
'VectorSkinVersion' => Constants::SKIN_VERSION_LEGACY,
[Special:Preferences] [PHP] Add skin version user preference and configs Add a Vector-specific user preference to Special:Preferences for toggling skin version, either Legacy Vector or the latest Vector. The presentation of the new preference section and the default values for anonymous, new, and existing accounts are configurable via $wgVectorShowSkinPreferences, $wgVectorDefaultSkinVersion (to be used by the feature manager in T244481), $wgVectorDefaultSkinVersionForExistingAccounts, and $wgVectorDefaultSkinVersionForNewAccounts. These configurations default to the fullest experience so that third-party configuration is minimal. See skin.json for details. The configurations are each tested in VectorHooksTest.php. When presentation is enabled, the new preference appears as a checkbox; enabled is Legacy mode and disable is latest. There are a number of unfortunate details: - Showing and hiding a checkbox is supported by OOUI. Showing and hiding a whole section (Vector skin preferences, in this case) is not so this additional client JavaScript functionality is added in Core (see Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377). - Stylization as a checkbox is wanted. However, the implied storage type for OOUI checkboxes is a boolean. This is not wanted in the event that another skin version is added (e.g., '3' or 'alpha'). As a workaround, the preference is converted from a boolean to a version string ('1' or '2') on save in Hooks::onPreferencesFormPreSave() and from a version string to a checkbox enable / disable string ('1' or '0') in onGetPreferences(). There a number of test cases to help cover these concerning details. Documentation for overriding the skin version as a URL query parameter is provided in anticipation of T244481. Bug: T242381 Bug: T245793 Depends-On: Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377 Depends-On: Ifc2863fca9cd9efd11ac30c780420e8d89e8cb22 Change-Id: I177dad88fc982170641059b6a4f53fbb38eefad6
2020-01-23 21:53:09 +00:00
];
$form = $this->createMock( HTMLForm::class );
$user = $this->createMock( User::class );
[Special:Preferences] [PHP] Add skin version user preference and configs Add a Vector-specific user preference to Special:Preferences for toggling skin version, either Legacy Vector or the latest Vector. The presentation of the new preference section and the default values for anonymous, new, and existing accounts are configurable via $wgVectorShowSkinPreferences, $wgVectorDefaultSkinVersion (to be used by the feature manager in T244481), $wgVectorDefaultSkinVersionForExistingAccounts, and $wgVectorDefaultSkinVersionForNewAccounts. These configurations default to the fullest experience so that third-party configuration is minimal. See skin.json for details. The configurations are each tested in VectorHooksTest.php. When presentation is enabled, the new preference appears as a checkbox; enabled is Legacy mode and disable is latest. There are a number of unfortunate details: - Showing and hiding a checkbox is supported by OOUI. Showing and hiding a whole section (Vector skin preferences, in this case) is not so this additional client JavaScript functionality is added in Core (see Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377). - Stylization as a checkbox is wanted. However, the implied storage type for OOUI checkboxes is a boolean. This is not wanted in the event that another skin version is added (e.g., '3' or 'alpha'). As a workaround, the preference is converted from a boolean to a version string ('1' or '2') on save in Hooks::onPreferencesFormPreSave() and from a version string to a checkbox enable / disable string ('1' or '0') in onGetPreferences(). There a number of test cases to help cover these concerning details. Documentation for overriding the skin version as a URL query parameter is provided in anticipation of T244481. Bug: T242381 Bug: T245793 Depends-On: Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377 Depends-On: Ifc2863fca9cd9efd11ac30c780420e8d89e8cb22 Change-Id: I177dad88fc982170641059b6a4f53fbb38eefad6
2020-01-23 21:53:09 +00:00
$user->expects( $this->never() )
->method( 'setOption' );
$result = true;
$oldPreferences = [];
Hooks::onPreferencesFormPreSave( $formData, $form, $user, $result, $oldPreferences );
}
/**
* @covers ::onPreferencesFormPreSave
*/
public function testOnPreferencesFormPreSaveVectorDisabledNoOldPreference() {
$formData = [
'VectorSkinVersion' => Constants::SKIN_VERSION_LATEST,
[Special:Preferences] [PHP] Add skin version user preference and configs Add a Vector-specific user preference to Special:Preferences for toggling skin version, either Legacy Vector or the latest Vector. The presentation of the new preference section and the default values for anonymous, new, and existing accounts are configurable via $wgVectorShowSkinPreferences, $wgVectorDefaultSkinVersion (to be used by the feature manager in T244481), $wgVectorDefaultSkinVersionForExistingAccounts, and $wgVectorDefaultSkinVersionForNewAccounts. These configurations default to the fullest experience so that third-party configuration is minimal. See skin.json for details. The configurations are each tested in VectorHooksTest.php. When presentation is enabled, the new preference appears as a checkbox; enabled is Legacy mode and disable is latest. There are a number of unfortunate details: - Showing and hiding a checkbox is supported by OOUI. Showing and hiding a whole section (Vector skin preferences, in this case) is not so this additional client JavaScript functionality is added in Core (see Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377). - Stylization as a checkbox is wanted. However, the implied storage type for OOUI checkboxes is a boolean. This is not wanted in the event that another skin version is added (e.g., '3' or 'alpha'). As a workaround, the preference is converted from a boolean to a version string ('1' or '2') on save in Hooks::onPreferencesFormPreSave() and from a version string to a checkbox enable / disable string ('1' or '0') in onGetPreferences(). There a number of test cases to help cover these concerning details. Documentation for overriding the skin version as a URL query parameter is provided in anticipation of T244481. Bug: T242381 Bug: T245793 Depends-On: Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377 Depends-On: Ifc2863fca9cd9efd11ac30c780420e8d89e8cb22 Change-Id: I177dad88fc982170641059b6a4f53fbb38eefad6
2020-01-23 21:53:09 +00:00
];
$form = $this->createMock( HTMLForm::class );
$user = $this->createMock( User::class );
[Special:Preferences] [PHP] Add skin version user preference and configs Add a Vector-specific user preference to Special:Preferences for toggling skin version, either Legacy Vector or the latest Vector. The presentation of the new preference section and the default values for anonymous, new, and existing accounts are configurable via $wgVectorShowSkinPreferences, $wgVectorDefaultSkinVersion (to be used by the feature manager in T244481), $wgVectorDefaultSkinVersionForExistingAccounts, and $wgVectorDefaultSkinVersionForNewAccounts. These configurations default to the fullest experience so that third-party configuration is minimal. See skin.json for details. The configurations are each tested in VectorHooksTest.php. When presentation is enabled, the new preference appears as a checkbox; enabled is Legacy mode and disable is latest. There are a number of unfortunate details: - Showing and hiding a checkbox is supported by OOUI. Showing and hiding a whole section (Vector skin preferences, in this case) is not so this additional client JavaScript functionality is added in Core (see Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377). - Stylization as a checkbox is wanted. However, the implied storage type for OOUI checkboxes is a boolean. This is not wanted in the event that another skin version is added (e.g., '3' or 'alpha'). As a workaround, the preference is converted from a boolean to a version string ('1' or '2') on save in Hooks::onPreferencesFormPreSave() and from a version string to a checkbox enable / disable string ('1' or '0') in onGetPreferences(). There a number of test cases to help cover these concerning details. Documentation for overriding the skin version as a URL query parameter is provided in anticipation of T244481. Bug: T242381 Bug: T245793 Depends-On: Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377 Depends-On: Ifc2863fca9cd9efd11ac30c780420e8d89e8cb22 Change-Id: I177dad88fc982170641059b6a4f53fbb38eefad6
2020-01-23 21:53:09 +00:00
$user->expects( $this->never() )
->method( 'setOption' );
$result = true;
$oldPreferences = [];
Hooks::onPreferencesFormPreSave( $formData, $form, $user, $result, $oldPreferences );
}
/**
* @covers ::onPreferencesFormPreSave
*/
public function testOnPreferencesFormPreSaveVectorDisabledOldPreference() {
$formData = [
'VectorSkinVersion' => Constants::SKIN_VERSION_LATEST,
[Special:Preferences] [PHP] Add skin version user preference and configs Add a Vector-specific user preference to Special:Preferences for toggling skin version, either Legacy Vector or the latest Vector. The presentation of the new preference section and the default values for anonymous, new, and existing accounts are configurable via $wgVectorShowSkinPreferences, $wgVectorDefaultSkinVersion (to be used by the feature manager in T244481), $wgVectorDefaultSkinVersionForExistingAccounts, and $wgVectorDefaultSkinVersionForNewAccounts. These configurations default to the fullest experience so that third-party configuration is minimal. See skin.json for details. The configurations are each tested in VectorHooksTest.php. When presentation is enabled, the new preference appears as a checkbox; enabled is Legacy mode and disable is latest. There are a number of unfortunate details: - Showing and hiding a checkbox is supported by OOUI. Showing and hiding a whole section (Vector skin preferences, in this case) is not so this additional client JavaScript functionality is added in Core (see Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377). - Stylization as a checkbox is wanted. However, the implied storage type for OOUI checkboxes is a boolean. This is not wanted in the event that another skin version is added (e.g., '3' or 'alpha'). As a workaround, the preference is converted from a boolean to a version string ('1' or '2') on save in Hooks::onPreferencesFormPreSave() and from a version string to a checkbox enable / disable string ('1' or '0') in onGetPreferences(). There a number of test cases to help cover these concerning details. Documentation for overriding the skin version as a URL query parameter is provided in anticipation of T244481. Bug: T242381 Bug: T245793 Depends-On: Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377 Depends-On: Ifc2863fca9cd9efd11ac30c780420e8d89e8cb22 Change-Id: I177dad88fc982170641059b6a4f53fbb38eefad6
2020-01-23 21:53:09 +00:00
];
$form = $this->createMock( HTMLForm::class );
$user = $this->createMock( User::class );
[Special:Preferences] [PHP] Add skin version user preference and configs Add a Vector-specific user preference to Special:Preferences for toggling skin version, either Legacy Vector or the latest Vector. The presentation of the new preference section and the default values for anonymous, new, and existing accounts are configurable via $wgVectorShowSkinPreferences, $wgVectorDefaultSkinVersion (to be used by the feature manager in T244481), $wgVectorDefaultSkinVersionForExistingAccounts, and $wgVectorDefaultSkinVersionForNewAccounts. These configurations default to the fullest experience so that third-party configuration is minimal. See skin.json for details. The configurations are each tested in VectorHooksTest.php. When presentation is enabled, the new preference appears as a checkbox; enabled is Legacy mode and disable is latest. There are a number of unfortunate details: - Showing and hiding a checkbox is supported by OOUI. Showing and hiding a whole section (Vector skin preferences, in this case) is not so this additional client JavaScript functionality is added in Core (see Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377). - Stylization as a checkbox is wanted. However, the implied storage type for OOUI checkboxes is a boolean. This is not wanted in the event that another skin version is added (e.g., '3' or 'alpha'). As a workaround, the preference is converted from a boolean to a version string ('1' or '2') on save in Hooks::onPreferencesFormPreSave() and from a version string to a checkbox enable / disable string ('1' or '0') in onGetPreferences(). There a number of test cases to help cover these concerning details. Documentation for overriding the skin version as a URL query parameter is provided in anticipation of T244481. Bug: T242381 Bug: T245793 Depends-On: Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377 Depends-On: Ifc2863fca9cd9efd11ac30c780420e8d89e8cb22 Change-Id: I177dad88fc982170641059b6a4f53fbb38eefad6
2020-01-23 21:53:09 +00:00
$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( [
'VectorDefaultSkinVersionForNewAccounts' => Constants::SKIN_VERSION_LEGACY,
[Special:Preferences] [PHP] Add skin version user preference and configs Add a Vector-specific user preference to Special:Preferences for toggling skin version, either Legacy Vector or the latest Vector. The presentation of the new preference section and the default values for anonymous, new, and existing accounts are configurable via $wgVectorShowSkinPreferences, $wgVectorDefaultSkinVersion (to be used by the feature manager in T244481), $wgVectorDefaultSkinVersionForExistingAccounts, and $wgVectorDefaultSkinVersionForNewAccounts. These configurations default to the fullest experience so that third-party configuration is minimal. See skin.json for details. The configurations are each tested in VectorHooksTest.php. When presentation is enabled, the new preference appears as a checkbox; enabled is Legacy mode and disable is latest. There are a number of unfortunate details: - Showing and hiding a checkbox is supported by OOUI. Showing and hiding a whole section (Vector skin preferences, in this case) is not so this additional client JavaScript functionality is added in Core (see Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377). - Stylization as a checkbox is wanted. However, the implied storage type for OOUI checkboxes is a boolean. This is not wanted in the event that another skin version is added (e.g., '3' or 'alpha'). As a workaround, the preference is converted from a boolean to a version string ('1' or '2') on save in Hooks::onPreferencesFormPreSave() and from a version string to a checkbox enable / disable string ('1' or '0') in onGetPreferences(). There a number of test cases to help cover these concerning details. Documentation for overriding the skin version as a URL query parameter is provided in anticipation of T244481. Bug: T242381 Bug: T245793 Depends-On: Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377 Depends-On: Ifc2863fca9cd9efd11ac30c780420e8d89e8cb22 Change-Id: I177dad88fc982170641059b6a4f53fbb38eefad6
2020-01-23 21:53:09 +00:00
] );
$this->setService( 'Vector.Config', $config );
$user = $this->createMock( User::class );
[Special:Preferences] [PHP] Add skin version user preference and configs Add a Vector-specific user preference to Special:Preferences for toggling skin version, either Legacy Vector or the latest Vector. The presentation of the new preference section and the default values for anonymous, new, and existing accounts are configurable via $wgVectorShowSkinPreferences, $wgVectorDefaultSkinVersion (to be used by the feature manager in T244481), $wgVectorDefaultSkinVersionForExistingAccounts, and $wgVectorDefaultSkinVersionForNewAccounts. These configurations default to the fullest experience so that third-party configuration is minimal. See skin.json for details. The configurations are each tested in VectorHooksTest.php. When presentation is enabled, the new preference appears as a checkbox; enabled is Legacy mode and disable is latest. There are a number of unfortunate details: - Showing and hiding a checkbox is supported by OOUI. Showing and hiding a whole section (Vector skin preferences, in this case) is not so this additional client JavaScript functionality is added in Core (see Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377). - Stylization as a checkbox is wanted. However, the implied storage type for OOUI checkboxes is a boolean. This is not wanted in the event that another skin version is added (e.g., '3' or 'alpha'). As a workaround, the preference is converted from a boolean to a version string ('1' or '2') on save in Hooks::onPreferencesFormPreSave() and from a version string to a checkbox enable / disable string ('1' or '0') in onGetPreferences(). There a number of test cases to help cover these concerning details. Documentation for overriding the skin version as a URL query parameter is provided in anticipation of T244481. Bug: T242381 Bug: T245793 Depends-On: Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377 Depends-On: Ifc2863fca9cd9efd11ac30c780420e8d89e8cb22 Change-Id: I177dad88fc982170641059b6a4f53fbb38eefad6
2020-01-23 21:53:09 +00:00
$user->expects( $this->once() )
->method( 'setOption' )
->with( 'VectorSkinVersion', Constants::SKIN_VERSION_LEGACY );
[Special:Preferences] [PHP] Add skin version user preference and configs Add a Vector-specific user preference to Special:Preferences for toggling skin version, either Legacy Vector or the latest Vector. The presentation of the new preference section and the default values for anonymous, new, and existing accounts are configurable via $wgVectorShowSkinPreferences, $wgVectorDefaultSkinVersion (to be used by the feature manager in T244481), $wgVectorDefaultSkinVersionForExistingAccounts, and $wgVectorDefaultSkinVersionForNewAccounts. These configurations default to the fullest experience so that third-party configuration is minimal. See skin.json for details. The configurations are each tested in VectorHooksTest.php. When presentation is enabled, the new preference appears as a checkbox; enabled is Legacy mode and disable is latest. There are a number of unfortunate details: - Showing and hiding a checkbox is supported by OOUI. Showing and hiding a whole section (Vector skin preferences, in this case) is not so this additional client JavaScript functionality is added in Core (see Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377). - Stylization as a checkbox is wanted. However, the implied storage type for OOUI checkboxes is a boolean. This is not wanted in the event that another skin version is added (e.g., '3' or 'alpha'). As a workaround, the preference is converted from a boolean to a version string ('1' or '2') on save in Hooks::onPreferencesFormPreSave() and from a version string to a checkbox enable / disable string ('1' or '0') in onGetPreferences(). There a number of test cases to help cover these concerning details. Documentation for overriding the skin version as a URL query parameter is provided in anticipation of T244481. Bug: T242381 Bug: T245793 Depends-On: Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377 Depends-On: Ifc2863fca9cd9efd11ac30c780420e8d89e8cb22 Change-Id: I177dad88fc982170641059b6a4f53fbb38eefad6
2020-01-23 21:53:09 +00:00
$isAutoCreated = false;
Hooks::onLocalUserCreated( $user, $isAutoCreated );
}
/**
* @covers ::onLocalUserCreated
*/
public function testOnLocalUserCreatedLatest() {
$config = new HashConfig( [
'VectorDefaultSkinVersionForNewAccounts' => Constants::SKIN_VERSION_LATEST,
[Special:Preferences] [PHP] Add skin version user preference and configs Add a Vector-specific user preference to Special:Preferences for toggling skin version, either Legacy Vector or the latest Vector. The presentation of the new preference section and the default values for anonymous, new, and existing accounts are configurable via $wgVectorShowSkinPreferences, $wgVectorDefaultSkinVersion (to be used by the feature manager in T244481), $wgVectorDefaultSkinVersionForExistingAccounts, and $wgVectorDefaultSkinVersionForNewAccounts. These configurations default to the fullest experience so that third-party configuration is minimal. See skin.json for details. The configurations are each tested in VectorHooksTest.php. When presentation is enabled, the new preference appears as a checkbox; enabled is Legacy mode and disable is latest. There are a number of unfortunate details: - Showing and hiding a checkbox is supported by OOUI. Showing and hiding a whole section (Vector skin preferences, in this case) is not so this additional client JavaScript functionality is added in Core (see Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377). - Stylization as a checkbox is wanted. However, the implied storage type for OOUI checkboxes is a boolean. This is not wanted in the event that another skin version is added (e.g., '3' or 'alpha'). As a workaround, the preference is converted from a boolean to a version string ('1' or '2') on save in Hooks::onPreferencesFormPreSave() and from a version string to a checkbox enable / disable string ('1' or '0') in onGetPreferences(). There a number of test cases to help cover these concerning details. Documentation for overriding the skin version as a URL query parameter is provided in anticipation of T244481. Bug: T242381 Bug: T245793 Depends-On: Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377 Depends-On: Ifc2863fca9cd9efd11ac30c780420e8d89e8cb22 Change-Id: I177dad88fc982170641059b6a4f53fbb38eefad6
2020-01-23 21:53:09 +00:00
] );
$this->setService( 'Vector.Config', $config );
$user = $this->createMock( User::class );
[Special:Preferences] [PHP] Add skin version user preference and configs Add a Vector-specific user preference to Special:Preferences for toggling skin version, either Legacy Vector or the latest Vector. The presentation of the new preference section and the default values for anonymous, new, and existing accounts are configurable via $wgVectorShowSkinPreferences, $wgVectorDefaultSkinVersion (to be used by the feature manager in T244481), $wgVectorDefaultSkinVersionForExistingAccounts, and $wgVectorDefaultSkinVersionForNewAccounts. These configurations default to the fullest experience so that third-party configuration is minimal. See skin.json for details. The configurations are each tested in VectorHooksTest.php. When presentation is enabled, the new preference appears as a checkbox; enabled is Legacy mode and disable is latest. There are a number of unfortunate details: - Showing and hiding a checkbox is supported by OOUI. Showing and hiding a whole section (Vector skin preferences, in this case) is not so this additional client JavaScript functionality is added in Core (see Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377). - Stylization as a checkbox is wanted. However, the implied storage type for OOUI checkboxes is a boolean. This is not wanted in the event that another skin version is added (e.g., '3' or 'alpha'). As a workaround, the preference is converted from a boolean to a version string ('1' or '2') on save in Hooks::onPreferencesFormPreSave() and from a version string to a checkbox enable / disable string ('1' or '0') in onGetPreferences(). There a number of test cases to help cover these concerning details. Documentation for overriding the skin version as a URL query parameter is provided in anticipation of T244481. Bug: T242381 Bug: T245793 Depends-On: Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377 Depends-On: Ifc2863fca9cd9efd11ac30c780420e8d89e8cb22 Change-Id: I177dad88fc982170641059b6a4f53fbb38eefad6
2020-01-23 21:53:09 +00:00
$user->expects( $this->once() )
->method( 'setOption' )
->with( 'VectorSkinVersion', Constants::SKIN_VERSION_LATEST );
[Special:Preferences] [PHP] Add skin version user preference and configs Add a Vector-specific user preference to Special:Preferences for toggling skin version, either Legacy Vector or the latest Vector. The presentation of the new preference section and the default values for anonymous, new, and existing accounts are configurable via $wgVectorShowSkinPreferences, $wgVectorDefaultSkinVersion (to be used by the feature manager in T244481), $wgVectorDefaultSkinVersionForExistingAccounts, and $wgVectorDefaultSkinVersionForNewAccounts. These configurations default to the fullest experience so that third-party configuration is minimal. See skin.json for details. The configurations are each tested in VectorHooksTest.php. When presentation is enabled, the new preference appears as a checkbox; enabled is Legacy mode and disable is latest. There are a number of unfortunate details: - Showing and hiding a checkbox is supported by OOUI. Showing and hiding a whole section (Vector skin preferences, in this case) is not so this additional client JavaScript functionality is added in Core (see Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377). - Stylization as a checkbox is wanted. However, the implied storage type for OOUI checkboxes is a boolean. This is not wanted in the event that another skin version is added (e.g., '3' or 'alpha'). As a workaround, the preference is converted from a boolean to a version string ('1' or '2') on save in Hooks::onPreferencesFormPreSave() and from a version string to a checkbox enable / disable string ('1' or '0') in onGetPreferences(). There a number of test cases to help cover these concerning details. Documentation for overriding the skin version as a URL query parameter is provided in anticipation of T244481. Bug: T242381 Bug: T245793 Depends-On: Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377 Depends-On: Ifc2863fca9cd9efd11ac30c780420e8d89e8cb22 Change-Id: I177dad88fc982170641059b6a4f53fbb38eefad6
2020-01-23 21:53:09 +00:00
$isAutoCreated = false;
Hooks::onLocalUserCreated( $user, $isAutoCreated );
}
/**
* @covers ::onSkinTemplateNavigation
*/
public function testOnSkinTemplateNavigation() {
$this->setMwGlobals( [
'wgVectorUseIconWatch' => true
] );
$skin = new SkinVector( [ 'name' => 'vector' ] );
$skin->getContext()->setTitle( Title::newFromText( 'Foo' ) );
$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'
);
}
[Special:Preferences] [PHP] Add skin version user preference and configs Add a Vector-specific user preference to Special:Preferences for toggling skin version, either Legacy Vector or the latest Vector. The presentation of the new preference section and the default values for anonymous, new, and existing accounts are configurable via $wgVectorShowSkinPreferences, $wgVectorDefaultSkinVersion (to be used by the feature manager in T244481), $wgVectorDefaultSkinVersionForExistingAccounts, and $wgVectorDefaultSkinVersionForNewAccounts. These configurations default to the fullest experience so that third-party configuration is minimal. See skin.json for details. The configurations are each tested in VectorHooksTest.php. When presentation is enabled, the new preference appears as a checkbox; enabled is Legacy mode and disable is latest. There are a number of unfortunate details: - Showing and hiding a checkbox is supported by OOUI. Showing and hiding a whole section (Vector skin preferences, in this case) is not so this additional client JavaScript functionality is added in Core (see Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377). - Stylization as a checkbox is wanted. However, the implied storage type for OOUI checkboxes is a boolean. This is not wanted in the event that another skin version is added (e.g., '3' or 'alpha'). As a workaround, the preference is converted from a boolean to a version string ('1' or '2') on save in Hooks::onPreferencesFormPreSave() and from a version string to a checkbox enable / disable string ('1' or '0') in onGetPreferences(). There a number of test cases to help cover these concerning details. Documentation for overriding the skin version as a URL query parameter is provided in anticipation of T244481. Bug: T242381 Bug: T245793 Depends-On: Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377 Depends-On: Ifc2863fca9cd9efd11ac30c780420e8d89e8cb22 Change-Id: I177dad88fc982170641059b6a4f53fbb38eefad6
2020-01-23 21:53:09 +00:00
}