xref: /webtrees/tests/app/Factories/MarkdownFactoryTest.php (revision 3ed19dbddff9f995e487ce66982b5b3c32f80e24)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2021 webtrees development team
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18declare(strict_types=1);
19
20namespace Fisharebest\Webtrees\Factories;
21
22use Fisharebest\Webtrees\TestCase;
23use Fisharebest\Webtrees\Tree;
24
25/**
26 * Test harness for the class GedcomEditService
27 *
28 * @covers \Fisharebest\Webtrees\Factories\MarkdownFactory
29 */
30class MarkdownFactoryTest extends TestCase
31{
32    /**
33     * @covers \Fisharebest\Webtrees\Factories\MarkdownFactory
34     */
35    public function testAutoLinkWithoutTree(): void
36    {
37        $factory  = new MarkdownFactory();
38        $autolink = $factory->autolink();
39
40        $this->assertSame(
41            "<p>FOO <a href=\"https://example.com\">https://example.com</a> BAR</p>\n",
42            $autolink->convertToHtml('FOO https://example.com BAR')
43        );
44    }
45
46    /**
47     * @covers \Fisharebest\Webtrees\CommonMark\XrefExtension
48     * @covers \Fisharebest\Webtrees\Factories\MarkdownFactory
49     */
50    public function testAutoLinkWithTree(): void
51    {
52        $tree = $this->createStub(Tree::class);
53
54        $factory  = new MarkdownFactory();
55        $autolink = $factory->autolink($tree);
56
57        $this->assertSame(
58            "<p>FOO <a href=\"https://example.com\">https://example.com</a> BAR</p>\n",
59            $autolink->convertToHtml('FOO https://example.com BAR')
60        );
61    }
62
63    /**
64     * @covers \Fisharebest\Webtrees\CommonMark\XrefExtension
65     * @covers \Fisharebest\Webtrees\Factories\MarkdownFactory
66     */
67    public function testAutoLinkWithHtml(): void
68    {
69        $factory  = new MarkdownFactory();
70        $autolink = $factory->autolink();
71
72        $this->assertSame(
73            "<p>&lt;b&gt; <a href=\"https://example.com\">https://example.com</a> &lt;/b&gt;</p>\n",
74            $autolink->convertToHtml('<b> https://example.com </b>')
75        );
76    }
77
78    /**
79     * @covers \Fisharebest\Webtrees\Factories\MarkdownFactory
80     */
81    public function testMarkdownWithoutTree(): void
82    {
83        $factory  = new MarkdownFactory();
84        $Markdown = $factory->Markdown();
85
86        $this->assertSame(
87            "<p>FOO https://example.com BAR</p>\n",
88            $Markdown->convertToHtml('FOO https://example.com BAR')
89        );
90
91        $this->assertSame(
92            "<p>FOO <a href=\"https://example.com\">https://example.com</a> BAR</p>\n",
93            $Markdown->convertToHtml('FOO <https://example.com> BAR')
94        );
95    }
96
97    /**
98     * @covers \Fisharebest\Webtrees\CommonMark\XrefExtension
99     * @covers \Fisharebest\Webtrees\Factories\MarkdownFactory
100     */
101    public function testMarkdownWithTree(): void
102    {
103        $tree = $this->createStub(Tree::class);
104
105        $factory  = new MarkdownFactory();
106        $Markdown = $factory->Markdown($tree);
107
108        $this->assertSame(
109            "<p>FOO https://example.com BAR</p>\n",
110            $Markdown->convertToHtml('FOO https://example.com BAR')
111        );
112
113        $this->assertSame(
114            "<p>FOO <a href=\"https://example.com\">https://example.com</a> BAR</p>\n",
115            $Markdown->convertToHtml('FOO <https://example.com> BAR')
116        );
117    }
118
119    /**
120     * @covers \Fisharebest\Webtrees\CommonMark\XrefExtension
121     * @covers \Fisharebest\Webtrees\Factories\MarkdownFactory
122     */
123    public function testMarkdownWithHtml(): void
124    {
125        $factory  = new MarkdownFactory();
126        $markdown = $factory->Markdown();
127
128        $this->assertSame(
129            "<p>&lt;b&gt; <a href=\"https://example.com\">https://example.com</a> &lt;/b&gt;</p>\n",
130            $markdown->convertToHtml('<b> <https://example.com> </b>')
131        );
132    }
133}
134