From 20f3b33b247691c3bf217f1c6eb5b0fe48a15d3a Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Fri, 11 May 2018 11:15:13 +0800 Subject: [PATCH] MDL-62394 privacy: Make JSON export pretty --- privacy/classes/local/request/moodle_content_writer.php | 8 ++++---- privacy/tests/moodle_content_writer_test.php | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/privacy/classes/local/request/moodle_content_writer.php b/privacy/classes/local/request/moodle_content_writer.php index c212e271df8..2e82e6a4f42 100644 --- a/privacy/classes/local/request/moodle_content_writer.php +++ b/privacy/classes/local/request/moodle_content_writer.php @@ -84,7 +84,7 @@ class moodle_content_writer implements content_writer { public function export_data(array $subcontext, \stdClass $data) : content_writer { $path = $this->get_path($subcontext, 'data.json'); - $this->write_data($path, json_encode($data, JSON_UNESCAPED_UNICODE)); + $this->write_data($path, json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)); return $this; } @@ -115,7 +115,7 @@ class moodle_content_writer implements content_writer { ]; $path = $this->get_path($subcontext, 'metadata.json'); - $this->write_data($path, json_encode($data, JSON_UNESCAPED_UNICODE)); + $this->write_data($path, json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)); return $this; } @@ -131,7 +131,7 @@ class moodle_content_writer implements content_writer { public function export_related_data(array $subcontext, $name, $data) : content_writer { $path = $this->get_path($subcontext, "{$name}.json"); - $this->write_data($path, json_encode($data, JSON_UNESCAPED_UNICODE)); + $this->write_data($path, json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)); return $this; } @@ -230,7 +230,7 @@ class moodle_content_writer implements content_writer { 'value' => $value, 'description' => $description, ]; - $this->write_data($path, json_encode($data, JSON_UNESCAPED_UNICODE)); + $this->write_data($path, json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)); return $this; } diff --git a/privacy/tests/moodle_content_writer_test.php b/privacy/tests/moodle_content_writer_test.php index 7e20f64879b..7e81a3d2cfa 100644 --- a/privacy/tests/moodle_content_writer_test.php +++ b/privacy/tests/moodle_content_writer_test.php @@ -897,7 +897,7 @@ class moodle_content_writer_test extends advanced_testcase { $contextpath = $this->get_context_path($context, $subcontext, 'metadata.json'); $json = $fileroot->getChild($contextpath)->getContent(); - $this->assertRegExp("/$text.*$text.*$text/", $json); + $this->assertRegExp("/$text.*$text.*$text/is", $json); $expanded = json_decode($json); $this->assertTrue(isset($expanded->$text)); @@ -950,7 +950,7 @@ class moodle_content_writer_test extends advanced_testcase { $contextpath = $this->get_context_path($context, [get_string('userpreferences')], "{$component}.json"); $json = $fileroot->getChild($contextpath)->getContent(); - $this->assertRegExp("/$text.*$text.*$text/", $json); + $this->assertRegExp("/$text.*$text.*$text/is", $json); $expanded = json_decode($json); $this->assertTrue(isset($expanded->$text)); @@ -1053,7 +1053,7 @@ class moodle_content_writer_test extends advanced_testcase { $this->assertEquals($expectedpath, $contextpath); $json = $fileroot->getChild($contextpath)->getContent(); - $this->assertRegExp("/$text.*$text.*$text/", $json); + $this->assertRegExp("/$text.*$text.*$text/is", $json); $expanded = json_decode($json); $this->assertTrue(isset($expanded->$text)); @@ -1091,7 +1091,7 @@ class moodle_content_writer_test extends advanced_testcase { $this->assertEquals($expectedpath, $contextpath); $json = $fileroot->getChild($contextpath)->getContent(); - $this->assertRegExp("/$text.*$text.*$text/", $json); + $this->assertRegExp("/$text.*$text.*$text/is", $json); $expanded = json_decode($json); $this->assertTrue(isset($expanded->$text)); -- 2.11.4.GIT