2016-09-10 08:54:15 +00:00
|
|
|
<?php
|
2017-04-19 19:37:35 +00:00
|
|
|
|
2020-01-18 20:25:04 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2017-04-19 19:37:35 +00:00
|
|
|
use Wikimedia\TestingAccessWrapper;
|
|
|
|
|
|
2016-09-10 08:54:15 +00:00
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
|
*/
|
|
|
|
|
|
2020-06-30 15:09:24 +00:00
|
|
|
class ContentHandlerSanityTest extends MediaWikiIntegrationTestCase {
|
2016-09-10 08:54:15 +00:00
|
|
|
|
|
|
|
|
public static function provideHandlers() {
|
|
|
|
|
$models = ContentHandler::getContentModels();
|
2020-01-18 20:25:04 +00:00
|
|
|
$contentHandlerFactory = MediaWikiServices::getInstance()->getContentHandlerFactory();
|
2016-09-10 08:54:15 +00:00
|
|
|
$handlers = [];
|
|
|
|
|
foreach ( $models as $model ) {
|
2020-01-18 20:25:04 +00:00
|
|
|
$handlers[] = [
|
|
|
|
|
$contentHandlerFactory->getContentHandler( $model )
|
|
|
|
|
];
|
2016-09-10 08:54:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $handlers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideHandlers
|
|
|
|
|
*/
|
|
|
|
|
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 );
|
|
|
|
|
|
2017-02-15 23:15:41 +00:00
|
|
|
if ( $handler->supportsDirectEditing() ) {
|
|
|
|
|
$this->assertTrue(
|
|
|
|
|
$content->isValid(),
|
|
|
|
|
"$handlerClass::makeEmptyContent() did not return a valid content ($contentClass::isValid())"
|
|
|
|
|
);
|
|
|
|
|
}
|
2016-09-10 08:54:15 +00:00
|
|
|
}
|
2017-02-15 23:15:41 +00:00
|
|
|
|
2016-09-10 08:54:15 +00:00
|
|
|
}
|