From fec6bf15f518d41fc6494f20fc8c0b6352150f37 Mon Sep 17 00:00:00 2001 From: bwang Date: Thu, 17 Mar 2022 11:25:02 -0500 Subject: [PATCH] Update Hooks tests to cover updateUserLinksItems Change-Id: Ia719f34f060e02acb81c7d48ba5885283df0045f --- tests/phpunit/integration/VectorHooksTest.php | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tests/phpunit/integration/VectorHooksTest.php b/tests/phpunit/integration/VectorHooksTest.php index 6ea52a441..dd4a8d72f 100644 --- a/tests/phpunit/integration/VectorHooksTest.php +++ b/tests/phpunit/integration/VectorHooksTest.php @@ -21,6 +21,7 @@ use Vector\Hooks; use Vector\HTMLForm\Fields\HTMLLegacySkinVersionField; use Vector\SkinVector; use Vector\SkinVector22; +use Vector\SkinVectorLegacy; /** * Integration tests for Vector Hooks. @@ -571,6 +572,54 @@ class VectorHooksTest extends MediaWikiIntegrationTestCase { ); } + /** + * @covers ::updateUserLinksItems + */ + public function testUpdateUserLinksItems() { + $vector2022Skin = new SkinVector22( [ 'name' => 'vector-2022' ] ); + $contentNav = [ + 'user-page' => [ + 'userpage' => [ 'class' => [], 'icon' => 'userpage' ], + ], + 'user-menu' => [ + 'login' => [ 'class' => [], 'icon' => 'login' ], + ] + ]; + $contentNavWatchlist = [ + 'user-menu' => [ + 'watchlist' => [ 'class' => [], 'icon' => 'watchlist' ], + ] + ]; + $vectorLegacySkin = new SkinVectorLegacy( [ 'name' => 'vector' ] ); + $contentNavLegacy = [ + 'user-page' => [ + 'userpage' => [ 'class' => [], 'icon' => 'userpage' ], + ] + ]; + + Hooks::onSkinTemplateNavigation( $vector2022Skin, $contentNav ); + $this->assertFalse( isset( $contentNav['vector-user-menu-overflow'] ), + 'watchlist data is not copied to vector-user-menu-overflow when not provided' + ); + $this->assertFalse( isset( $contentNav['user-page']['login'] ), + 'updateUserLinksDropdownItems is called when user-page is defined' + ); + $this->assertContains( 'mw-ui-button', + $contentNav['user-page']['userpage']['link-class'], + 'updateUserLinksOverflowItems is called when not legacy' + ); + + Hooks::onSkinTemplateNavigation( $vector2022Skin, $contentNavWatchlist ); + $this->assertTrue( isset( $contentNavWatchlist['vector-user-menu-overflow'] ), + 'watchlist data is copied to vector-user-menu-overflow when provided' + ); + + Hooks::onSkinTemplateNavigation( $vectorLegacySkin, $contentNavLegacy ); + $this->assertFalse( isset( $contentNavLegacy['user-page'] ), + 'user-page is unset for legacy vector' + ); + } + /** * @covers ::updateUserLinksDropdownItems */