X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=tests%2Fphpunit%2Flanguages%2Fclasses%2FLanguageSrTest.php;h=8da760237a92388b1f86b5642dbf2fa7cd3dd6e9;hp=30b4df891de90227e4f89eb7d56deed7321f2e11;hb=9f2ffdfbd4c289446f2baf8a168cbe89fa122157;hpb=55aab97bb4b507911e24995ae870b78f86c17557 diff --git a/tests/phpunit/languages/classes/LanguageSrTest.php b/tests/phpunit/languages/classes/LanguageSrTest.php index 30b4df891d..8da760237a 100644 --- a/tests/phpunit/languages/classes/LanguageSrTest.php +++ b/tests/phpunit/languages/classes/LanguageSrTest.php @@ -21,6 +21,63 @@ * @covers SrConverter */ class LanguageSrTest extends LanguageClassesTestCase { + /** + * @covers Language::hasVariants + */ + public function testHasVariants() { + $this->assertTrue( $this->getLang()->hasVariants(), 'sr has variants' ); + } + + /** + * @covers Language::hasVariant + */ + public function testHasVariant() { + $langs = [ + 'sr' => $this->getLang(), + 'sr-ec' => Language::factory( 'sr-ec' ), + 'sr-cyrl' => Language::factory( 'sr-cyrl' ), + ]; + foreach ( $langs as $code => $l ) { + $p = $l->getParentLanguage(); + $this->assertTrue( $p !== null, 'parent language exists' ); + $this->assertEquals( 'sr', $p->getCode(), 'sr is parent language' ); + $this->assertTrue( $p instanceof LanguageSr, 'parent is LanguageSr' ); + // This is a valid variant of the base + $this->assertTrue( $p->hasVariant( $l->getCode() ) ); + // This test should be tweaked if/when sr-ec is renamed (T117845) + // to swap the roles of sr-ec and sr-Cyrl + $this->assertTrue( $l->hasVariant( 'sr-ec' ), 'sr-ec exists' ); + // note that sr-cyrl is an alias, not a (strict) variant name + foreach ( [ 'sr-EC', 'sr-Cyrl', 'sr-cyrl', 'sr-bogus' ] as $v ) { + $this->assertFalse( $l->hasVariant( $v ), "$v is not a variant of $code" ); + } + } + } + + /** + * @covers Language::hasVariant + */ + public function testHasVariantBogus() { + $langs = [ + // Note that case matters when calling Language::factory(); + // these are all bogus language codes + 'sr-EC' => Language::factory( 'sr-EC' ), + 'sr-Cyrl' => Language::factory( 'sr-Cyrl' ), + 'sr-bogus' => Language::factory( 'sr-bogus' ), + ]; + foreach ( $langs as $code => $l ) { + $p = $l->getParentLanguage(); + $this->assertTrue( $p === null, 'no parent for bogus language' ); + $this->assertFalse( $l instanceof LanguageSr, "$code is not sr" ); + $this->assertFalse( $this->getLang()->hasVariant( $code ), "$code is not a sr variant" ); + foreach ( [ 'sr', 'sr-ec', 'sr-EC', 'sr-Cyrl', 'sr-cyrl', 'sr-bogus' ] as $v ) { + if ( $v !== $code ) { + $this->assertFalse( $l->hasVariant( $v ), "no variant $v" ); + } + } + } + } + /** * @covers LanguageConverter::convertTo */ @@ -41,11 +98,11 @@ class LanguageSrTest extends LanguageClassesTestCase { public function testMixedConversions() { $this->assertCyrillic( 'шђчћжШЂЧЋЖ - šđčćž', - 'Mostly cyrillic characters' + 'Mostly Cyrillic characters' ); $this->assertLatin( 'šđč枊ĐČĆŽ - шђчћж', - 'Mostly latin characters' + 'Mostly Latin characters' ); } @@ -54,11 +111,11 @@ class LanguageSrTest extends LanguageClassesTestCase { */ public function testSameAmountOfLatinAndCyrillicGetConverted() { $this->assertConverted( - '4 latin: šđčć | 4 cyrillic: шђчћ', + '4 Latin: šđčć | 4 Cyrillic: шђчћ', 'sr-ec' ); $this->assertConverted( - '4 latin: šđčć | 4 cyrillic: шђчћ', + '4 Latin: šđčć | 4 Cyrillic: шђчћ', 'sr-el' ); } @@ -181,6 +238,7 @@ class LanguageSrTest extends LanguageClassesTestCase { } # #### HELPERS ##################################################### + /** *Wrapper to verify text stay the same after applying conversion * @param string $text Text to convert @@ -211,7 +269,7 @@ class LanguageSrTest extends LanguageClassesTestCase { /** * Verifiy the given Cyrillic text is not converted when using - * using the cyrillic variant and converted to Latin when using + * using the Cyrillic variant and converted to Latin when using * the Latin variant. * @param string $text Text to convert * @param string $msg Optional message