JsonContentHandler: Make sure makeEmptyContent() is valid JSON
authorKunal Mehta <legoktm@member.fsf.org>
Thu, 8 Sep 2016 06:18:47 +0000 (23:18 -0700)
committerKunal Mehta <legoktm@member.fsf.org>
Thu, 8 Sep 2016 19:52:56 +0000 (12:52 -0700)
The default TextContentHandler::makeEmptyContent() implementation
is an empty string, which is not valid JSON.

Change-Id: I8bc6ec647c5e8cd01c5cd63031525619c4ef44d0

includes/content/JsonContentHandler.php
tests/phpunit/includes/content/JsonContentHandlerTest.php [new file with mode: 0644]

index eb1c67d..edb21f6 100644 (file)
@@ -39,4 +39,9 @@ class JsonContentHandler extends CodeContentHandler {
        protected function getContentClass() {
                return JsonContent::class;
        }
+
+       public function makeEmptyContent() {
+               $class = $this->getContentClass();
+               return new $class( '{}' );
+       }
 }
diff --git a/tests/phpunit/includes/content/JsonContentHandlerTest.php b/tests/phpunit/includes/content/JsonContentHandlerTest.php
new file mode 100644 (file)
index 0000000..abfb673
--- /dev/null
@@ -0,0 +1,14 @@
+<?php
+
+class JsonContentHandlerTest extends MediaWikiTestCase {
+
+       /**
+        * @covers JsonContentHandler::makeEmptyContent
+        */
+       public function testMakeEmptyContent() {
+               $handler = new JsonContentHandler();
+               $content = $handler->makeEmptyContent();
+               $this->assertInstanceOf( JsonContent::class, $content );
+               $this->assertTrue( $content->isValid() );
+       }
+}