From f86d2a63e4ac89dfc3438b018da853247fdadaee Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Sat, 10 Sep 2016 01:54:15 -0700 Subject: [PATCH] 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 --- .../structure/ContentHandlerSanityTest.php | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 tests/phpunit/structure/ContentHandlerSanityTest.php diff --git a/tests/phpunit/structure/ContentHandlerSanityTest.php b/tests/phpunit/structure/ContentHandlerSanityTest.php new file mode 100644 index 0000000000..98a0fbbfd5 --- /dev/null +++ b/tests/phpunit/structure/ContentHandlerSanityTest.php @@ -0,0 +1,53 @@ +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())" + ); + } +} -- 2.20.1