From: Thiemo Mättig Date: Tue, 24 Jan 2017 17:30:33 +0000 (+0100) Subject: Add tests for OutputPage::addMeta and set{Index|Follow}Policy X-Git-Tag: 1.31.0-rc.0~4209^2~1 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=3ee7729f199c5e5ac93be84b3d71b4b6491a9809 Add tests for OutputPage::addMeta and set{Index|Follow}Policy This is a very basic test setup for the core functionality only. All the special cases in getHeadLinksArray are currently not tested. But this is a start. This is relevant for the changes made in Ie8fd697. Bug: T51859 Change-Id: I61e2da68ae0daea15fab2065a5dd63605d0b837d --- diff --git a/tests/phpunit/includes/OutputPageTest.php b/tests/phpunit/includes/OutputPageTest.php index 0e83006221..371731b257 100644 --- a/tests/phpunit/includes/OutputPageTest.php +++ b/tests/phpunit/includes/OutputPageTest.php @@ -12,6 +12,45 @@ class OutputPageTest extends MediaWikiTestCase { const SCREEN_MEDIA_QUERY = 'screen and (min-width: 982px)'; const SCREEN_ONLY_MEDIA_QUERY = 'only screen and (min-width: 982px)'; + /** + * @covers OutputPage::addMeta + * @covers OutputPage::getMetaTags + * @covers OutputPage::getHeadLinksArray + */ + public function testMetaTags() { + $outputPage = $this->newInstance(); + $outputPage->addMeta( 'http:expires', '0' ); + $outputPage->addMeta( 'keywords', 'first' ); + $outputPage->addMeta( 'keywords', 'second' ); + + $expected = [ + [ 'http:expires', '0' ], + [ 'keywords', 'first' ], + [ 'keywords', 'second' ], + ]; + $this->assertSame( $expected, $outputPage->getMetaTags() ); + + $links = $outputPage->getHeadLinksArray(); + $this->assertContains( '', $links ); + $this->assertContains( '', $links ); + $this->assertContains( '', $links ); + $this->assertArrayNotHasKey( 'meta-robots', $links ); + } + + /** + * @covers OutputPage::setIndexPolicy + * @covers OutputPage::setFollowPolicy + * @covers OutputPage::getHeadLinksArray + */ + public function testRobotsPolicies() { + $outputPage = $this->newInstance(); + $outputPage->setIndexPolicy( 'noindex' ); + $outputPage->setFollowPolicy( 'nofollow' ); + + $links = $outputPage->getHeadLinksArray(); + $this->assertContains( '', $links ); + } + /** * Tests a particular case of transformCssMedia, using the given input, globals, * expected return, and message @@ -374,6 +413,29 @@ class OutputPageTest extends MediaWikiTestCase { $this->assertEquals( [ 0 => 'Test2' ], $outputPage->getCategories( 'normal' ) ); $this->assertEquals( [ 0 => 'Test' ], $outputPage->getCategories( 'hidden' ) ); } + + /** + * @return OutputPage + */ + private function newInstance() { + $context = new RequestContext(); + + $context->setConfig( new HashConfig( [ + 'AppleTouchIcon' => false, + 'DisableLangConversion' => true, + 'EnableAPI' => false, + 'EnableCanonicalServerLink' => false, + 'Favicon' => false, + 'Feed' => false, + 'LanguageCode' => false, + 'ReferrerPolicy' => false, + 'RightsPage' => false, + 'RightsUrl' => false, + 'UniversalEditButton' => false, + ] ) ); + + return new OutputPage( $context ); + } } /**