const SCREEN_MEDIA_QUERY = 'screen and (min-width: 982px)';
const SCREEN_ONLY_MEDIA_QUERY = 'only screen and (min-width: 982px)';
+ // Ensure that we don't affect the global ResourceLoader state.
+ protected function setUp() {
+ parent::setUp();
+ ResourceLoader::clearCache();
+ }
+ protected function tearDown() {
+ parent::tearDown();
+ ResourceLoader::clearCache();
+ }
+
/**
* @dataProvider provideRedirect
*
/**
* Test the actual behavior of the method (in the case where it doesn't throw, e.g., in
- * production). Since it threw an exception once in this file, it won't when we call it again.
+ * production).
*
* @covers OutputPage::addScriptFile
*/
public function testAddDeprecatedScriptFileNoOp() {
+ $this->hideDeprecated( 'OutputPage::addScriptFile' );
$op = $this->newInstance();
$op->addScriptFile( 'ignored-script.js' );
$op = $this->getMockBuilder( OutputPage::class )
->setConstructorArgs( [ new RequestContext() ] )
- ->setMethods( [ 'addCategoryLinksToLBAndGetResult' ] )
+ ->setMethods( [ 'addCategoryLinksToLBAndGetResult', 'getTitle' ] )
->getMock();
+ $title = Title::newFromText( 'My test page' );
+ $op->expects( $this->any() )
+ ->method( 'getTitle' )
+ ->will( $this->returnValue( $title ) );
+
$op->expects( $this->any() )
->method( 'addCategoryLinksToLBAndGetResult' )
->will( $this->returnCallback( function ( array $categories ) use ( $fakeResults ) {
/**
* @dataProvider provideAddWikiText
* @covers OutputPage::addWikiText
+ * @covers OutputPage::addWikiTextAsInterface
+ * @covers OutputPage::addWikiTextAsContent
* @covers OutputPage::addWikiTextWithTitle
* @covers OutputPage::addWikiTextTitle
+ * @covers OutputPage::addWikiTextTidy
+ * @covers OutputPage::addWikiTextTitleTidy
* @covers OutputPage::getHTML
*/
public function testAddWikiText( $method, array $args, $expected ) {
$op = $this->newInstance();
$this->assertSame( '', $op->getHTML() );
+ $this->hideDeprecated( 'OutputPage::addWikiTextTitle' );
+ $this->hideDeprecated( 'OutputPage::addWikiTextWithTitle' );
if ( in_array(
$method,
[ 'addWikiTextWithTitle', 'addWikiTextTitleTidy', 'addWikiTextTitle' ]
// Special placeholder because we can't get the actual title in the provider
$args[1] = $op->getTitle();
}
+ if ( in_array(
+ $method,
+ [ 'addWikiTextAsInterface', 'addWikiTextAsContent' ]
+ ) && count( $args ) >= 3 && $args[2] === null ) {
+ // Special placeholder because we can't get the actual title in the provider
+ $args[2] = $op->getTitle();
+ }
$op->$method( ...$args );
$this->assertSame( $expected, $op->getHTML() );
public function provideAddWikiText() {
$tests = [
'addWikiText' => [
+ // Not tidied; this API is deprecated.
'Simple wikitext' => [
[ "'''Bold'''" ],
"<p><b>Bold</b>\n</p>",
'* Not a list',
], 'Non-interface' => [
[ "'''Bold'''", true, false ],
- "<div class=\"mw-parser-output\"><p><b>Bold</b>\n</p></div>",
+ "<p><b>Bold</b>\n</p>",
], 'No section edit links' => [
[ '== Title ==' ],
"<h2><span class=\"mw-headline\" id=\"Title\">Title</span></h2>\n",
],
],
'addWikiTextWithTitle' => [
+ // Untidied; this API is deprecated
'With title at start' => [
[ '* {{PAGENAME}}', Title::newFromText( 'Talk:Some page' ) ],
- "<div class=\"mw-parser-output\"><ul><li>Some page</li></ul>\n</div>",
+ "<ul><li>Some page</li></ul>\n",
], 'With title at start' => [
[ '* {{PAGENAME}}', Title::newFromText( 'Talk:Some page' ), false ],
- "<div class=\"mw-parser-output\">* Some page</div>",
+ "* Some page",
+ ],
+ ],
+ 'addWikiTextAsInterface' => [
+ // Preferred interface: output is tidied
+ 'Simple wikitext' => [
+ [ "'''Bold'''" ],
+ "<p><b>Bold</b>\n</p>",
+ ], 'Untidy wikitext' => [
+ [ "<b>Bold" ],
+ "<p><b>Bold\n</b></p>",
+ ], 'List at start' => [
+ [ '* List' ],
+ "<ul><li>List</li></ul>\n",
+ ], 'List not at start' => [
+ [ '* Not a list', false ],
+ '<p>* Not a list</p>',
+ ], 'No section edit links' => [
+ [ '== Title ==' ],
+ "<h2><span class=\"mw-headline\" id=\"Title\">Title</span></h2>\n",
+ ], 'With title at start' => [
+ [ '* {{PAGENAME}}', true, Title::newFromText( 'Talk:Some page' ) ],
+ "<ul><li>Some page</li></ul>\n",
+ ], 'With title at start' => [
+ [ '* {{PAGENAME}}', false, Title::newFromText( 'Talk:Some page' ), false ],
+ "<p>* Some page</p>",
+ ], 'Untidy input' => [
+ [ '<b>{{PAGENAME}}', true, Title::newFromText( 'Talk:Some page' ) ],
+ "<p><b>Some page\n</b></p>",
+ ],
+ ],
+ 'addWikiTextAsContent' => [
+ // Preferred interface: output is tidied
+ 'SpecialNewimages' => [
+ [ "<p lang='en' dir='ltr'>\nMy message" ],
+ '<p lang="en" dir="ltr">' . "\nMy message\n</p>"
+ ], 'List at start' => [
+ [ '* List' ],
+ "<ul><li>List</li></ul>\n",
+ ], 'List not at start' => [
+ [ '* <b>Not a list', false ],
+ '<p>* <b>Not a list</b></p>',
+ ], 'With title at start' => [
+ [ '* {{PAGENAME}}', true, Title::newFromText( 'Talk:Some page' ) ],
+ "<ul><li>Some page</li></ul>\n",
+ ], 'With title at start' => [
+ [ '* {{PAGENAME}}', false, Title::newFromText( 'Talk:Some page' ), false ],
+ "<p>* Some page</p>",
+ ], 'EditPage' => [
+ [ "<div class='mw-editintro'>{{PAGENAME}}", true, Title::newFromText( 'Talk:Some page' ) ],
+ '<div class="mw-editintro">' . "Some page\n</div>"
],
],
];
$tests['addWikiTextTitle']["$key (addWikiTextTitle)"] =
array_merge( [ $args ], array_slice( $val, 1 ) );
}
+ foreach ( $tests['addWikiTextAsInterface'] as $key => $val ) {
+ $args = [ $val[0][0], $val[0][2] ?? null, $val[0][1] ?? true, true, true ];
+ $tests['addWikiTextTitle']["$key (addWikiTextTitle)"] =
+ array_merge( [ $args ], array_slice( $val, 1 ) );
+ }
+ foreach ( $tests['addWikiTextAsContent'] as $key => $val ) {
+ $args = [ $val[0][0], $val[0][2] ?? null, $val[0][1] ?? true, true, false ];
+ $tests['addWikiTextTitle']["$key (addWikiTextTitle)"] =
+ array_merge( [ $args ], array_slice( $val, 1 ) );
+ }
+ // addWikiTextTidy / addWikiTextTitleTidy were old aliases of
+ // addWikiTextAsContent
+ foreach ( $tests['addWikiTextAsContent'] as $key => $val ) {
+ if ( count( $val[0] ) > 2 ) {
+ $args = [ $val[0][0], $val[0][2], $val[0][1] ?? true ];
+ $tests['addWikiTextTitleTidy']["$key (addWikiTextTitleTidy)"] =
+ array_merge( [ $args ], array_slice( $val, 1 ) );
+ } else {
+ $args = [ $val[0][0], $val[0][1] ?? true ];
+ $tests['addWikiTextTidy']["$key (addWikiTextTidy)"] =
+ array_merge( [ $args ], array_slice( $val, 1 ) );
+ }
+ }
// We have to reformat our array to match what PHPUnit wants
$ret = [];
$op->addWikiText( 'a' );
}
- // @todo How should we cover the Tidy variants?
+ /**
+ * @covers OutputPage::addWikiTextAsInterface
+ */
+ public function testAddWikiTextAsInterfaceNoTitle() {
+ $this->setExpectedException( MWException::class, 'Title is null' );
+
+ $op = $this->newInstance( [], null, 'notitle' );
+ $op->addWikiTextAsInterface( 'a' );
+ }
+
+ /**
+ * @covers OutputPage::addWikiTextAsContent
+ */
+ public function testAddWikiTextAsContentNoTitle() {
+ $this->setExpectedException( MWException::class, 'Title is null' );
+
+ $op = $this->newInstance( [], null, 'notitle' );
+ $op->addWikiTextAsContent( 'a' );
+ }
+
+ /**
+ * @covers OutputPage::addWikiMsg
+ */
+ public function testAddWikiMsg() {
+ $msg = wfMessage( 'parentheses' );
+ $this->assertSame( '(a)', $msg->rawParams( 'a' )->plain() );
+
+ $op = $this->newInstance();
+ $this->assertSame( '', $op->getHTML() );
+ $op->addWikiMsg( 'parentheses', "<b>a" );
+ // This is known to be bad unbalanced HTML; this will be fixed
+ // by I743f4185a03403f8d9b9db010ff1ee4e9342e062 (T198214)
+ $this->assertSame( "<p>(<b>a)\n</p>", $op->getHTML() );
+ }
+
+ /**
+ * @covers OutputPage::wrapWikiMsg
+ */
+ public function testWrapWikiMsg() {
+ $msg = wfMessage( 'parentheses' );
+ $this->assertSame( '(a)', $msg->rawParams( 'a' )->plain() );
+
+ $op = $this->newInstance();
+ $this->assertSame( '', $op->getHTML() );
+ $op->wrapWikiMsg( '[$1]', [ 'parentheses', "<b>a" ] );
+ // This is known to be bad unbalanced HTML; this will be fixed
+ // by I743f4185a03403f8d9b9db010ff1ee4e9342e062 (T198214)
+ $this->assertSame( "<p>[(<b>a)]\n</p>", $op->getHTML() );
+ }
/**
* @covers OutputPage::addParserOutputMetadata
'exemptStyleModules' => [ 'site' => [ 'site.styles' ], 'user' => [ 'user.styles' ] ],
'<meta name="ResourceLoaderDynamicStyles" content=""/>' . "\n" .
'<link rel="stylesheet" href="/w/load.php?debug=false&lang=en&modules=site.styles&only=styles&skin=fallback"/>' . "\n" .
- '<link rel="stylesheet" href="/w/load.php?debug=false&lang=en&modules=user.styles&only=styles&skin=fallback&version=1e9z0ox"/>',
+ '<link rel="stylesheet" href="/w/load.php?debug=false&lang=en&modules=user.styles&only=styles&skin=fallback&version=1ai9g6t"/>',
],
'custom modules' => [
'exemptStyleModules' => [
'<link rel="stylesheet" href="/w/load.php?debug=false&lang=en&modules=example.site.a%2Cb&only=styles&skin=fallback"/>' . "\n" .
'<link rel="stylesheet" href="/w/load.php?debug=false&lang=en&modules=site.styles&only=styles&skin=fallback"/>' . "\n" .
'<link rel="stylesheet" href="/w/load.php?debug=false&lang=en&modules=example.user&only=styles&skin=fallback&version=0a56zyi"/>' . "\n" .
- '<link rel="stylesheet" href="/w/load.php?debug=false&lang=en&modules=user.styles&only=styles&skin=fallback&version=1e9z0ox"/>',
+ '<link rel="stylesheet" href="/w/load.php?debug=false&lang=en&modules=user.styles&only=styles&skin=fallback&version=1ai9g6t"/>',
],
];
// phpcs:enable