ContentHandlerSanityTest.php 1.9 KB

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