wiki.techinc.nl/tests/phpunit/structure/ContentHandlerSanityTest.php
Kunal Mehta f86d2a63e4 Add structure test for ContentHandler::makeEmptyContent()
This adds a structure test that verifies all registered ContentHandlers
will return a valid content object (as determined by
Content::isValid()), when makeEmptyContent() is called. Additionally, if
the handler extends TextContentHandler, it will verify it is an instance
of TextContentHandler::getContentClass().

This is a structure test so it is run for content handlers created by
extensions as well.

Change-Id: Idd67d824f2f7cc1819b1d8b186be058e63c4513d
2016-09-10 01:55:18 -07:00

53 lines
1.8 KiB
PHP

<?php
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*/
class ContentHandlerSanityTest extends MediaWikiTestCase {
public static function provideHandlers() {
$models = ContentHandler::getContentModels();
$handlers = [];
foreach ( $models as $model ) {
$handlers[] = [ ContentHandler::getForModelID( $model ) ];
}
return $handlers;
}
/**
* @dataProvider provideHandlers
* @param ContentHandler $handler
*/
public function testMakeEmptyContent( ContentHandler $handler ) {
$content = $handler->makeEmptyContent();
$this->assertInstanceOf( Content::class, $content );
if ( $handler instanceof TextContentHandler ) {
// TextContentHandler::getContentClass() is protected, so bypass
// that restriction
$testingWrapper = TestingAccessWrapper::newFromObject( $handler );
$this->assertInstanceOf( $testingWrapper->getContentClass(), $content );
}
$handlerClass = get_class( $handler );
$contentClass = get_class( $content );
$this->assertTrue(
$content->isValid(),
"$handlerClass::makeEmptyContent() did not return a valid content ($contentClass::isValid())"
);
}
}