Merge "Added release notes for 'ContentHandler::runLegacyHooks' removal"
[mediawiki.git] / tests / phpunit / structure / ContentHandlerSanityTest.php
blob98a0fbbfd5c41d171bae000ad6e1daa5cdad77fc
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
19 class ContentHandlerSanityTest extends MediaWikiTestCase {
21 public static function provideHandlers() {
22 $models = ContentHandler::getContentModels();
23 $handlers = [];
24 foreach ( $models as $model ) {
25 $handlers[] = [ ContentHandler::getForModelID( $model ) ];
28 return $handlers;
31 /**
32 * @dataProvider provideHandlers
33 * @param ContentHandler $handler
35 public function testMakeEmptyContent( ContentHandler $handler ) {
36 $content = $handler->makeEmptyContent();
37 $this->assertInstanceOf( Content::class, $content );
38 if ( $handler instanceof TextContentHandler ) {
39 // TextContentHandler::getContentClass() is protected, so bypass
40 // that restriction
41 $testingWrapper = TestingAccessWrapper::newFromObject( $handler );
42 $this->assertInstanceOf( $testingWrapper->getContentClass(), $content );
45 $handlerClass = get_class( $handler );
46 $contentClass = get_class( $content );
48 $this->assertTrue(
49 $content->isValid(),
50 "$handlerClass::makeEmptyContent() did not return a valid content ($contentClass::isValid())"