Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3745125
D2527.id6378.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D2527.id6378.diff
View Options
diff --git a/src/Output/XMLOutput.php b/src/Output/XMLOutput.php
new file mode 100644
--- /dev/null
+++ b/src/Output/XMLOutput.php
@@ -0,0 +1,54 @@
+<?php
+
+
+
+namespace Keruald\Reporting\Output;
+
+
+class XMLOutput extends Output {
+
+ public function render() : string {
+ $report = $this->report;
+ $send = [];
+ $send[] = '<?xml version="1.0" encoding="UTF-8" ?>';
+ $send[] = '<root>';
+ $send[] = ' <T1>'.$report->title.'</T1>';
+
+ foreach ($report->sections as $key => $section) {
+ $send[] =' <T2>'. $section->title.'</T2>';
+ foreach ($section->entries as $key => $entry) {
+
+ $send[] = ' <T3>'.$entry->title.'</T3>';
+
+ $text = explode("\n\n", $entry->text);
+
+ foreach ($text as $key => $value) {
+ $send[] = ' <p>'.$value.'</p>';
+ }
+ }
+ }
+
+ $send[] = '';
+ $send[] = ' <T1>Properties</T1>';
+ $send[] = '';
+ $send[] = ' <tableau>';
+
+ $properties = $report->properties;
+
+ foreach ($properties as $key => $value) {
+ $send[] = ' <ligne>';
+ $send[] = ' <colonne>'.$key.'</colonne>';
+ $send[] = ' <colonne>'.$value.'</colonne>';
+ $send[] = ' </ligne>';
+ }
+ $send[] = ' </tableau>';
+ $send[] = '';
+ $send[] = '</root>';
+ $send[] = '';
+
+
+
+ return implode("\n", $send);
+ }
+
+}
diff --git a/tests/Output/XMLOutputTest.php b/tests/Output/XMLOutputTest.php
new file mode 100644
--- /dev/null
+++ b/tests/Output/XMLOutputTest.php
@@ -0,0 +1,38 @@
+<?php
+
+namespace Keruald\Reporting\Tests\Output;
+
+
+use Keruald\Reporting\Output\XMLOutput;
+use Keruald\Reporting\Report;
+
+use Keruald\Reporting\Tests\WithSampleReport;
+use PHPUnit\Framework\TestCase;
+
+class XMLOutputTest extends TestCase {
+ use WithSampleReport;
+
+ ///
+ /// Initialization
+ //
+
+ public Report $report;
+
+ protected function setUp () : void {
+ $this->report = $this->buildSampleReport();
+ }
+
+ ///
+ /// Tests
+ //
+
+ public function testRender () : void {
+ $actual = XMLOutput::for($this->report)
+ ->render();
+
+ $expected = file_get_contents($this->getDataDir() . "/report.xml");
+
+ $this->assertEquals($expected, $actual);
+ }
+
+}
diff --git a/tests/data/report.xml b/tests/data/report.xml
new file mode 100644
--- /dev/null
+++ b/tests/data/report.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<root>
+ <T1>Sneakers</T1>
+ <T2>Air Max</T2>
+ <T3>Air Max 90</T3>
+ <p>One of the more icon color is the infrared.</p>
+ <T3>Air Max 95</T3>
+ <p>Launched in 1995, designed by Sergio Lozano.</p>
+ <T3>Air Max 97</T3>
+ <p>Well highlighted Air bubble.</p>
+ <p>Inspired by mountain bikes, while an urban legend quotes Japan bullet trains as inspiration.</p>
+ <T2>Other Nike Air</T2>
+ <T3>Introduction</T3>
+ <p>Because there are other sneakers than Air Max.</p>
+ <T3>Air Force 1</T3>
+ <p>« Air Force 1. Zéro fan, que des fanatiques. » -- LTA</p>
+ <T2>👟</T2>
+
+ <T1>Properties</T1>
+
+ <tableau>
+ <ligne>
+ <colonne>Date</colonne>
+ <colonne>9999-99-99</colonne>
+ </ligne>
+ <ligne>
+ <colonne>Topic</colonne>
+ <colonne>Urban culture</colonne>
+ </ligne>
+ </tableau>
+
+</root>
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 16, 12:22 (21 h, 29 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2247519
Default Alt Text
D2527.id6378.diff (3 KB)
Attached To
Mode
D2527: Output report in XML
Attached
Detach File
Event Timeline
Log In to Comment