aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/unit
diff options
context:
space:
mode:
Diffstat (limited to 'tests/phpunit/unit')
-rw-r--r--tests/phpunit/unit/includes/GlobalFunctions/WfEscapeWikiTextTest.php22
-rw-r--r--tests/phpunit/unit/includes/Permissions/UserAuthorityTest.php25
2 files changed, 30 insertions, 17 deletions
diff --git a/tests/phpunit/unit/includes/GlobalFunctions/WfEscapeWikiTextTest.php b/tests/phpunit/unit/includes/GlobalFunctions/WfEscapeWikiTextTest.php
index ed3b37fcf4ed..c9de634b8fe4 100644
--- a/tests/phpunit/unit/includes/GlobalFunctions/WfEscapeWikiTextTest.php
+++ b/tests/phpunit/unit/includes/GlobalFunctions/WfEscapeWikiTextTest.php
@@ -14,16 +14,18 @@ class WfEscapeWikiTextTest extends MediaWikiUnitTestCase {
$old = $wgEnableMagicLinks;
$wgEnableMagicLinks = [];
- $actual = wfEscapeWikiText( $input );
- // Sanity check that the output can be decoded back to the input
- // input as well.
- $decoded = html_entity_decode( $actual, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML5 );
- $this->assertEquals( $decoded, (string)$input );
- // And that the output was what we expected
- $this->assertEquals( $expected, $actual );
-
- // restore global
- $wgEnableMagicLinks = $old;
+ try {
+ $actual = wfEscapeWikiText( $input );
+ // Sanity check that the output can be decoded back to the input
+ // input as well.
+ $decoded = html_entity_decode( $actual, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML5 );
+ $this->assertEquals( $decoded, (string)$input );
+ // And that the output was what we expected
+ $this->assertEquals( $expected, $actual );
+ } finally {
+ // restore global
+ $wgEnableMagicLinks = $old;
+ }
}
public function provideEscape() {
diff --git a/tests/phpunit/unit/includes/Permissions/UserAuthorityTest.php b/tests/phpunit/unit/includes/Permissions/UserAuthorityTest.php
index a910f922c0f6..1152572f2179 100644
--- a/tests/phpunit/unit/includes/Permissions/UserAuthorityTest.php
+++ b/tests/phpunit/unit/includes/Permissions/UserAuthorityTest.php
@@ -26,6 +26,8 @@ use MediaWiki\Page\PageIdentity;
use MediaWiki\Page\PageIdentityValue;
use MediaWiki\Permissions\PermissionStatus;
use MediaWiki\Permissions\RateLimiter;
+use MediaWiki\Status\StatusFormatter;
+use MediaWiki\Tests\Unit\FakeQqxMessageLocalizer;
use MediaWiki\User\User;
use MediaWikiUnitTestCase;
@@ -381,12 +383,21 @@ class UserAuthorityTest extends MediaWikiUnitTestCase {
$this->assertStatusError( 'blockedtext-partial', $permissionStatus );
$this->assertNotNull( $permissionStatus->getBlock() );
- // The actual index is not relevant and depends on the implementation
- $message = $permissionStatus->getMessages()[2];
- $this->assertEquals( 'blockedtext-partial', $message->getKey() );
- $this->assertArrayEquals(
- $this->getFakeBlockMessageParams(),
- $message->getParams()
- );
+ $formatter = new StatusFormatter( new FakeQqxMessageLocalizer(), $this->createNoOpMock( \MessageCache::class ) );
+ // Despite all the futzing around with services, StatusFormatter depends on this global through wfEscapeWikiText
+ global $wgEnableMagicLinks;
+ $old = $wgEnableMagicLinks;
+ $wgEnableMagicLinks = [];
+
+ try {
+ $wikitext = $formatter->getWikiText( $permissionStatus );
+ // Assert that the formatted wikitext contains the original values of the message parameters,
+ // rather than escaped ones
+ foreach ( $this->getFakeBlockMessageParams() as $param ) {
+ $this->assertStringContainsString( $param, $wikitext );
+ }
+ } finally {
+ $wgEnableMagicLinks = $old;
+ }
}
}