| 1 | <?php |
| 2 | /** |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License as published by |
| 5 | * the Free Software Foundation; either version 2 of the License, or |
| 6 | * (at your option) any later version. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License along |
| 14 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 16 | * http://www.gnu.org/copyleft/gpl.html |
| 17 | * |
| 18 | * @file |
| 19 | * @since 1.42 |
| 20 | */ |
| 21 | |
| 22 | namespace MediaWiki\Skins\Vector\Tests\Unit\Components; |
| 23 | |
| 24 | use MediaWiki\Skins\Vector\Components\VectorComponent; |
| 25 | use MediaWiki\Skins\Vector\Components\VectorComponentMainMenuAction; |
| 26 | use MediaWikiUnitTestCase; |
| 27 | use Skin; |
| 28 | |
| 29 | /** |
| 30 | * @group Vector |
| 31 | * @group Components |
| 32 | * @coversDefaultClass \MediaWiki\Skins\Vector\Components\VectorComponentMainMenuAction |
| 33 | */ |
| 34 | class VectorComponentMainMenuActionTest extends MediaWikiUnitTestCase { |
| 35 | |
| 36 | /** |
| 37 | * This test checks if the VectorComponentMainMenuAction class can be instantiated |
| 38 | * @covers ::__construct |
| 39 | */ |
| 40 | public function testConstruct() { |
| 41 | // Mock the Skin, htmlData, headingOptions, and classes |
| 42 | $skinMock = $this->createMock( Skin::class ); |
| 43 | $htmlData = []; |
| 44 | $headingOptions = []; |
| 45 | $classes = ''; |
| 46 | |
| 47 | // Create a new VectorComponentMainMenuAction object |
| 48 | $mainMenuAction = new VectorComponentMainMenuAction( |
| 49 | 'actionName', |
| 50 | $skinMock, |
| 51 | $htmlData, |
| 52 | $headingOptions, |
| 53 | $classes |
| 54 | ); |
| 55 | |
| 56 | // Check if the object is an instance of VectorComponent |
| 57 | $this->assertInstanceOf( VectorComponent::class, $mainMenuAction ); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * This test checks if the makeMainMenuActionData method returns the correct data |
| 62 | * @covers ::getTemplateData |
| 63 | */ |
| 64 | public function testMakeMainMenuActionData() { |
| 65 | // Mock the Skin |
| 66 | $skinMock = $this->createMock( Skin::class ); |
| 67 | |
| 68 | // Create a new VectorComponentMainMenuAction object |
| 69 | $mainMenuAction = new VectorComponentMainMenuAction( |
| 70 | 'action-example', |
| 71 | $skinMock, |
| 72 | [ 'html-content' => '<a href="/example">Some Link</a>' ], |
| 73 | [ 'heading' => 'Some Heading' ], |
| 74 | 'some-class' |
| 75 | ); |
| 76 | |
| 77 | // Call the getTemplateData method |
| 78 | $templateData = $mainMenuAction->getTemplateData(); |
| 79 | |
| 80 | // Verifying that the template data is constructed as expected |
| 81 | $this->assertEquals( 'Some Heading', $templateData['heading'] ); |
| 82 | $this->assertStringContainsString( 'Some Link', $templateData['html-content'] ); |
| 83 | $this->assertEquals( 'some-class', $templateData['class'] ); |
| 84 | } |
| 85 | } |