From bb8fff662a1745c88c68beac45749bfd25755187 Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Wed, 7 Sep 2016 23:18:47 -0700 Subject: [PATCH] JsonContentHandler: Make sure makeEmptyContent() is valid JSON The default TextContentHandler::makeEmptyContent() implementation is an empty string, which is not valid JSON. Change-Id: I8bc6ec647c5e8cd01c5cd63031525619c4ef44d0 --- includes/content/JsonContentHandler.php | 5 +++++ .../includes/content/JsonContentHandlerTest.php | 14 ++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 tests/phpunit/includes/content/JsonContentHandlerTest.php diff --git a/includes/content/JsonContentHandler.php b/includes/content/JsonContentHandler.php index eb1c67d5d2..edb21f682c 100644 --- a/includes/content/JsonContentHandler.php +++ b/includes/content/JsonContentHandler.php @@ -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 index 0000000000..abfb6733a5 --- /dev/null +++ b/tests/phpunit/includes/content/JsonContentHandlerTest.php @@ -0,0 +1,14 @@ +makeEmptyContent(); + $this->assertInstanceOf( JsonContent::class, $content ); + $this->assertTrue( $content->isValid() ); + } +} -- 2.20.1