jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/340147 )
Change subject: Trivialize InterWikiLinkWikitextFormatterTest ...................................................................... Trivialize InterWikiLinkWikitextFormatterTest Main change in here is the test for spaces and single quotes. This was not fully tested before. Spaces should not be encoded in the label. Quotes should be encoded in the label, but must use an other encoding. This change also changes many self:: calls to phpunit assert methods to call $this-> instead. Bug: T57549 Change-Id: I94309aaa3408b78dc625eba7677c361bf93120e2 --- M lib/tests/phpunit/Formatters/InterWikiLinkWikitextFormatterTest.php M repo/tests/phpunit/includes/ChangeOp/NullChangeOpTest.php M repo/tests/phpunit/includes/Specials/HTMLForm/HTMLAliasesFieldTest.php M repo/tests/phpunit/includes/Specials/HTMLForm/HTMLContentLanguageFieldTest.php M repo/tests/phpunit/includes/Specials/HTMLForm/HTMLItemReferenceFieldTest.php 5 files changed, 34 insertions(+), 68 deletions(-) Approvals: WMDE-leszek: Looks good to me, but someone else must approve Addshore: Looks good to me, approved jenkins-bot: Verified diff --git a/lib/tests/phpunit/Formatters/InterWikiLinkWikitextFormatterTest.php b/lib/tests/phpunit/Formatters/InterWikiLinkWikitextFormatterTest.php index b8ef856..277a568 100644 --- a/lib/tests/phpunit/Formatters/InterWikiLinkWikitextFormatterTest.php +++ b/lib/tests/phpunit/Formatters/InterWikiLinkWikitextFormatterTest.php @@ -15,93 +15,59 @@ class InterWikiLinkWikitextFormatterTest extends \PHPUnit_Framework_TestCase { public function testSomeTitleGiven_FormatsItAsAnExternalLink() { - $formatter = $this->createFormatter( '//site.org/wiki/' ); + $formatter = new InterWikiLinkWikitextFormatter( '//site.org/wiki/' ); $link = $formatter->format( new StringValue( 'Namespace:Title' ) ); - self::assertEquals( + $this->assertSame( '[//site.org/wiki/Namespace:Title Namespace:Title]', $link ); } public function testTitleContainsSpaces_ReplacesSpacesWithUnderscoresWhenFormats() { - $formatter = $this->createFormatter( '//site.org/wiki/' ); + $formatter = new InterWikiLinkWikitextFormatter( '//site.org/wiki/' ); $link = $formatter->format( new StringValue( 'Namespace:Title with spaces' ) ); - $url = $this->extractUrlFromExternalWikitextLink( $link ); - self::assertEquals( - '//site.org/wiki/Namespace:Title_with_spaces', - $url + $this->assertSame( + '[//site.org/wiki/Namespace:Title_with_spaces Namespace:Title with spaces]', + $link ); } - public function testTitleDoubleSingleQuotes_HtmlencodesThemInTitleWhenFormats() { - $formatter = $this->createFormatter( '//base.url/' ); + public function testTitleDoubleSingleQuotes_EncodesThemWhenFormats() { + $formatter = new InterWikiLinkWikitextFormatter( '//base.url/' ); $link = $formatter->format( new StringValue( "Namespace:Title ''with'' quotes" ) ); - $text = $this->extractLinkTextFromExternalWikitextLink( $link ); - self::assertEquals( - 'Namespace:Title ''with'' quotes', - $text + $this->assertSame( + '[//base.url/Namespace:Title_%27%27with%27%27_quotes ' + . 'Namespace:Title ''with'' quotes]', + $link ); } public function testBasePathContainsSpace_EncodesSpaceWhenFormats() { - $formatter = $this->createFormatter( '//base.url/some wiki/' ); + $formatter = new InterWikiLinkWikitextFormatter( '//base.url/some wiki/' ); $link = $formatter->format( new StringValue( 'Namespace:Title' ) ); - $text = $this->extractUrlFromExternalWikitextLink( $link ); - self::assertEquals( - '//base.url/some+wiki/Namespace:Title', - $text + $this->assertStringStartsWith( + '[//base.url/some+wiki/', + $link ); } public function testBasePathContainsPercent_EncodesPercentWhenFormats() { - $formatter = $this->createFormatter( '//base.url/100%wiki/' ); + $formatter = new InterWikiLinkWikitextFormatter( '//base.url/100%wiki/' ); $link = $formatter->format( new StringValue( 'Namespace:Title' ) ); - $text = $this->extractUrlFromExternalWikitextLink( $link ); - self::assertEquals( - '//base.url/100%25wiki/Namespace:Title', - $text + $this->assertStringStartsWith( + '[//base.url/100%25wiki/', + $link ); - } - - /** - * @return InterWikiLinkWikitextFormatter - */ - private function createFormatter( $baseUrl ) { - return new InterWikiLinkWikitextFormatter( $baseUrl ); - } - - /** - * @param $link - * - * @return string - */ - private function extractLinkTextFromExternalWikitextLink( $link ) { - list( , $text ) = explode( ' ', $link, 2 ); - $text = substr( $text, 0, strlen( $text ) - 1 ); - - return $text; - } - - /** - * @param $link - * - * @return string - */ - private function extractUrlFromExternalWikitextLink( $link ) { - list( $url ) = explode( ' ', $link, 2 ); - $url = substr( $url, 1 ); - - return $url; } } diff --git a/repo/tests/phpunit/includes/ChangeOp/NullChangeOpTest.php b/repo/tests/phpunit/includes/ChangeOp/NullChangeOpTest.php index def7e2f..b4b07b1 100644 --- a/repo/tests/phpunit/includes/ChangeOp/NullChangeOpTest.php +++ b/repo/tests/phpunit/includes/ChangeOp/NullChangeOpTest.php @@ -21,7 +21,7 @@ $result = $nullChangeOp->validate( $entityDocument ); - self::assertTrue( $result->isValid() ); + $this->assertTrue( $result->isValid() ); } public function testDoesNotCallAnyMethodOnEntity_WhenApplied() { diff --git a/repo/tests/phpunit/includes/Specials/HTMLForm/HTMLAliasesFieldTest.php b/repo/tests/phpunit/includes/Specials/HTMLForm/HTMLAliasesFieldTest.php index 380f8f6..c1725c0 100644 --- a/repo/tests/phpunit/includes/Specials/HTMLForm/HTMLAliasesFieldTest.php +++ b/repo/tests/phpunit/includes/Specials/HTMLForm/HTMLAliasesFieldTest.php @@ -46,7 +46,7 @@ ] ); - self::assertEquals( 'text', $field->mParams['type'] ); + $this->assertSame( 'text', $field->mParams['type'] ); } public function testConvertsToArrayAndRemovesExtraSpaces_WhenFilters() { @@ -54,7 +54,7 @@ $result = $field->filter( ' a | b ', [] ); - self::assertEquals( [ 'a', 'b' ], $result ); + $this->assertSame( [ 'a', 'b' ], $result ); } public function testRemovesEmptyValues_WhenFilters() { @@ -62,7 +62,7 @@ $result = $field->filter( 'a| |b', [] ); - self::assertEquals( [ 'a', 'b' ], $result ); + $this->assertSame( [ 'a', 'b' ], $result ); } public function testValidationFailsWithGenericMessage_WhenRequiredAndEmptyArrayGivenAsValue() { @@ -71,7 +71,7 @@ /** @var \Message $failureMessage */ $failureMessage = $field->validate( [], [] ); - self::assertEquals( 'htmlform-required', $failureMessage->getKey() ); + $this->assertSame( 'htmlform-required', $failureMessage->getKey() ); } public function testValidationPasses_WhenRequiredAndNonEmptyArrayGivenAsValue() { @@ -79,7 +79,7 @@ $result = $field->validate( [ 'a' ], [] ); - self::assertTrue( $result ); + $this->assertTrue( $result ); } public function testValidationPasses_WhenNotRequiredAndEmptyArrayGivenAsValue() { @@ -87,7 +87,7 @@ $result = $field->validate( [], [] ); - self::assertTrue( $result ); + $this->assertTrue( $result ); } /** diff --git a/repo/tests/phpunit/includes/Specials/HTMLForm/HTMLContentLanguageFieldTest.php b/repo/tests/phpunit/includes/Specials/HTMLForm/HTMLContentLanguageFieldTest.php index daf2dff..1a7084e 100644 --- a/repo/tests/phpunit/includes/Specials/HTMLForm/HTMLContentLanguageFieldTest.php +++ b/repo/tests/phpunit/includes/Specials/HTMLForm/HTMLContentLanguageFieldTest.php @@ -48,7 +48,7 @@ $field = $this->createField( $params ); - self::assertEquals( 'some-language', $field->getDefault() ); + $this->assertSame( 'some-language', $field->getDefault() ); } public function testUsesDefaultValue_WhenDefaultIsDefined() { @@ -58,7 +58,7 @@ $field = $this->createField( $params ); - self::assertEquals( 'default-language', $field->getDefault() ); + $this->assertSame( 'default-language', $field->getDefault() ); } private function createNewContextSourceWithLanguage( $langCode ) { diff --git a/repo/tests/phpunit/includes/Specials/HTMLForm/HTMLItemReferenceFieldTest.php b/repo/tests/phpunit/includes/Specials/HTMLForm/HTMLItemReferenceFieldTest.php index d9de0d6..4dffa81 100644 --- a/repo/tests/phpunit/includes/Specials/HTMLForm/HTMLItemReferenceFieldTest.php +++ b/repo/tests/phpunit/includes/Specials/HTMLForm/HTMLItemReferenceFieldTest.php @@ -37,7 +37,7 @@ public function testSetsTypeToText_WhenCreated() { $field = $this->createField(); - self::assertEquals( 'text', $field->mParams['type'] ); + $this->assertSame( 'text', $field->mParams['type'] ); } public function testValidationPasses_WhenEmptyStringGivenAndFieldIsNotRequired() { @@ -45,7 +45,7 @@ $result = $field->validate( '', [] ); - self::assertTrue( $result ); + $this->assertTrue( $result ); } public function testValidationFailsWithInvalidFormatMessage_WhenEnteredTextDoesNotMatchItemIdFormat() { @@ -54,7 +54,7 @@ /** @var \Message $failureMessage */ $failureMessage = $field->validate( 'x', [] ); - self::assertEquals( 'wikibase-item-reference-edit-invalid-format', $failureMessage->getKey() ); + $this->assertSame( 'wikibase-item-reference-edit-invalid-format', $failureMessage->getKey() ); } public function testValidationFailsWithNonexistentItemMessage_WhenItemHavingEnteredIdDoesNotExist() { @@ -63,7 +63,7 @@ /** @var \Message $failureMessage */ $failureMessage = $field->validate( 'Q2', [] ); - self::assertEquals( 'wikibase-item-reference-edit-nonexistent-item', $failureMessage->getKey() ); + $this->assertSame( 'wikibase-item-reference-edit-nonexistent-item', $failureMessage->getKey() ); } public function testValidationCallbackExecuted_WhenReferencedItemExists() { @@ -79,7 +79,7 @@ /** @var \Message $failureMessage */ $failureMessage = $field->validate( $existingItemId, [] ); - self::assertEquals( 'some-message', $failureMessage->getKey() ); + $this->assertSame( 'some-message', $failureMessage->getKey() ); } /** -- To view, visit https://gerrit.wikimedia.org/r/340147 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I94309aaa3408b78dc625eba7677c361bf93120e2 Gerrit-PatchSet: 3 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de> Gerrit-Reviewer: Addshore <addshorew...@gmail.com> Gerrit-Reviewer: Aleksey Bekh-Ivanov (WMDE) <aleksey.bekh-iva...@wikimedia.de> Gerrit-Reviewer: Jonas Kress (WMDE) <jonas.kr...@wikimedia.de> Gerrit-Reviewer: WMDE-leszek <leszek.mani...@wikimedia.de> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits