ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
MarkdownShapeTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use PHPUnit\Framework\TestCase;
23use ILIAS\Data;
26
27class MarkdownShapeTest extends TestCase
28{
30
31 protected function setUp(): void
32 {
33 $language = $this->createMock(ilLanguage::class);
34 $data_factory = new Data\Factory();
35 $refinery = new ILIAS\Refinery\Factory($data_factory, $language);
36 $this->markdown_shape = new Markdown(new \ILIAS\Refinery\String\MarkdownFormattingToHTML());
37 }
38
39 public static function stringToHTMLDataProvider(): array
40 {
41 return [
42 ["lorem", new HTML("<p>lorem</p>\n")],
43 ["lorem **ipsum**", new HTML("<p>lorem <strong>ipsum</strong></p>\n")],
44 ["_lorem_ **ipsum**", new HTML("<p><em>lorem</em> <strong>ipsum</strong></p>\n")],
45 ["# Headline", new HTML("<h1>Headline</h1>\n")],
46 ["## Headline", new HTML("<h2>Headline</h2>\n")],
47 ["### Headline", new HTML("<h3>Headline</h3>\n")],
48 ["1. Lorem\n2. Ipsum", new HTML("<ol>\n<li>Lorem</li>\n<li>Ipsum</li>\n</ol>\n")],
49 ["- Lorem\n- Ipsum", new HTML("<ul>\n<li>Lorem</li>\n<li>Ipsum</li>\n</ul>\n")],
50 ["[Link Titel](https://www.ilias.de)", new HTML("<p><a href=\"https://www.ilias.de\">Link Titel</a></p>\n")]
51 ];
52 }
53
54 public static function stringToPlainDataProvider(): array
55 {
56 return [
57 ["lorem", new PlainText("lorem")],
58 ["lorem **ipsum**", new PlainText("lorem **ipsum**")],
59 ["_lorem_ **ipsum**", new PlainText("_lorem_ **ipsum**")],
60 ["# Headline", new PlainText("# Headline")],
61 ["## Headline", new PlainText("## Headline")],
62 ["### Headline", new PlainText("### Headline")],
63 ["1. Lorem\n2. Ipsum", new PlainText("1. Lorem\n2. Ipsum")],
64 ["- Lorem\n- Ipsum", new PlainText("- Lorem\n- Ipsum")],
65 ["[Link Titel](https://www.ilias.de)", new PlainText("[Link Titel](https://www.ilias.de)")]
66 ];
67 }
68
69 #[\PHPUnit\Framework\Attributes\DataProvider('stringToHTMLDataProvider')]
70 public function testToHTML(string $markdown_string, HTML $expected_html): void
71 {
72 $text = $this->markdown_shape->fromString($markdown_string);
73 $this->assertEquals($expected_html, $this->markdown_shape->toHTML($text));
74 }
75
76 #[\PHPUnit\Framework\Attributes\DataProvider('stringToPlainDataProvider')]
77 public function testToPlainText(string $markdown_string, PlainText $expected_text): void
78 {
79 $text = $this->markdown_shape->fromString($markdown_string);
80 $this->assertEquals($expected_text, $this->markdown_shape->toPlainText($text));
81 }
82}
Builds data types.
Definition: Factory.php:36
This class currently is a stub only.
Definition: HTML.php:28
This class currently is a stub only.
Definition: PlainText.php:28
testToPlainText(string $markdown_string, PlainText $expected_text)
static stringToPlainDataProvider()
testToHTML(string $markdown_string, HTML $expected_html)
static stringToHTMLDataProvider()
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.