Page MenuHomeDevCentral

D2538.id6403.diff
No OneTemporary

D2538.id6403.diff

diff --git a/src/Output/HTMLOutput.php b/src/Output/HTMLOutput.php
--- a/src/Output/HTMLOutput.php
+++ b/src/Output/HTMLOutput.php
@@ -15,48 +15,58 @@
public function render () : string {
$send = [];
- $title = $this->report->title;
- $send[] =
- '<h1 id="' . $this->makeId($title) . '">' . self::encode($title)
- . '</h1>';
+ if ($this->report->sections || $this->report->properties
+ || $this->report->title) {
- foreach ($this->report->sections as $section) {
- $title = $section->title;
+ $title = $this->report->title;
$send[] =
- '<h2 id="' . $this->makeId($title) . '">' .
- self::encode($title) . '</h2>';
- foreach ($section->entries as $entry) {
- $title = $entry->title;
- $send[] = '<h3 id="' . $this->makeId($title) . '">' .
- self::encode($title) . '</h3>';
+ '<h1 id="' . $this->makeId($title) . '">' . self::encode($title)
+ . '</h1>';
+ if ($this->report->sections) {
+ foreach ($this->report->sections as $section) {
+ $title = $section->title;
+ $send[] =
+ '<h2 id="' . $this->makeId($title) . '">' .
+ self::encode($title) . '</h2>';
+ foreach ($section->entries as $entry) {
+ $title = $entry->title;
+ $send[] = '<h3 id="' . $this->makeId($title) . '">' .
+ self::encode($title) . '</h3>';
- $text = explode("\n\n", $entry->text);
+ $text = explode("\n\n", $entry->text);
- foreach ($text as $value) {
- $send[] = '<p>' . self::encode($value) . '</p>';
+ foreach ($text as $value) {
+ $send[] = '<p>' . self::encode($value) . '</p>';
+ }
+ }
+ }
+ if ($this->report->properties && $this->report->sections) {
+ $send[] = '<hr>';
}
}
- }
- $send[] = '<hr>';
-
- $send[] = '<h2 id="report-properties">Report properties</h2>';
- $send[] = '<table>';
- $send[] = str_repeat(" ", 4) . '<tbody>';
+ if ($this->report->properties) {
+ $send[] = '<h2 id="report-properties">Report properties</h2>';
+ $send[] = '<table>';
+ $send[] = str_repeat(" ", 4) . '<tbody>';
- $properties = $this->report->properties;
+ $properties = $this->report->properties;
- foreach ($properties as $key => $value) {
- $send[] = str_repeat(" ", 4) . '<tr>';
- $send[] = str_repeat(" ", 8) .
+ foreach ($properties as $key => $value) {
+ $send[] = str_repeat(" ", 4) . '<tr>';
+ $send[] = str_repeat(" ", 8) .
- '<th>' . self::encode($key) . '</th>';
- $send[] = str_repeat(" ", 8) .
- '<td>' . self::encode($value) . '</td>';
+ '<th>' . self::encode($key) . '</th>';
+ $send[] = str_repeat(" ", 8) .
+ '<td>' . self::encode($value) . '</td>';
- $send[] = str_repeat(" ", 4) . '</tr>';
+ $send[] = str_repeat(" ", 4) . '</tr>';
+ }
+ $send[] = str_repeat(" ", 4) . '</tbody>';
+ $send[] = '</table>';
+ }
+ } else {
+ $send[] = "<h1 id=\"void-report\">Void report</h1>";
}
- $send[] = str_repeat(" ", 4) . '</tbody>';
- $send[] = '</table>';
$send[] = '';
return implode("\n", $send);
diff --git a/src/Output/MarkdownOutput.php b/src/Output/MarkdownOutput.php
--- a/src/Output/MarkdownOutput.php
+++ b/src/Output/MarkdownOutput.php
@@ -8,48 +8,61 @@
$send = [];
- $send[] = '# ' . $this->report->title;
- $send[] = '';
- foreach ($this->report->sections as $section) {
- $send[] = '## ' . $section->title;
+ if ($this->report->sections || $this->report->properties
+ || $this->report->title) {
+
+ $send[] = '# ' . $this->report->title;
$send[] = '';
- foreach ($section->entries as $entry) {
+ if ($this->report->sections) {
+ foreach ($this->report->sections as $section) {
+ $send[] = '## ' . $section->title;
+ $send[] = '';
+ foreach ($section->entries as $entry) {
- $send[] = '### ' . $entry->title;
- $send[] = '';
- $send[] = $entry->text;
+ $send[] = '### ' . $entry->title;
+ $send[] = '';
+ $send[] = $entry->text;
+ $send[] = '';
+ }
+ }
+ }
+ if ($this->report->properties && $this->report->sections) {
+ $send[] = '---';
$send[] = '';
}
- }
+ if ($this->report->properties) {
+ $properties = $this->report->properties;
+ $propertyMaxLength = 0;
+ $maxValue = 0;
+ foreach ($properties as $key => $value) {
+ $propertyMaxLength = max($propertyMaxLength, strlen($key));
+ $maxValue = max($maxValue, strlen($value));
+ }
+ if ($propertyMaxLength < 8) {
+ $propertyMaxLength = 8;
+ }
- $send[] = '---';
- $send[] = '';
- $properties = $this->report->properties;
- $propertyMaxLength = 0;
- $maxValue = 0;
- foreach ($properties as $key => $value) {
- $propertyMaxLength = max($propertyMaxLength, strlen($key));
- $maxValue = max($maxValue, strlen($value));
- }
- if ($propertyMaxLength < 8) {
- $propertyMaxLength = 8;
- }
+ $send[] =
+ '| Property' . str_repeat(' ', $propertyMaxLength - 8)
+ . ' | '
+ . str_repeat(' ', $maxValue) . ' |';
- $send[] = '| Property' . str_repeat(' ', $propertyMaxLength - 8) . ' | '
- . str_repeat(' ', $maxValue) . ' |';
+ $send[] = '|' . str_repeat('-', $propertyMaxLength + 2) . '|'
+ . str_repeat('-', $maxValue + 2) . '|';
- $send[] = '|' . str_repeat('-', $propertyMaxLength + 2) . '|'
- . str_repeat('-', $maxValue + 2) . '|';
+ foreach ($properties as $key => $value) {
+ $send[] =
+ '| ' . $key . str_repeat(' ',
+ $propertyMaxLength - strlen($key))
+ . ' | '
+ . $value . str_repeat(' ', $maxValue - strlen($value))
+ . ' |';
+ }
- foreach ($properties as $key => $value) {
- $send[] =
- '| ' . $key . str_repeat(' ', $propertyMaxLength - strlen($key))
- . ' | '
- . $value . str_repeat(' ', $maxValue - strlen($value)) . ' |';
+ $send[] = '';
+ }
}
- $send[] = '';
-
return implode("\n", $send);
}
}
diff --git a/src/Output/XMLOutput.php b/src/Output/XMLOutput.php
--- a/src/Output/XMLOutput.php
+++ b/src/Output/XMLOutput.php
@@ -12,57 +12,71 @@
xmlwriter_set_indent($document, true);
xmlwriter_set_indent_string($document, ' ');
-
xmlwriter_start_document($document, '1.0', 'UTF-8');
xmlwriter_start_element($document, 'report');
xmlwriter_start_attribute($document, 'title');
- xmlwriter_text($document, $this->report->title);
- xmlwriter_end_attribute($document);
- foreach ($this->report->sections as $section) {
- xmlwriter_start_element($document, 'section');
- xmlwriter_start_attribute($document, 'title');
- xmlwriter_text($document, $section->title);
+ if ($this->report->sections || $this->report->properties
+ || $this->report->title) {
+
+ xmlwriter_text($document, $this->report->title);
xmlwriter_end_attribute($document);
- foreach ($section->entries as $entry) {
- xmlwriter_start_element($document, 'entry');
+ if ($this->report->sections) {
+ foreach ($this->report->sections as $section) {
+ xmlwriter_start_element($document, 'section');
+ xmlwriter_start_attribute($document, 'title');
+ xmlwriter_text($document, $section->title);
+ xmlwriter_end_attribute($document);
- xmlwriter_start_attribute($document, 'title');
- xmlwriter_text($document, $entry->title);
- xmlwriter_end_attribute($document);
+ foreach ($section->entries as $entry) {
+ xmlwriter_start_element($document, 'entry');
- xmlwriter_start_element($document, 'text');
- xmlwriter_text($document, $entry->text);
- xmlwriter_end_element($document);
+ xmlwriter_start_attribute($document, 'title');
+ xmlwriter_text($document, $entry->title);
+ xmlwriter_end_attribute($document);
- xmlwriter_end_element($document);
+ xmlwriter_start_element($document, 'text');
+ xmlwriter_text($document, $entry->text);
+ xmlwriter_end_element($document);
+
+ xmlwriter_end_element($document);
+ }
+ xmlwriter_end_element($document); // section
+ }
}
- xmlwriter_end_element($document); // section
- }
- xmlwriter_start_element($document, 'data');
- xmlwriter_start_attribute($document, 'title');
- xmlwriter_text($document, "Properties");
- xmlwriter_end_attribute($document);
+ if ($this->report->properties) {
- foreach ($this->report->properties as $key => $value) {
- xmlwriter_start_element($document, 'entry');
+ xmlwriter_start_element($document, 'data');
+ xmlwriter_start_attribute($document, 'title');
+ xmlwriter_text($document, "Properties");
+ xmlwriter_end_attribute($document);
+
+ foreach ($this->report->properties as $key => $value) {
+ xmlwriter_start_element($document, 'entry');
- xmlwriter_start_element($document, 'key');
- xmlwriter_text($document, $key);
- xmlwriter_end_element($document);
+ xmlwriter_start_element($document, 'key');
+ xmlwriter_text($document, $key);
+ xmlwriter_end_element($document);
- xmlwriter_start_element($document, 'value');
- xmlwriter_text($document, $value);
- xmlwriter_end_element($document);
+ xmlwriter_start_element($document, 'value');
+ xmlwriter_text($document, $value);
+ xmlwriter_end_element($document);
- xmlwriter_end_element($document);
+ xmlwriter_end_element($document);
+ }
+ xmlwriter_end_element($document); // data
+
+ // report
+ }
+ } else {
+ xmlwriter_text($document, "Void report");
+ xmlwriter_end_attribute($document);
}
- xmlwriter_end_element($document); // data
+ xmlwriter_end_element($document);
- xmlwriter_end_element($document); // report
xmlwriter_end_document($document);
return xmlwriter_output_memory($document);
diff --git a/tests/Output/HTMLOutputTest.php b/tests/Output/HTMLOutputTest.php
--- a/tests/Output/HTMLOutputTest.php
+++ b/tests/Output/HTMLOutputTest.php
@@ -12,26 +12,19 @@
use WithSampleReport;
- ///
- /// Initialization
- //
-
- public Report $report;
-
- protected function setUp () : void {
- $this->report = $this->buildSampleReport();
- }
-
///
/// Tests
//
- public function testRender () : void {
- $actual = HTMLOutput::for($this->report)
- ->render();
+ /**
+ * @dataProvider provideSampleReports
+ */
+ public function testRender (string $name, Report $report) : void {
+ $actual = HTMLOutput::for($report)->render();
- $expected = file_get_contents($this->getDataDir() . "/report.html");
+ $expected = file_get_contents($this->getDataDir() . "/$name.html");
$this->assertEquals($expected, $actual);
}
+
}
diff --git a/tests/Output/MarkdownOutputTest.php b/tests/Output/MarkdownOutputTest.php
--- a/tests/Output/MarkdownOutputTest.php
+++ b/tests/Output/MarkdownOutputTest.php
@@ -12,25 +12,17 @@
use WithSampleReport;
- ///
- /// Initialization
- //
-
- public Report $report;
-
- protected function setUp () : void {
- $this->report = $this->buildSampleReport();
- }
-
///
/// Tests
//
- public function testRender () : void {
- $actual = MarkdownOutput::for($this->report)
- ->render();
+ /**
+ * @dataProvider provideSampleReports
+ */
+ public function testRender (string $name, Report $report) : void {
+ $actual = MarkdownOutput::for($report)->render();
- $expected = file_get_contents($this->getDataDir() . "/report.md");
+ $expected = file_get_contents($this->getDataDir() . "/$name.md");
$this->assertEquals($expected, $actual);
}
diff --git a/tests/Output/XMLOutputTest.php b/tests/Output/XMLOutputTest.php
--- a/tests/Output/XMLOutputTest.php
+++ b/tests/Output/XMLOutputTest.php
@@ -13,25 +13,17 @@
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();
+ /**
+ * @dataProvider provideSampleReports
+ */
+ public function testRender (string $name, Report $report) : void {
+ $actual = XMLOutput::for($report)->render();
- $expected = file_get_contents($this->getDataDir() . "/report.xml");
+ $expected = file_get_contents($this->getDataDir() . "/$name.xml");
$this->assertEquals($expected, $actual);
}
diff --git a/tests/WithSampleReport.php b/tests/WithSampleReport.php
--- a/tests/WithSampleReport.php
+++ b/tests/WithSampleReport.php
@@ -12,6 +12,19 @@
return __DIR__ . "/data";
}
+ public function provideSampleReports () : iterable {
+ yield ["report", $this->buildSampleReport()];
+ yield ["empty", new Report("Void report")];
+
+ $report = $this->buildSampleReport();
+ $report->properties = [];
+ yield ["no_metadata", $report];
+
+ $report = $this->buildSampleReport();
+ $report->sections = [];
+ yield ["only_metadata", $report];
+ }
+
public function buildSampleReport () : Report {
$report = new Report("Sneakers");
diff --git a/tests/data/empty.html b/tests/data/empty.html
new file mode 100644
--- /dev/null
+++ b/tests/data/empty.html
@@ -0,0 +1 @@
+<h1 id="void-report">Void report</h1>
diff --git a/tests/data/empty.md b/tests/data/empty.md
new file mode 100644
--- /dev/null
+++ b/tests/data/empty.md
@@ -0,0 +1 @@
+# Void report
diff --git a/tests/data/empty.xml b/tests/data/empty.xml
new file mode 100644
--- /dev/null
+++ b/tests/data/empty.xml
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<report title="Void report"/>
diff --git a/tests/data/no_metadata.html b/tests/data/no_metadata.html
new file mode 100644
--- /dev/null
+++ b/tests/data/no_metadata.html
@@ -0,0 +1,15 @@
+<h1 id="sneakers">Sneakers</h1>
+<h2 id="air-max">Air Max</h2>
+<h3 id="air-max-90">Air Max 90</h3>
+<p>One of the more icon color is the infrared.</p>
+<h3 id="air-max-95">Air Max 95</h3>
+<p>Launched in 1995, designed by Sergio Lozano.</p>
+<h3 id="air-max-97">Air Max 97</h3>
+<p>Well highlighted Air bubble.</p>
+<p>Inspired by mountain bikes, while an urban legend quotes Japan bullet trains as inspiration.</p>
+<h2 id="other-nike-air">Other Nike Air</h2>
+<h3 id="introduction">Introduction</h3>
+<p>Because there are other sneakers than Air Max.</p>
+<h3 id="air-force-1">Air Force 1</h3>
+<p>« Air Force 1. Zéro fan, que des fanatiques. » -- LTA</p>
+<h2 id="%F0%9F%91%9F">👟</h2>
diff --git a/tests/data/no_metadata.md b/tests/data/no_metadata.md
new file mode 100644
--- /dev/null
+++ b/tests/data/no_metadata.md
@@ -0,0 +1,29 @@
+# Sneakers
+
+## Air Max
+
+### Air Max 90
+
+One of the more icon color is the infrared.
+
+### Air Max 95
+
+Launched in 1995, designed by Sergio Lozano.
+
+### Air Max 97
+
+Well highlighted Air bubble.
+
+Inspired by mountain bikes, while an urban legend quotes Japan bullet trains as inspiration.
+
+## Other Nike Air
+
+### Introduction
+
+Because there are other sneakers than Air Max.
+
+### Air Force 1
+
+« Air Force 1. Zéro fan, que des fanatiques. » -- LTA
+
+## 👟
diff --git a/tests/data/no_metadata.xml b/tests/data/no_metadata.xml
new file mode 100644
--- /dev/null
+++ b/tests/data/no_metadata.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<report title="Sneakers">
+ <section title="Air Max">
+ <entry title="Air Max 90">
+ <text>One of the more icon color is the infrared.</text>
+ </entry>
+ <entry title="Air Max 95">
+ <text>Launched in 1995, designed by Sergio Lozano.</text>
+ </entry>
+ <entry title="Air Max 97">
+ <text>Well highlighted Air bubble.
+
+Inspired by mountain bikes, while an urban legend quotes Japan bullet trains as inspiration.</text>
+ </entry>
+ </section>
+ <section title="Other Nike Air">
+ <entry title="Introduction">
+ <text>Because there are other sneakers than Air Max.</text>
+ </entry>
+ <entry title="Air Force 1">
+ <text>« Air Force 1. Zéro fan, que des fanatiques. » -- LTA</text>
+ </entry>
+ </section>
+ <section title="👟"/>
+</report>
diff --git a/tests/data/only_metadata.html b/tests/data/only_metadata.html
new file mode 100644
--- /dev/null
+++ b/tests/data/only_metadata.html
@@ -0,0 +1,14 @@
+<h1 id="sneakers">Sneakers</h1>
+<h2 id="report-properties">Report properties</h2>
+<table>
+ <tbody>
+ <tr>
+ <th>Date</th>
+ <td>9999-99-99</td>
+ </tr>
+ <tr>
+ <th>Topic</th>
+ <td>Urban culture</td>
+ </tr>
+ </tbody>
+</table>
diff --git a/tests/data/only_metadata.md b/tests/data/only_metadata.md
new file mode 100644
--- /dev/null
+++ b/tests/data/only_metadata.md
@@ -0,0 +1,6 @@
+# Sneakers
+
+| Property | |
+|----------|---------------|
+| Date | 9999-99-99 |
+| Topic | Urban culture |
diff --git a/tests/data/only_metadata.xml b/tests/data/only_metadata.xml
new file mode 100644
--- /dev/null
+++ b/tests/data/only_metadata.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<report title="Sneakers">
+ <data title="Properties">
+ <entry>
+ <key>Date</key>
+ <value>9999-99-99</value>
+ </entry>
+ <entry>
+ <key>Topic</key>
+ <value>Urban culture</value>
+ </entry>
+ </data>
+</report>

File Metadata

Mime Type
text/plain
Expires
Thu, Nov 21, 10:12 (21 h, 52 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2254994
Default Alt Text
D2538.id6403.diff (19 KB)

Event Timeline