xref: /webtrees/tests/app/Factories/MarkdownFactoryTest.php (revision 89950eb4a8b302be0915d2ba9885d70db994abd6)
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
39        $this->assertSame(
40            "<p>FOO <a href=\"https://example.com\">https://example.com</a> BAR</p>\n",
41            $factory->autolink('FOO https://example.com BAR')
42        );
43    }
44
45    /**
46     * @covers \Fisharebest\Webtrees\CommonMark\XrefExtension
47     * @covers \Fisharebest\Webtrees\Factories\MarkdownFactory
48     */
49    public function testAutoLinkWithTree(): void
50    {
51        $factory = new MarkdownFactory();
52        $tree    = $this->createStub(Tree::class);
53
54        $this->assertSame(
55            "<p>FOO <a href=\"https://example.com\">https://example.com</a> BAR</p>\n",
56            $factory->autolink('FOO https://example.com BAR', $tree)
57        );
58    }
59
60    /**
61     * @covers \Fisharebest\Webtrees\CommonMark\XrefExtension
62     * @covers \Fisharebest\Webtrees\Factories\MarkdownFactory
63     */
64    public function testAutoLinkWithHtml(): void
65    {
66        $factory  = new MarkdownFactory();
67
68        $this->assertSame(
69            "<p>&lt;b&gt; <a href=\"https://example.com\">https://example.com</a> &lt;/b&gt;</p>\n",
70            $factory->autolink('<b> https://example.com </b>')
71        );
72    }
73
74    /**
75     * @covers \Fisharebest\Webtrees\Factories\MarkdownFactory
76     */
77    public function testMarkdownWithoutTree(): void
78    {
79        $factory = new MarkdownFactory();
80
81        $this->assertSame(
82            "<p>FOO https://example.com BAR</p>\n",
83            $factory->markdown('FOO https://example.com BAR')
84        );
85
86        $this->assertSame(
87            "<p>FOO <a href=\"https://example.com\">https://example.com</a> BAR</p>\n",
88            $factory->markdown('FOO <https://example.com> BAR')
89        );
90    }
91
92    /**
93     * @covers \Fisharebest\Webtrees\CommonMark\XrefExtension
94     * @covers \Fisharebest\Webtrees\Factories\MarkdownFactory
95     */
96    public function testMarkdownWithTree(): void
97    {
98        $tree    = $this->createStub(Tree::class);
99        $factory = new MarkdownFactory();
100
101        $this->assertSame(
102            "<p>FOO https://example.com BAR</p>\n",
103            $factory->markdown('FOO https://example.com BAR', $tree)
104        );
105
106        $this->assertSame(
107            "<p>FOO <a href=\"https://example.com\">https://example.com</a> BAR</p>\n",
108            $factory->markdown('FOO <https://example.com> BAR', $tree)
109        );
110    }
111
112    /**
113     * @covers \Fisharebest\Webtrees\CommonMark\XrefExtension
114     * @covers \Fisharebest\Webtrees\Factories\MarkdownFactory
115     */
116    public function testMarkdownWithHtml(): void
117    {
118        $factory = new MarkdownFactory();
119
120        $this->assertSame(
121            "<p>&lt;b&gt; <a href=\"https://example.com\">https://example.com</a> &lt;/b&gt;</p>\n",
122            $factory->markdown('<b> <https://example.com> </b>')
123        );
124    }
125}
126