wiki.techinc.nl/tests/phpunit/structure/ContentHandlerSanityTest.php
Thiemo Kreuz 2f66b3754f tests: Remove @param docs from test code that just repeat the signature
These are not only 100% identical to the actual code, but also:
* It's error-prone. Some are already wrong.
* These test…() functions are not meant to be called from
  anywhere. What is the target audience for this documentation?
* There is a @dataProvider. What such @param tags actually do is
  document the provider, but in an odd place. Just looking at
  the provider should give the same information.
* The MediaWiki CodeSniffer allows to skip @param when there is
  a @dataProvider, for the reasone listed.

Change-Id: I0f6f42f9a15776df944a0da48a50f9d5a2fb6349
2021-01-21 03:41:23 +00:00

62 lines
2 KiB
PHP

<?php
use MediaWiki\MediaWikiServices;
use Wikimedia\TestingAccessWrapper;
/**
* 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 MediaWikiIntegrationTestCase {
public static function provideHandlers() {
$models = ContentHandler::getContentModels();
$contentHandlerFactory = MediaWikiServices::getInstance()->getContentHandlerFactory();
$handlers = [];
foreach ( $models as $model ) {
$handlers[] = [
$contentHandlerFactory->getContentHandler( $model )
];
}
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 );
if ( $handler->supportsDirectEditing() ) {
$this->assertTrue(
$content->isValid(),
"$handlerClass::makeEmptyContent() did not return a valid content ($contentClass::isValid())"
);
}
}
}