コード例 #1
0
 /**
  * @dataProvider provideTryNormaliseRedirect
  * @covers MediaWiki::tryNormaliseRedirect
  */
 public function testTryNormaliseRedirect($url, $query, $title, $expectedRedirect = false)
 {
     // Set SERVER because interpolateTitle() doesn't use getRequestURL(),
     // whereas tryNormaliseRedirect does().
     $_SERVER['REQUEST_URI'] = $url;
     $req = new FauxRequest($query);
     $req->setRequestURL($url);
     // This adds a virtual 'title' query parameter. Normally called from Setup.php
     $req->interpolateTitle();
     $titleObj = Title::newFromText($title);
     // Set global context since some involved code paths don't yet have context
     $context = RequestContext::getMain();
     $context->setRequest($req);
     $context->setTitle($titleObj);
     $mw = new MediaWiki($context);
     $method = new ReflectionMethod($mw, 'tryNormaliseRedirect');
     $method->setAccessible(true);
     $ret = $method->invoke($mw, $titleObj);
     $this->assertEquals($expectedRedirect !== false, $ret, 'Return true only when redirecting');
     $this->assertEquals($expectedRedirect ?: '', $context->getOutput()->getRedirect());
 }