diff options
Diffstat (limited to 'MLEB/Translate/tests/phpunit/unit/Synchronization/MessageUpdateParameterTest.php')
-rw-r--r-- | MLEB/Translate/tests/phpunit/unit/Synchronization/MessageUpdateParameterTest.php | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/MLEB/Translate/tests/phpunit/unit/Synchronization/MessageUpdateParameterTest.php b/MLEB/Translate/tests/phpunit/unit/Synchronization/MessageUpdateParameterTest.php new file mode 100644 index 00000000..22e4f639 --- /dev/null +++ b/MLEB/Translate/tests/phpunit/unit/Synchronization/MessageUpdateParameterTest.php @@ -0,0 +1,101 @@ +<?php + +namespace MediaWiki\Extensions\Translate\Synchronization; + +use MediaWikiUnitTestCase; +use MessageUpdateJob; +use Title; + +/** + * @covers \MediaWiki\Extensions\Translate\Synchronization\MessageUpdateParameter + */ +class MessageUpdateParameterTest extends MediaWikiUnitTestCase { + /** + * @dataProvider provideSerializable + */ + public function testSerializable( + string $title, + string $content, + bool $isRename, + string $target = '', + string $replacement = '', + bool $isFuzzy = false, + array $otherLangs = [] + ) { + $job = $this->getJobFromInput( + $title, $content, $isRename, $target, $replacement, $isFuzzy, $otherLangs + ); + + $messageParam = MessageUpdateParameter::createFromJob( $job ); + + $serializedMessageParam = unserialize( serialize( $messageParam ) ); + $this->assertEquals( $messageParam, $serializedMessageParam ); + } + + /** + * @dataProvider provideSerializable + */ + public function testCreateFromJob( + string $title, + string $content, + bool $isRename, + string $target = '', + string $replacement = '', + bool $isFuzzy = false, + array $otherLangs = [] + ) { + $job = $this->getJobFromInput( + $title, $content, $isRename, $target, $replacement, $isFuzzy, $otherLangs + ); + $messageParams = MessageUpdateParameter::createFromJob( $job ); + $this->assertEquals( $title, $messageParams->getPageName() ); + $this->assertEquals( $content, $messageParams->getContent() ); + $this->assertEquals( $isRename, $messageParams->isRename() ); + $this->assertEquals( $isFuzzy, $messageParams->isFuzzy() ); + if ( $isRename ) { + $this->assertEquals( $target, $messageParams->getTargetValue() ); + $this->assertEquals( $replacement, $messageParams->getReplacementValue() ); + $this->assertEquals( $otherLangs, $messageParams->getOtherLangs() ); + } + } + + private function getJobFromInput( + string $title, + string $content, + bool $isRename, + string $target, + string $replacement, + bool $isFuzzy, + array $otherLangs + ): MessageUpdateJob { + $title = Title::makeTitle( NS_MAIN, $title ); + if ( $isRename ) { + $job = MessageUpdateJob::newRenameJob( + $title, $target, $replacement, $isFuzzy, $content, $otherLangs + ); + } else { + $job = MessageUpdateJob::newJob( $title, $content, $isFuzzy ); + } + + return $job; + } + + public function provideSerializable() { + yield [ + 'Normal_Job/en', + 'Hello World!', + false, + ]; + + yield [ + 'Rename_Job/en', + 'Hello World - Rename!', + true, + 'target', + 'replacement', + true, + [ 'hello' => 'world' ] + ]; + } + +} |