2019-01-12 19:03:01 +00:00
|
|
|
<?php
|
|
|
|
|
2022-07-30 22:43:58 +00:00
|
|
|
namespace MediaWiki\Extension\Scribunto\Tests;
|
2022-04-07 23:12:32 +00:00
|
|
|
|
2022-07-30 22:43:58 +00:00
|
|
|
use MediaWiki\Extension\Scribunto\Hooks;
|
2024-03-10 13:34:21 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2023-08-19 18:18:41 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2022-07-30 22:43:58 +00:00
|
|
|
use MediaWikiCoversValidator;
|
|
|
|
use Monolog\Test\TestCase;
|
|
|
|
|
2022-10-08 19:51:24 +00:00
|
|
|
/**
|
|
|
|
* @covers \MediaWiki\Extension\Scribunto\Hooks
|
|
|
|
*/
|
2022-07-30 22:43:58 +00:00
|
|
|
class HooksTest extends TestCase {
|
2019-07-22 00:49:41 +00:00
|
|
|
use MediaWikiCoversValidator;
|
2019-01-12 19:03:01 +00:00
|
|
|
|
2023-05-20 17:35:54 +00:00
|
|
|
public static function provideContentHandlerDefaultModelFor() {
|
2019-01-12 19:03:01 +00:00
|
|
|
return [
|
2018-10-18 13:37:23 +00:00
|
|
|
[ 'Module:Foo', CONTENT_MODEL_SCRIBUNTO, true ],
|
2019-01-12 19:03:01 +00:00
|
|
|
[ 'Module:Foo/doc', null, true ],
|
2018-10-18 13:37:23 +00:00
|
|
|
[ 'Module:Foo/styles.css', 'sanitized-css', true, 'sanitized-css' ],
|
2022-09-22 06:19:39 +00:00
|
|
|
[ 'Module:Foo.json', CONTENT_MODEL_JSON, true ],
|
|
|
|
[ 'Module:Foo/subpage.json', CONTENT_MODEL_JSON, true ],
|
2019-01-12 19:03:01 +00:00
|
|
|
[ 'Main Page', null, true ],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider provideContentHandlerDefaultModelFor
|
|
|
|
*/
|
2018-10-18 13:37:23 +00:00
|
|
|
public function testContentHandlerDefaultModelFor( $name, $expected,
|
|
|
|
$retVal, $before = null
|
|
|
|
) {
|
2019-01-12 19:03:01 +00:00
|
|
|
$title = Title::newFromText( $name );
|
2018-10-18 13:37:23 +00:00
|
|
|
$model = $before;
|
2024-03-10 13:34:21 +00:00
|
|
|
$ret = ( new Hooks(
|
|
|
|
MediaWikiServices::getInstance()->getMainConfig()
|
|
|
|
) )->onContentHandlerDefaultModelFor( $title, $model );
|
2019-01-12 19:03:01 +00:00
|
|
|
$this->assertSame( $retVal, $ret );
|
|
|
|
$this->assertSame( $expected, $model );
|
|
|
|
}
|
|
|
|
}
|