| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- declare(strict_types=1);
-
- use PHPUnit\Framework\TestCase;
-
- require_once __DIR__ . '/../../php/markdown.php';
- require_once __DIR__ . '/../../php/spreadsheet.php';
-
- final class SpreadsheetMarkdownIntegrationTests extends TestCase {
- private ?Markdown $parser;
-
- protected function setUp(): void {
- $this->parser = new Markdown(array_merge(Markdown::allReaders(), [ new MDSpreadsheetReader() ]));
- }
-
- private function md(string $markdown): string {
- return $this->normalizeWhitespace($this->parser->toHTML($markdown));
- }
-
- private function normalizeWhitespace(string $str): string {
- $str = mb_eregi_replace('\\s+', ' ', $str);
- $str = mb_eregi_replace('>\\s+<', '><', $str);
- return trim($str);
- }
-
- public function test_integration() {
- $markdown = "| A | B | C |\n| --- | --- | --- |\n| 3 | 4 | =A*B |";
- $expected = '<table><thead>' .
- '<tr><th>A</th><th>B</th><th>C</th></tr>' .
- '</thead><tbody><tr>' .
- '<td class="spreadsheet-type-number" data-numeric-value="3" data-string-value="3">3</td>' .
- '<td class="spreadsheet-type-number" data-numeric-value="4" data-string-value="4">4</td>' .
- '<td class="calculated spreadsheet-type-number" data-numeric-value="12" data-string-value="12">12</td>' .
- '</tr></tbody></table>';
- $actual = $this->md($markdown);
- $this->assertSame($expected, $actual);
- }
-
- public function test_bailOut() {
- // If no formulas found table isn't modified
- $markdown = "| A | B | C |\n| --- | --- | --- |\n| 3 | 4 | A*B |";
- $expected = '<table><thead>' .
- '<tr><th>A</th><th>B</th><th>C</th></tr>' .
- '</thead><tbody><tr>' .
- '<td>3</td>' .
- '<td>4</td>' .
- '<td>A*B</td>' .
- '</tr></tbody></table>';
- $actual = $this->md($markdown);
- $this->assertSame($expected, $actual);
- }
-
- public function test_observedError1() {
- // Saw "Uncaught Error: columnIndex must be number, got string" from this
- $markdown = "| Unit Price | Qty | Subtotal |\n| ---: | ---: | ---: |\n| $1.23 | 2 | =A*B FILL |\n| $4.99 | 6 | |\n| Total | | =SUM(C:C) |";
- $expected = '<table><thead><tr>' .
- '<th style="text-align: right;">Unit Price</th>' .
- '<th style="text-align: right;">Qty</th>' .
- '<th>Subtotal</th>' .
- '</tr></thead><tbody><tr>' .
- '<td class="spreadsheet-type-currency" style="text-align: right;" data-numeric-value="1.23" data-string-value="1.23">$1.23</td>' .
- '<td class="spreadsheet-type-number" style="text-align: right;" data-numeric-value="2" data-string-value="2">2</td>' .
- '<td class="calculated spreadsheet-type-currency" data-numeric-value="2.46" data-string-value="2.46">$2.46</td>' .
- '</tr><tr>' .
- '<td class="spreadsheet-type-currency" style="text-align: right;" data-numeric-value="4.99" data-string-value="4.99">$4.99</td>' .
- '<td class="spreadsheet-type-number" style="text-align: right;" data-numeric-value="6" data-string-value="6">6</td>' .
- '<td class="calculated spreadsheet-type-currency" data-numeric-value="29.94" data-string-value="29.94">$29.94</td>' .
- '</tr><tr>' .
- '<td class="spreadsheet-type-string" style="text-align: right;" data-string-value="Total">Total</td>' .
- '<td class="spreadsheet-type-blank" style="text-align: right;" data-numeric-value="0" data-string-value=""></td>' .
- '<td class="calculated spreadsheet-type-currency" data-numeric-value="32.4" data-string-value="32.4">$32.40</td>' .
- '</tr></tbody></table>';
- $actual = $this->md($markdown);
- $this->assertSame($expected, $actual);
- }
- }
- ?>
|