xref: /webtrees/tests/app/Factories/MarkdownFactoryTest.php (revision b11cdcd45131b1585d66693fab363cfeb18c51a4)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * 'Copyright (C) 2023 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 MarkdownFactory
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        static::assertSame(
40            '<p>FOO <a href="https://example.com">https://example.com</a> BAR</p>',
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        static::assertSame(
55            '<p>FOO <a href="https://example.com">https://example.com</a> BAR</p>',
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        static::assertSame(
69            '<p>&lt;b&gt; <a href="https://example.com">https://example.com</a> &lt;/b&gt;</p>',
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        static::assertSame(
82            '<p>FOO https://example.com BAR</p>',
83            $factory->markdown('FOO https://example.com BAR')
84        );
85
86        static::assertSame(
87            '<p>FOO <a href="https://example.com">https://example.com</a> BAR</p>',
88            $factory->markdown('FOO <https://example.com> BAR')
89        );
90    }
91
92    /**
93     * @covers \Fisharebest\Webtrees\Factories\MarkdownFactory
94     */
95    public function testMarkdownWithTree(): void
96    {
97        $tree    = $this->createStub(Tree::class);
98        $factory = new MarkdownFactory();
99
100        static::assertSame(
101            '<p>FOO https://example.com BAR</p>',
102            $factory->markdown('FOO https://example.com BAR', $tree)
103        );
104
105        static::assertSame(
106            '<p>FOO <a href="https://example.com">https://example.com</a> BAR</p>',
107            $factory->markdown('FOO <https://example.com> BAR', $tree)
108        );
109    }
110
111    /**
112     * @covers \Fisharebest\Webtrees\Factories\MarkdownFactory
113     */
114    public function testMarkdownWithHtml(): void
115    {
116        $factory = new MarkdownFactory();
117
118        static::assertSame(
119            '<p>&lt;b&gt; <a href="https://example.com">https://example.com</a> &lt;/b&gt;</p>',
120            $factory->markdown('<b> <https://example.com> </b>')
121        );
122    }
123
124    /**
125     * @covers \Fisharebest\Webtrees\Factories\MarkdownFactory
126     */
127    public function testSoftLineBreaks(): void
128    {
129        $factory = new MarkdownFactory();
130
131        static::assertSame(
132            '<p>alpha<br />beta<br />gamma<br />delta</p>',
133            $factory->autolink("alpha\nbeta\ngamma  \ndelta")
134        );
135
136        static::assertSame(
137            '<p>alpha<br />beta<br />gamma<br />delta</p>',
138            $factory->markdown("alpha\nbeta\ngamma  \ndelta")
139        );
140    }
141
142    /**
143     * @covers \Fisharebest\Webtrees\Factories\MarkdownFactory
144     */
145    public function testMultipleParagraphs(): void
146    {
147        $factory = new MarkdownFactory();
148
149        static::assertSame(
150            '<p>alpha<br />beta</p><p>gamma<br />delta</p>',
151            $factory->autolink("alpha\nbeta\n\n\n\ngamma\ndelta")
152        );
153
154        static::assertSame(
155            '<p>alpha<br />beta</p><p>gamma<br />delta</p>',
156            $factory->markdown("alpha\nbeta\n\n\n\ngamma\ndelta")
157        );
158    }
159}
160