From 2f5b6f7c02b00f725c1983bc4851095884db750a Mon Sep 17 00:00:00 2001 From: Fomafix Date: Sat, 2 Mar 2024 19:34:53 +0000 Subject: [PATCH] LanguagesHelperTest: Use @dataProvider to configure test cases The two test cases can combined. Change-Id: I7bff4993e87d8c7a95eb55d4e4596f9330105391 --- tests/phpunit/LanguagesHelperTest.php | 46 +++++++++------------------ 1 file changed, 15 insertions(+), 31 deletions(-) diff --git a/tests/phpunit/LanguagesHelperTest.php b/tests/phpunit/LanguagesHelperTest.php index 11a11ad50..093437625 100644 --- a/tests/phpunit/LanguagesHelperTest.php +++ b/tests/phpunit/LanguagesHelperTest.php @@ -58,44 +58,28 @@ class LanguagesHelperTest extends MediaWikiIntegrationTestCase { } /** + * @dataProvider provideDoesTitleHasLanguagesOrVariants + * @param bool $hasVariants + * @param array $langLinks + * @param bool $expected * @covers ::__construct * @covers ::doesTitleHasLanguagesOrVariants */ - public function testReturnsWhenOutputPageHasLangLinks() { + public function testDoesTitleHasLanguagesOrVariants( bool $hasVariants, array $langLinks, bool $expected ) { $helper = new LanguagesHelper( - $this->getLanguageConverterFactory( false ), - $this->getOutput( [ 'pl:StronaTestowa', 'en:TestPage' ] ) + $this->getLanguageConverterFactory( $hasVariants ), + $this->getOutput( $langLinks ) ); - $this->assertTrue( $helper->doesTitleHasLanguagesOrVariants( $this->getTitle() ) ); - - $helper = new LanguagesHelper( - $this->getLanguageConverterFactory( true ), - $this->getOutput( [ 'pl:StronaTestowa', 'en:TestPage' ] ) - ); - - $this->assertTrue( $helper->doesTitleHasLanguagesOrVariants( $this->getTitle() ) ); + $this->assertSame( $expected, $helper->doesTitleHasLanguagesOrVariants( $this->getTitle() ) ); } - /** - * @covers ::__construct - * @covers ::doesTitleHasLanguagesOrVariants - */ - public function testReturnsWhenOutputDoesNotHaveLangLinks() { - $helper = new LanguagesHelper( - $this->getLanguageConverterFactory( false ), - $this->getOutput( [] ) - ); - - $this->assertFalse( $helper->doesTitleHasLanguagesOrVariants( - $this->getTitle() ) ); - - $helper = new LanguagesHelper( - $this->getLanguageConverterFactory( true ), - $this->getOutput( [] ) - ); - - $this->assertTrue( $helper->doesTitleHasLanguagesOrVariants( - $this->getTitle() ) ); + public static function provideDoesTitleHasLanguagesOrVariants() { + return [ + [ false, [ 'pl:StronaTestowa', 'en:TestPage' ], true ], + [ true, [ 'pl:StronaTestowa', 'en:TestPage' ], true ], + [ false, [], false ], + [ true, [], true ], + ]; } }