diff options
Diffstat (limited to 'MLEB/Translate/tests/phpunit/MessageGroupBaseTest.php')
-rw-r--r-- | MLEB/Translate/tests/phpunit/MessageGroupBaseTest.php | 94 |
1 files changed, 18 insertions, 76 deletions
diff --git a/MLEB/Translate/tests/phpunit/MessageGroupBaseTest.php b/MLEB/Translate/tests/phpunit/MessageGroupBaseTest.php index 7353d911..9f47c22d 100644 --- a/MLEB/Translate/tests/phpunit/MessageGroupBaseTest.php +++ b/MLEB/Translate/tests/phpunit/MessageGroupBaseTest.php @@ -1,8 +1,11 @@ <?php declare( strict_types = 1 ); -use MediaWiki\Extensions\Translate\Validation\MessageValidator as MessageValidatorInterface; -use MediaWiki\Extensions\Translate\Validation\ValidationIssues; +use MediaWiki\Extension\Translate\TranslatorInterface\Insertable\Insertable; +use MediaWiki\Extension\Translate\TranslatorInterface\Insertable\InsertablesSuggester; +use MediaWiki\Extension\Translate\Validation\MessageValidator; +use MediaWiki\Extension\Translate\Validation\ValidationIssues; +use MediaWiki\Extension\Translate\Validation\ValidationRunner; /** * @license GPL-2.0-or-later @@ -11,7 +14,6 @@ use MediaWiki\Extensions\Translate\Validation\ValidationIssues; class MessageGroupBaseTest extends MediaWikiIntegrationTestCase { /** @var MessageGroup */ protected $group; - protected $groupConfiguration = [ 'BASIC' => [ 'class' => FileBasedMessageGroup::class, @@ -22,12 +24,12 @@ class MessageGroupBaseTest extends MediaWikiIntegrationTestCase { ], ]; - protected function setUp() : void { + protected function setUp(): void { parent::setUp(); $this->group = MessageGroupBase::factory( $this->groupConfiguration ); } - protected function tearDown() : void { + protected function tearDown(): void { unset( $this->group ); parent::tearDown(); } @@ -88,65 +90,6 @@ class MessageGroupBaseTest extends MediaWikiIntegrationTestCase { ); } - public function testInsertablesSuggesterClass() { - $conf = $this->groupConfiguration; - $conf['INSERTABLES']['class'] = FakeInsertablesSuggester::class; - $this->group = MessageGroupBase::factory( $conf ); - - $this->assertArrayEquals( - [ new Insertable( 'Fake', 'Insertables', 'Suggester' ) ], - $this->group->getInsertablesSuggester()->getInsertables( '' ) - ); - } - - public function testInsertablesSuggesterClasses() { - $conf = $this->groupConfiguration; - $conf['INSERTABLES']['classes'] = [ - 'FakeInsertablesSuggester', - 'AnotherFakeInsertablesSuggester', - ]; - $this->group = MessageGroupBase::factory( $conf ); - - $this->assertArrayEquals( - [ - new Insertable( 'Fake', 'Insertables', 'Suggester' ), - new Insertable( 'AnotherFake', 'Insertables', 'Suggester' ), - ], - $this->group->getInsertablesSuggester()->getInsertables( '' ) - ); - } - - public function testInsertablesSuggesterClassAndClasses() { - $conf = $this->groupConfiguration; - $conf['INSERTABLES']['class'] = FakeInsertablesSuggester::class; - $conf['INSERTABLES']['classes'] = [ AnotherFakeInsertablesSuggester::class ]; - $this->group = MessageGroupBase::factory( $conf ); - - $this->assertArrayEquals( - [ - new Insertable( 'Fake', 'Insertables', 'Suggester' ), - new Insertable( 'AnotherFake', 'Insertables', 'Suggester' ), - ], - $this->group->getInsertablesSuggester()->getInsertables( '' ) - ); - - $conf['INSERTABLES']['classes'][] = 'FakeInsertablesSuggester'; - $conf['INSERTABLES']['classes'][] = 'AnotherFakeInsertablesSuggester'; - $this->group = MessageGroupBase::factory( $conf ); - - $this->assertArrayEquals( - [ - new Insertable( 'Fake', 'Insertables', 'Suggester' ), - new Insertable( 'AnotherFake', 'Insertables', 'Suggester' ), - ], - $this->group->getInsertablesSuggester()->getInsertables( '' ), - false, - false, - "should correctly get InsertablesSuggesters using " . - "both 'class' and 'classes' options and removing duplicates." - ); - } - public function testGetNamespaceInvalid() { $conf = $this->groupConfiguration; $conf['BASIC']['namespace'] = 'ergweofijwef'; @@ -185,8 +128,9 @@ class MessageGroupBaseTest extends MediaWikiIntegrationTestCase { public function testInsertableValidatorConfiguration() { $conf = $this->groupConfiguration; - unset( $conf['INSERTABLES']['class'] ); - $conf['INSERTABLES']['classes'] = [ AnotherFakeInsertablesSuggester::class ]; + $conf['INSERTABLES'] = [ + [ 'class' => AnotherFakeInsertablesSuggester::class ] + ]; $conf['VALIDATORS'] = []; $conf['VALIDATORS'][] = [ 'class' => FakeInsertableValidator::class, @@ -204,8 +148,8 @@ class MessageGroupBaseTest extends MediaWikiIntegrationTestCase { $messageValidators = $this->group->getValidator(); $insertables = $this->group->getInsertablesSuggester()->getInsertables( '' ); - $this->assertInstanceOf( MessageValidator::class, $messageValidators, - "should correctly fetch a 'MessageValidator' using the 'VALIDATOR' configuration." + $this->assertInstanceOf( ValidationRunner::class, $messageValidators, + "should correctly fetch a 'ValidationRunner' using the 'VALIDATOR' configuration." ); // Returns insertables from, @@ -225,8 +169,6 @@ class MessageGroupBaseTest extends MediaWikiIntegrationTestCase { public function testInsertableArrayConfiguration() { $conf = $this->groupConfiguration; - unset( $conf['INSERTABLES']['class'] ); - unset( $conf['INSERTABLES']['classes'] ); $conf['INSERTABLES'] = [ [ @@ -257,33 +199,33 @@ class MessageGroupBaseTest extends MediaWikiIntegrationTestCase { } class FakeInsertablesSuggester implements InsertablesSuggester { - public function getInsertables( $text ) { + public function getInsertables( string $text ): array { return [ new Insertable( 'Fake', 'Insertables', 'Suggester' ) ]; } } class AnotherFakeInsertablesSuggester implements InsertablesSuggester { - public function getInsertables( $text ) { + public function getInsertables( string $text ): array { return [ new Insertable( 'AnotherFake', 'Insertables', 'Suggester' ) ]; } } -class FakeInsertableValidator implements MessageValidatorInterface, InsertablesSuggester { +class FakeInsertableValidator implements MessageValidator, InsertablesSuggester { public function getIssues( TMessage $message, string $targetLanguage ): ValidationIssues { return new ValidationIssues(); } - public function getInsertables( $text ) { + public function getInsertables( string $text ): array { return [ new Insertable( 'Fake', 'Insertable', 'Validator' ) ]; } } -class AnotherFakeInsertableValidator implements MessageValidatorInterface, InsertablesSuggester { +class AnotherFakeInsertableValidator implements MessageValidator, InsertablesSuggester { public function getIssues( TMessage $message, string $targetLanguage ): ValidationIssues { return new ValidationIssues(); } - public function getInsertables( $text ) { + public function getInsertables( string $text ): array { return [ new Insertable( 'Another', 'Fake Insertable', 'Validator' ) ]; } } |