Ensure watchlist in user menu dropdown has the collapsible class

Bug: T302084
Change-Id: I27d7c0e46ee809185133fd787fc0c6fa5fcdac2e
This commit is contained in:
bwang 2022-03-04 09:45:45 -06:00 committed by Jdlrobson
parent 832c1bc3bd
commit a1afa7ccb3
2 changed files with 58 additions and 3 deletions

View file

@ -214,6 +214,8 @@ class Hooks {
*
* @param SkinTemplate $sk
* @param array &$content_navigation
* @suppress PhanTypeArraySuspiciousNullable False positives
* @suppress PhanTypePossiblyInvalidDimOffset False positives
*/
private static function updateUserLinksDropdownItems( $sk, &$content_navigation ) {
// For logged-in users in modern Vector, rearrange some links in the personal toolbar.
@ -224,10 +226,9 @@ class Hooks {
);
// watchlist may be disabled if $wgGroupPermissions['*']['viewmywatchlist'] = false;
// See [[phab:T299671]]
$wlItem = $content_navigation['user-menu']['watchlist'] ?? false;
if ( $wlItem ) {
if ( isset( $content_navigation['user-menu']['watchlist'] ) ) {
self::makeMenuItemCollapsible(
$wlItem
$content_navigation['user-menu']['watchlist']
);
}
// Remove logout link from user-menu and recreate it in SkinVector,
@ -260,6 +261,7 @@ class Hooks {
*
* @param SkinTemplate $sk
* @param array &$content_navigation
* @suppress PhanTypeArraySuspiciousNullable False positives
*/
private static function updateUserLinksItems( $sk, &$content_navigation ) {
$hasUserMenu = $content_navigation['user-menu'] ?? false;

View file

@ -10,6 +10,7 @@ use HashConfig;
use HTMLForm;
use MediaWiki\User\UserOptionsManager;
use MediaWikiIntegrationTestCase;
use ReflectionMethod;
use ResourceLoaderContext;
use RuntimeException;
use Title;
@ -568,4 +569,56 @@ class VectorHooksTest extends MediaWikiIntegrationTestCase {
'List item other than watch or unwatch should not have an "icon" class'
);
}
/**
* @covers ::updateUserLinksDropdownItems
*/
public function testUpdateUserLinksDropdownItems() {
$updateUserLinksDropdownItems = new ReflectionMethod(
Hooks::class,
'updateUserLinksDropdownItems'
);
$updateUserLinksDropdownItems->setAccessible( true );
$skin = new SkinVector( [ 'name' => 'vector' ] );
// Anon user
$skin->getUser()->setId( '1' );
$contentAnon = [
'user-menu' => [
'anonuserpage' => [ 'class' => [], 'icon' => 'anonuserpage' ],
'createaccount' => [ 'class' => [], 'icon' => 'createaccount' ],
'login' => [ 'class' => [], 'icon' => 'login' ],
'login-private' => [ 'class' => [], 'icon' => 'login-private' ],
],
];
$updateUserLinksDropdownItems->invokeArgs( null, [ $skin, &$contentAnon ] );
$this->assertTrue(
count( $contentAnon['user-menu'] ) === 0,
'Anon user page, create account, login, and login private links are removed from anon user links dropdown'
);
// Registered user
$skin->getUser()->setId( '1' );
$contentRegistered = [
'user-menu' => [
'userpage' => [ 'class' => [], 'icon' => 'userpage' ],
'watchlist' => [ 'class' => [], 'icon' => 'watchlist' ],
'logout' => [ 'class' => [], 'icon' => 'logout' ],
],
];
$updateUserLinksDropdownItems->invokeArgs( null, [ $skin, &$contentRegistered ] );
$this->assertContains( 'user-links-collapsible-item', $contentRegistered['user-menu']['userpage']['class'],
'User page link in user links dropdown requires collapsible class'
);
$this->assertContains( 'mw-ui-icon-before', $contentRegistered['user-menu']['userpage']['link-class'],
'User page link in user links dropdown requires icon classes'
);
$this->assertContains( 'user-links-collapsible-item', $contentRegistered['user-menu']['watchlist']['class'],
'Watchlist link in user links dropdown requires collapsible class'
);
$this->assertContains( 'mw-ui-icon-before', $contentRegistered['user-menu']['watchlist']['link-class'],
'Watchlist link in user links dropdown requires icon classes'
);
$this->assertFalse( isset( $contentRegistered['user-menu']['logout'] ),
'Logout link in user links dropdown is not set'
);
}
}