mediawiki-extensions-Scribunto/tests/phpunit/HooksTest.php
Kunal Mehta 4ccebcdf4b Simplify creating JSON pages in the Module namespace
Pages ending with a ".json" suffix in the Module namespace will use the
built-in JSON content model by default. Previously editors had to use
Special:ChangeContentModel to get a JSON page, which requires the
"editcontentmodel" userright that is not granted to a wide set of users
by default.

Bug: T144475
Change-Id: I1546fcad823a55a8c5a93177df8715844de1e87c
2022-09-22 19:48:52 -07:00

33 lines
1,009 B
PHP

<?php
use MediaWiki\Extension\Scribunto\Hooks as ScribuntoHooks;
class ScribuntoHooksTest extends PHPUnit\Framework\TestCase {
use MediaWikiCoversValidator;
public function provideContentHandlerDefaultModelFor() {
return [
[ 'Module:Foo', CONTENT_MODEL_SCRIBUNTO, true ],
[ 'Module:Foo/doc', null, true ],
[ 'Module:Foo/styles.css', 'sanitized-css', true, 'sanitized-css' ],
[ 'Module:Foo.json', CONTENT_MODEL_JSON, true ],
[ 'Module:Foo/subpage.json', CONTENT_MODEL_JSON, true ],
[ 'Main Page', null, true ],
];
}
/**
* @covers \MediaWiki\Extension\Scribunto\Hooks::contentHandlerDefaultModelFor
* @dataProvider provideContentHandlerDefaultModelFor
*/
public function testContentHandlerDefaultModelFor( $name, $expected,
$retVal, $before = null
) {
$title = Title::newFromText( $name );
$model = $before;
$ret = ScribuntoHooks::contentHandlerDefaultModelFor( $title, $model );
$this->assertSame( $retVal, $ret );
$this->assertSame( $expected, $model );
}
}