| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Skins\Vector\Tests\Integration; |
| 4 |
|
| 5 |
use MediaWiki\Context\RequestContext; |
| 6 |
use MediaWiki\Request\FauxRequest; |
| 7 |
use MediaWiki\Skins\Vector\ConfigHelper; |
| 8 |
use MediaWiki\Title\Title; |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
class ConfigHelperTest extends \MediaWikiIntegrationTestCase { |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
public function testShouldDisableEmpty() { |
| 18 |
$request = RequestContext::getMain()->getRequest(); |
| 19 |
|
| 20 |
$this->assertFalse( ConfigHelper::shouldDisable( [], $request ) ); |
| 21 |
} |
| 22 |
|
| 23 |
public static function provideShouldDisableMainPage() { |
| 24 |
return [ |
| 25 |
[ true ], [ false ] |
| 26 |
]; |
| 27 |
} |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
public function testShouldDisableMainPage( $disable ) { |
| 34 |
$config = [ 'exclude' => [ 'mainpage' => $disable ] ]; |
| 35 |
$request = RequestContext::getMain()->getRequest(); |
| 36 |
$title = Title::makeTitle( NS_MAIN, 'Main Page' ); |
| 37 |
|
| 38 |
$this->assertSame( ConfigHelper::shouldDisable( $config, $request, $title ), $disable ); |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
public function testShouldDisableMainPageWithQueryString() { |
| 45 |
$config = [ |
| 46 |
'exclude' => [ |
| 47 |
'mainpage' => false, |
| 48 |
'querystring' => [ |
| 49 |
'diff' => '*', |
| 50 |
] |
| 51 |
], |
| 52 |
]; |
| 53 |
$request = new FauxRequest( [ |
| 54 |
'title' => 'Main_Page', |
| 55 |
'diff' => '1223300368', |
| 56 |
'oldid' => '1212457119', |
| 57 |
] ); |
| 58 |
$title = Title::makeTitle( NS_MAIN, 'Main_Page' ); |
| 59 |
|
| 60 |
$this->assertSame( true, ConfigHelper::shouldDisable( $config, $request, $title ) ); |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
public function testShouldDisablePageTitlesRespectCase() { |
| 67 |
$config = [ 'exclude' => [ 'pagetitles' => [ 'Special:AbuseLog' ] ] ]; |
| 68 |
$request = RequestContext::getMain()->getRequest(); |
| 69 |
$title = Title::makeTitle( NS_MAIN, 'Special:AbuseLog' ); |
| 70 |
|
| 71 |
$this->assertTrue( ConfigHelper::shouldDisable( $config, $request, $title ), true ); |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
public function testShouldDisableMainPageImplicit() { |
| 78 |
$config = [ 'exclude' => [ 'pagetitles' => [ 'Main Page' ] ] ]; |
| 79 |
$request = RequestContext::getMain()->getRequest(); |
| 80 |
$title = Title::makeTitle( NS_MAIN, 'Main Page' ); |
| 81 |
|
| 82 |
$this->assertFalse( ConfigHelper::shouldDisable( $config, $request, $title ) ); |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
public function testShouldDisableInclude() { |
| 89 |
$config = [ 'exclude' => [ 'pagetitles' => [ 'test' ] ], 'include' => [ 'test' ] ]; |
| 90 |
$request = RequestContext::getMain()->getRequest(); |
| 91 |
$title = Title::makeTitle( NS_MAIN, 'test' ); |
| 92 |
|
| 93 |
$this->assertFalse( ConfigHelper::shouldDisable( $config, $request, $title ) ); |
| 94 |
} |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
public function testShouldDisablePageTitles() { |
| 100 |
$config = [ 'exclude' => [ 'pagetitles' => [ 'test' ] ] ]; |
| 101 |
$request = RequestContext::getMain()->getRequest(); |
| 102 |
$title = Title::makeTitle( NS_MAIN, 'test' ); |
| 103 |
|
| 104 |
$this->assertTrue( ConfigHelper::shouldDisable( $config, $request, $title ) ); |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
public function testShouldDisableNamespaces() { |
| 111 |
$config = [ 'exclude' => [ 'namespaces' => [ NS_SPECIAL ] ] ]; |
| 112 |
$request = RequestContext::getMain()->getRequest(); |
| 113 |
$title = Title::makeTitle( NS_SPECIAL, 'test' ); |
| 114 |
|
| 115 |
$this->assertTrue( ConfigHelper::shouldDisable( $config, $request, $title ) ); |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
public function testShouldDisableQueryString() { |
| 122 |
$config = [ 'exclude' => [ 'querystring' => [ 'action' => 'test' ] ] ]; |
| 123 |
$request = RequestContext::getMain()->getRequest(); |
| 124 |
$title = Title::makeTitle( NS_MAIN, 'test' ); |
| 125 |
|
| 126 |
$request->setVal( 'action', 'aaatestaaa' ); |
| 127 |
|
| 128 |
$this->assertTrue( ConfigHelper::shouldDisable( $config, $request, $title ) ); |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
public function testShouldDisableQueryStringRegex() { |
| 135 |
$config = [ 'exclude' => [ 'querystring' => [ 'action' => 'a+b.c' ] ] ]; |
| 136 |
$request = RequestContext::getMain()->getRequest(); |
| 137 |
$title = Title::makeTitle( NS_MAIN, 'test' ); |
| 138 |
|
| 139 |
$request->setVal( 'action', 'aaaabbc' ); |
| 140 |
|
| 141 |
$this->assertTrue( ConfigHelper::shouldDisable( $config, $request, $title ) ); |
| 142 |
} |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
public function testShouldDisableQueryStringWildcard() { |
| 148 |
$config = [ 'exclude' => [ 'querystring' => [ 'action' => '*' ] ] ]; |
| 149 |
$request = RequestContext::getMain()->getRequest(); |
| 150 |
$title = Title::makeTitle( NS_MAIN, 'test' ); |
| 151 |
|
| 152 |
$request->setVal( 'action', 'test' ); |
| 153 |
|
| 154 |
$this->assertTrue( ConfigHelper::shouldDisable( $config, $request, $title ) ); |
| 155 |
} |
| 156 |
} |