X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2FMediaWikiTest.php;h=e1962436ecd9fc10f1732a81813d8dfabc64defc;hb=6467ad900b4799c01bbbaceb38cb7fbe309f1c53;hp=3ca8d887e084e2fc603a7b0016a5dc3ac313d17b;hpb=37895d45e79e12ab403b05ff55789518bc389b7e;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/MediaWikiTest.php b/tests/phpunit/includes/MediaWikiTest.php index 3ca8d887e0..e1962436ec 100644 --- a/tests/phpunit/includes/MediaWikiTest.php +++ b/tests/phpunit/includes/MediaWikiTest.php @@ -1,183 +1,157 @@ object = new MediaWiki( $context ); - } - - protected function tearDown() { - $this->object = NULL; - } - - /** - * Test case insentiveness for get / set - */ - public function testSetGetValKeyInsentiveness() { - - // set with lower case key - $value = 'SomeValue'; - $this->object->setVal( 'foobar', $value ); - - $this->assertEquals( - $this->object->getVal( 'foobar' ), 'SomeValue', - 'lower case key set, getting lower case key' - ); - $this->assertEquals( - $this->object->getVal( 'FOOBAR' ), 'SomeValue', - 'lower case key set, getting upper case key' - ); - - // set with Mixed case key - $value = 'SomeValue2'; - $this->object->setVal( 'FooBar', $value ); - - $this->assertEquals( - $this->object->getVal( 'foobar' ), 'SomeValue2', - 'mixed case key set, getting lower case key' - ); - $this->assertEquals( - $this->object->getVal( 'FOOBAR' ), 'SomeValue2', - 'mixed case key set, getting upper case key' - ); - } - - public function testGetValWithDefault() { - $this->assertEmpty( - $this->object->getVal( 'NonExistent' ), - 'Non existent key return empty string' - ); - $this->assertEquals( - $this->object->getVal( 'NonExistent2', 'Default Value' ), 'Default Value', - 'Non existent key with default given, should give default' + parent::setUp(); + + $this->setMwGlobals( array( + 'wgServer' => 'http://example.org', + 'wgScriptPath' => '/w', + 'wgScript' => '/w/index.php', + 'wgArticlePath' => '/wiki/$1', + 'wgActionPaths' => array(), + ) ); + } + + public static function provideTryNormaliseRedirect() { + return array( + array( + // View: Canonical + 'url' => 'http://example.org/wiki/Foo_Bar', + 'query' => array(), + 'title' => 'Foo_Bar', + 'redirect' => false, + ), + array( + // View: Escaped title + 'url' => 'http://example.org/wiki/Foo%20Bar', + 'query' => array(), + 'title' => 'Foo_Bar', + 'redirect' => 'http://example.org/wiki/Foo_Bar', + ), + array( + // View: Script path + 'url' => 'http://example.org/w/index.php?title=Foo_Bar', + 'query' => array( 'title' => 'Foo_Bar' ), + 'title' => 'Foo_Bar', + 'redirect' => 'http://example.org/wiki/Foo_Bar', + ), + array( + // View: Script path with implicit title from page id + 'url' => 'http://example.org/w/index.php?curid=123', + 'query' => array( 'curid' => '123' ), + 'title' => 'Foo_Bar', + 'redirect' => false, + ), + array( + // View: Script path with implicit title from revision id + 'url' => 'http://example.org/w/index.php?oldid=123', + 'query' => array( 'oldid' => '123' ), + 'title' => 'Foo_Bar', + 'redirect' => false, + ), + array( + // View: Script path without title + 'url' => 'http://example.org/w/index.php', + 'query' => array(), + 'title' => 'Main_Page', + 'redirect' => 'http://example.org/wiki/Main_Page', + ), + array( + // View: Script path with empty title + 'url' => 'http://example.org/w/index.php?title=', + 'query' => array( 'title' => '' ), + 'title' => 'Main_Page', + 'redirect' => 'http://example.org/wiki/Main_Page', + ), + array( + // View: Index with escaped title + 'url' => 'http://example.org/w/index.php?title=Foo%20Bar', + 'query' => array( 'title' => 'Foo Bar' ), + 'title' => 'Foo_Bar', + 'redirect' => 'http://example.org/wiki/Foo_Bar', + ), + array( + // View: Script path with escaped title + 'url' => 'http://example.org/w/?title=Foo_Bar', + 'query' => array( 'title' => 'Foo_Bar' ), + 'title' => 'Foo_Bar', + 'redirect' => 'http://example.org/wiki/Foo_Bar', + ), + array( + // View: Root path with escaped title + 'url' => 'http://example.org/?title=Foo_Bar', + 'query' => array( 'title' => 'Foo_Bar' ), + 'title' => 'Foo_Bar', + 'redirect' => 'http://example.org/wiki/Foo_Bar', + ), + array( + // View: Canonical with redundant query + 'url' => 'http://example.org/wiki/Foo_Bar?action=view', + 'query' => array( 'action' => 'view' ), + 'title' => 'Foo_Bar', + 'redirect' => 'http://example.org/wiki/Foo_Bar', + ), + array( + // Edit: Canonical view url with action query + 'url' => 'http://example.org/wiki/Foo_Bar?action=edit', + 'query' => array( 'action' => 'edit' ), + 'title' => 'Foo_Bar', + 'redirect' => false, + ), + array( + // View: Index with action query + 'url' => 'http://example.org/w/index.php?title=Foo_Bar&action=view', + 'query' => array( 'title' => 'Foo_Bar', 'action' => 'view' ), + 'title' => 'Foo_Bar', + 'redirect' => 'http://example.org/wiki/Foo_Bar', + ), + array( + // Edit: Index with action query + 'url' => 'http://example.org/w/index.php?title=Foo_Bar&action=edit', + 'query' => array( 'title' => 'Foo_Bar', 'action' => 'edit' ), + 'title' => 'Foo_Bar', + 'redirect' => false, + ), ); } /** - * @todo Implement testPerformRequestForTitle(). + * @dataProvider provideTryNormaliseRedirect + * @covers MediaWiki::tryNormaliseRedirect */ - public function testPerformRequestForTitle() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } + public function testTryNormaliseRedirect( $url, $query, $title, $expectedRedirect = false ) { + // Set SERVER because interpolateTitle() doesn't use getRequestURL(), + // whereas tryNormaliseRedirect does(). + $_SERVER['REQUEST_URI'] = $url; - /** - * @todo Implement testCheckMaxLag(). - */ - public function testCheckMaxLag() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } + $req = new FauxRequest( $query ); + $req->setRequestURL( $url ); + // This adds a virtual 'title' query parameter. Normally called from Setup.php + $req->interpolateTitle(); - /** - * @todo Implement testCheckInitialQueries(). - */ - public function testCheckInitialQueries() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } + $titleObj = Title::newFromText( $title ); - /** - * @todo Implement testPreliminaryChecks(). - */ - public function testPreliminaryChecks() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } + // Set global context since some involved code paths don't yet have context + $context = RequestContext::getMain(); + $context->setRequest( $req ); + $context->setTitle( $titleObj ); - /** - * @todo Implement testHandleSpecialCases(). - */ - public function testHandleSpecialCases() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } + $mw = new MediaWiki( $context ); - /** - * @todo Implement testArticleFromTitle(). - */ - public function testArticleFromTitle() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } + $method = new ReflectionMethod( $mw, 'tryNormaliseRedirect' ); + $method->setAccessible( true ); + $ret = $method->invoke( $mw, $titleObj ); - /** - * @todo Implement testGetAction(). - */ - public function testGetAction() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @todo Implement testInitializeArticle(). - */ - public function testInitializeArticle() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @todo Implement testFinalCleanup(). - */ - public function testFinalCleanup() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @todo Implement testDoJobs(). - */ - public function testDoJobs() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @todo Implement testRestInPeace(). - */ - public function testRestInPeace() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' + $this->assertEquals( + $expectedRedirect !== false, + $ret, + 'Return true only when redirecting' ); - } - /** - * @todo Implement testPerformAction(). - */ - public function testPerformAction() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' + $this->assertEquals( + $expectedRedirect ?: '', + $context->getOutput()->getRedirect() ); } }