diff options
author | jenkins-bot <jenkins-bot@gerrit.wikimedia.org> | 2021-04-16 17:49:53 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@wikimedia.org> | 2021-04-16 17:49:53 +0000 |
commit | 592bb57b31b89a3863671da2f26df4f95011ba7c (patch) | |
tree | c3ea6c1ccc3706770e05edff1975e9dc45a7a6b6 /tests/phpunit | |
parent | 2bb6e3b27010e17deddf94d6aa973e4e39700707 (diff) | |
parent | c1eb74603afdac61960e23630fa1959d3e019bd4 (diff) | |
download | mediawikicore-592bb57b31b89a3863671da2f26df4f95011ba7c.tar.gz mediawikicore-592bb57b31b89a3863671da2f26df4f95011ba7c.zip |
Merge "Remove Title from public interface of OutputPage"
Diffstat (limited to 'tests/phpunit')
-rw-r--r-- | tests/phpunit/includes/OutputPageTest.php | 63 | ||||
-rw-r--r-- | tests/phpunit/mocks/MockTitleTrait.php | 1 | ||||
-rw-r--r-- | tests/phpunit/unit/includes/title/TitleValueTest.php | 31 |
3 files changed, 75 insertions, 20 deletions
diff --git a/tests/phpunit/includes/OutputPageTest.php b/tests/phpunit/includes/OutputPageTest.php index 15e564c9849b..91e90bab712b 100644 --- a/tests/phpunit/includes/OutputPageTest.php +++ b/tests/phpunit/includes/OutputPageTest.php @@ -3,6 +3,9 @@ use MediaWiki\Languages\LanguageConverterFactory; use MediaWiki\MediaWikiServices; use MediaWiki\Page\PageIdentity; +use MediaWiki\Page\PageReference; +use MediaWiki\Page\PageReferenceValue; +use MediaWiki\Page\PageStoreRecord; use MediaWiki\Permissions\Authority; use MediaWiki\Tests\Unit\Permissions\MockAuthorityTrait; use PHPUnit\Framework\MockObject\MockObject; @@ -17,6 +20,7 @@ use Wikimedia\TestingAccessWrapper; */ class OutputPageTest extends MediaWikiIntegrationTestCase { use MockAuthorityTrait; + use MockTitleTrait; private const SCREEN_MEDIA_QUERY = 'screen and (min-width: 982px)'; private const SCREEN_ONLY_MEDIA_QUERY = 'only screen and (min-width: 982px)'; @@ -700,7 +704,7 @@ class OutputPageTest extends MediaWikiIntegrationTestCase { public function testSetRedirectedFrom() { $op = $this->newInstance(); - $op->setRedirectedFrom( Title::newFromText( 'Talk:Some page' ) ); + $op->setRedirectedFrom( new PageReferenceValue( NS_TALK, 'Some page', PageReference::LOCAL ) ); $this->assertSame( 'Talk:Some_page', $op->getJSVars()['wgRedirectedFrom'] ); } @@ -797,12 +801,9 @@ class OutputPageTest extends MediaWikiIntegrationTestCase { return; } - $title = Title::newFromText( $titles[0] ); + $title = $titles[0]; $query = $queries[0]; - $this->editPage( 'Page 1', '' ); - $this->editPage( 'Page 2', '#REDIRECT [[Page 1]]' ); - $str = OutputPage::buildBacklinkSubtitle( $title, $query )->text(); foreach ( $contains as $substr ) { @@ -821,12 +822,9 @@ class OutputPageTest extends MediaWikiIntegrationTestCase { * @covers OutputPage::getSubtitle */ public function testAddBacklinkSubtitle( $titles, $queries, $contains, $notContains ) { - $this->editPage( 'Page 1', '' ); - $this->editPage( 'Page 2', '#REDIRECT [[Page 1]]' ); - $op = $this->newInstance(); foreach ( $titles as $i => $unused ) { - $op->addBacklinkSubtitle( Title::newFromText( $titles[$i] ), $queries[$i] ); + $op->addBacklinkSubtitle( $titles[$i], $queries[$i] ); } $str = $op->getSubtitle(); @@ -841,27 +839,50 @@ class OutputPageTest extends MediaWikiIntegrationTestCase { } public function provideBacklinkSubtitle() { + $page1title = $this->makeMockTitle( 'Page 1', [ 'redirect' => true ] ); + $page1ref = new PageReferenceValue( NS_MAIN, 'Page 1', PageReference::LOCAL ); + + $row = [ + 'page_id' => 28, + 'page_namespace' => NS_MAIN, + 'page_title' => 'Page 2', + 'page_latest' => 75, + 'page_is_redirect' => true, + 'page_is_new' => true, + 'page_touched' => '20200101221133', + 'page_lang' => 'en', + ]; + $page2rec = new PageStoreRecord( (object)$row, PageReference::LOCAL ); + + $special = new PageReferenceValue( NS_SPECIAL, 'BlankPage', PageReference::LOCAL ); + return [ [ - [ 'Page 1' ], + [ $page1title ], [ [] ], [ 'Page 1' ], [ 'redirect', 'Page 2' ], ], [ - [ 'Page 2' ], + [ $page2rec ], [ [] ], [ 'redirect=no' ], [ 'Page 1' ], ], [ - [ 'Page 1' ], + [ $special ], + [ [] ], + [ 'Special:BlankPage' ], + [ 'redirect=no' ], + ], + [ + [ $page1ref ], [ [ 'action' => 'edit' ] ], [ 'action=edit' ], [], ], [ - [ 'Page 1', 'Page 2' ], + [ $page1ref, $page2rec ], [ [], [] ], [ 'Page 1', 'Page 2', "<br />\n\t\t\t\t" ], [], @@ -1637,6 +1658,8 @@ class OutputPageTest extends MediaWikiIntegrationTestCase { } public function provideAddWikiText() { + $somePageRef = new PageReferenceValue( NS_TALK, 'Some page', PageReference::LOCAL ); + $tests = [ 'addWikiTextAsInterface' => [ 'Simple wikitext' => [ @@ -1657,11 +1680,11 @@ class OutputPageTest extends MediaWikiIntegrationTestCase { ], '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 ], + ], 'With title not at start' => [ + [ '* {{PAGENAME}}', false, Title::newFromText( 'Talk:Some page' ) ], "<p>* Some page</p>", ], 'Untidy input' => [ - [ '<b>{{PAGENAME}}', true, Title::newFromText( 'Talk:Some page' ) ], + [ '<b>{{PAGENAME}}', true, $somePageRef ], "<p><b>Some page\n</b></p>", ], ], @@ -1677,12 +1700,12 @@ class OutputPageTest extends MediaWikiIntegrationTestCase { '<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 ], + "<ul><li>Some page</li></ul>", + ], 'With title not at start' => [ + [ '* {{PAGENAME}}', false, Title::newFromText( 'Talk:Some page' ) ], "<p>* Some page</p>", ], 'EditPage' => [ - [ "<div class='mw-editintro'>{{PAGENAME}}", true, Title::newFromText( 'Talk:Some page' ) ], + [ "<div class='mw-editintro'>{{PAGENAME}}", true, $somePageRef ], '<div class="mw-editintro">' . "Some page</div>" ], ], diff --git a/tests/phpunit/mocks/MockTitleTrait.php b/tests/phpunit/mocks/MockTitleTrait.php index 9668fd296550..bc42f1a38166 100644 --- a/tests/phpunit/mocks/MockTitleTrait.php +++ b/tests/phpunit/mocks/MockTitleTrait.php @@ -47,6 +47,7 @@ trait MockTitleTrait { $title->method( 'hasFragment' )->willReturn( !empty( $props['fragment'] ) ); $title->method( 'getInterwiki' )->willReturn( $props['interwiki'] ?? '' ); $title->method( 'exists' )->willReturn( $id > 0 ); + $title->method( 'isRedirect' )->willReturn( $props['redirect'] ?? false ); $title->method( 'getTouched' )->willReturn( $id ? '20200101223344' : false ); $title->method( 'getPageLanguage' )->willReturn( $props['language'] ?? 'qqx' ); $title->method( 'getContentModel' ) diff --git a/tests/phpunit/unit/includes/title/TitleValueTest.php b/tests/phpunit/unit/includes/title/TitleValueTest.php index df6de7d7b3e6..fbd25f371f98 100644 --- a/tests/phpunit/unit/includes/title/TitleValueTest.php +++ b/tests/phpunit/unit/includes/title/TitleValueTest.php @@ -188,6 +188,37 @@ class TitleValueTest extends \MediaWikiUnitTestCase { $this->assertFalse( $title->hasFragment() ); } + public function provideCastPageToLinkTarget() { + yield [ new PageReferenceValue( NS_USER, 'Test', PageIdentity::LOCAL ) ]; + yield [ new PageReferenceValue( NS_USER, 'Test', 'acme' ) ]; + } + + /** + * @dataProvider provideNewFromPage + * + * @param PageReference $page + */ + public function testCastPageToLinkTarget( PageReference $page ) { + $title = TitleValue::castPageToLinkTarget( $page ); + + $this->assertSame( $page->getNamespace(), $title->getNamespace() ); + $this->assertSame( $page->getDBkey(), $title->getDBkey() ); + $this->assertSame( $page->getDBkey(), $title->getText() ); + $this->assertSame( '', $title->getFragment() ); + $this->assertSame( '', $title->getInterwiki() ); + $this->assertFalse( $title->isExternal() ); + $this->assertFalse( $title->hasFragment() ); + } + + public function testCastTitleToLinkTarget() { + $page = Title::makeTitle( NS_MAIN, 'Test' ); + $this->assertSame( $page, TitleValue::castPageToLinkTarget( $page ) ); + } + + public function testCastNullToLinkTarget() { + $this->assertNull( TitleValue::castPageToLinkTarget( null ) ); + } + public function getTextProvider() { return [ [ 'Foo', 'Foo' ], |