From 4b1a4726a0723f320cbdd43ccfa5f270456a77bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Do=C4=9Fu=20Abaris?= Date: Wed, 7 Feb 2024 11:16:53 +0100 Subject: [PATCH] Add PHPUnit tests for VectorComponentClientPrefs Adds tests for VectorComponentClientPrefs in Vector skin. The test suite includes the following validations: - Both pinned and unpinned states - Correct structuring of 'data-pinnable-header' Change-Id: I745559b2f738b4bed0f152fc8de3af1653b96ecd --- .../VectorComponentClientPrefsTest.php | 137 ++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 tests/phpunit/unit/components/VectorComponentClientPrefsTest.php diff --git a/tests/phpunit/unit/components/VectorComponentClientPrefsTest.php b/tests/phpunit/unit/components/VectorComponentClientPrefsTest.php new file mode 100644 index 000000000..e4a3d0d4a --- /dev/null +++ b/tests/phpunit/unit/components/VectorComponentClientPrefsTest.php @@ -0,0 +1,137 @@ +createMock( MessageLocalizer::class ); + $featureManager = $this->createMock( FeatureManager::class ); + // The isFeatureEnabled method is called and returns true + $featureManager->method( 'isFeatureEnabled' ) + ->willReturn( true ); + + // Create a new VectorComponentClientPrefs object + $clientPrefs = new VectorComponentClientPrefs( $localizer, $featureManager ); + // Call the getTemplateData method + $actualData = $clientPrefs->getTemplateData(); + + // The expected data + $expectedData = [ + // The id is set to 'vector-client-prefs' + 'id' => 'vector-client-prefs', + // The is-pinned value is true + 'is-pinned' => true, + // The data-pinnable-header array + 'data-pinnable-header' => [ + // The is-pinned value is true + 'is-pinned' => true, + // The label is null + 'label' => null, + // The label-tag-name is set to 'div' + 'label-tag-name' => 'div', + // The pin-label is null + 'pin-label' => null, + // The unpin-label is null + 'unpin-label' => null, + // The data-pinnable-element-id is set to 'vector-client-prefs' + 'data-pinnable-element-id' => 'vector-client-prefs', + // The data-feature-name is set to 'client-prefs-pinned' + 'data-feature-name' => 'client-prefs-pinned', + // The data-unpinned-container-id is set to 'vector-client-prefs-unpinned-container' + 'data-unpinned-container-id' => 'vector-client-prefs-unpinned-container', + // The data-pinned-container-id is set to 'vector-client-prefs-pinned-container' + 'data-pinned-container-id' => 'vector-client-prefs-pinned-container', + ] + ]; + + // Assert that the actual data matches the expected data + $this->assertEquals( $expectedData, $actualData ); + // Assert that the is-pinned value is true + $this->assertSame( true, $actualData['is-pinned'], 'Assertion for the pinned state failed.' ); + } + + /** + * @covers ::getTemplateData + */ + public function testGetTemplateDataUnpinned() { + // Mock the MessageLocalizer and FeatureManager + $localizer = $this->createMock( MessageLocalizer::class ); + $featureManager = $this->createMock( FeatureManager::class ); + // The isFeatureEnabled method is called and returns false + $featureManager->method( 'isFeatureEnabled' ) + ->willReturn( false ); + + // Create a new VectorComponentClientPrefs object + $clientPrefs = new VectorComponentClientPrefs( $localizer, $featureManager ); + // Call the getTemplateData method + $actualData = $clientPrefs->getTemplateData(); + + // The expected data + $expectedData = [ + // The id is set to 'vector-client-prefs' + 'id' => 'vector-client-prefs', + // The is-pinned value is false + 'is-pinned' => false, + // The data-pinnable-header array + 'data-pinnable-header' => [ + // The is-pinned value is false + 'is-pinned' => false, + // The label is null + 'label' => null, + // The label-tag-name is set to 'div' + 'label-tag-name' => 'div', + // The pin-label is null + 'pin-label' => null, + // The unpin-label is null + 'unpin-label' => null, + // The data-pinnable-element-id is set to 'vector-client-prefs' + 'data-pinnable-element-id' => 'vector-client-prefs', + // The data-feature-name is set to 'client-prefs-pinned' + 'data-feature-name' => 'client-prefs-pinned', + // The data-unpinned-container-id is set to 'vector-client-prefs-unpinned-container' + 'data-unpinned-container-id' => 'vector-client-prefs-unpinned-container', + // The data-pinned-container-id is set to 'vector-client-prefs-pinned-container' + 'data-pinned-container-id' => 'vector-client-prefs-pinned-container', + ] + ]; + + // Assert that the actual data matches the expected data + $this->assertEquals( $expectedData, $actualData ); + // Assert that the is-pinned value is false + $this->assertSame( false, $actualData['is-pinned'], 'Assertion for the pinned state failed.' ); + } +}