Introduce Special:RedirectExternal
[lhc/web/wiklou.git] / tests / phpunit / includes / specials / SpecialRedirectExternalTest.php
1 <?php
2
3 /**
4 * Test class for SpecialRedirectExternal class.
5 *
6 * @license GPL-2.0-or-later
7 */
8 class SpecialRedirectExternalTest extends MediaWikiTestCase {
9
10 /**
11 * @dataProvider provideDispatch
12 * @covers SpecialRedirectExternal::dispatch
13 * @covers SpecialRedirectExternal
14 * @param $url
15 * @param $expectedStatus
16 */
17 public function testDispatch( $url, $expectedStatus ) {
18 $page = new SpecialRedirectExternal();
19 $this->assertEquals( $expectedStatus, $page->dispatch( $url )->isGood() );
20 }
21
22 /**
23 * @throws HttpError
24 * @expectedException HttpError
25 * @expectedExceptionMessage asdf is not a valid URL
26 * @covers SpecialRedirectExternal::execute
27 */
28 public function testExecuteInvalidUrl() {
29 $page = new SpecialRedirectExternal();
30 $page->execute( 'asdf' );
31 }
32
33 /**
34 * @throws HttpError
35 * @covers SpecialRedirectExternal::execute
36 */
37 public function testValidUrl() {
38 $page = new SpecialRedirectExternal();
39 $this->assertTrue( $page->execute( 'https://www.mediawiki.org' ) );
40 }
41
42 public static function provideDispatch() {
43 return [
44 [ 'asdf', false ],
45 [ null, false ],
46 [ 'https://www.mediawiki.org?test=1', true ],
47 ];
48 }
49 }