MDL-62394 privacy: Make JSON export pretty
authorAndrew Nicols <andrew@nicols.co.uk>
Fri, 11 May 2018 03:15:13 +0000 (11:15 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Fri, 11 May 2018 06:12:10 +0000 (14:12 +0800)
privacy/classes/local/request/moodle_content_writer.php
privacy/tests/moodle_content_writer_test.php

index c212e27..2e82e6a 100644 (file)
@@ -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;
     }
index 7e20f64..7e81a3d 100644 (file)
@@ -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));