xref: /webtrees/tests/app/Factories/MarkdownFactoryTest.php (revision db3f03687778a9ca480e61247e532d65feca63b1)
1dbfdfe6bSGreg Roach<?php
2dbfdfe6bSGreg Roach
3dbfdfe6bSGreg Roach/**
4dbfdfe6bSGreg Roach * webtrees: online genealogy
55bfc6897SGreg Roach * Copyright (C) 2022 webtrees development team
6dbfdfe6bSGreg Roach * This program is free software: you can redistribute it and/or modify
7dbfdfe6bSGreg Roach * it under the terms of the GNU General Public License as published by
8dbfdfe6bSGreg Roach * the Free Software Foundation, either version 3 of the License, or
9dbfdfe6bSGreg Roach * (at your option) any later version.
10dbfdfe6bSGreg Roach * This program is distributed in the hope that it will be useful,
11dbfdfe6bSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
12dbfdfe6bSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13dbfdfe6bSGreg Roach * GNU General Public License for more details.
14dbfdfe6bSGreg Roach * You should have received a copy of the GNU General Public License
15dbfdfe6bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>.
16dbfdfe6bSGreg Roach */
17dbfdfe6bSGreg Roach
18dbfdfe6bSGreg Roachdeclare(strict_types=1);
19dbfdfe6bSGreg Roach
20dbfdfe6bSGreg Roachnamespace Fisharebest\Webtrees\Factories;
21dbfdfe6bSGreg Roach
22dbfdfe6bSGreg Roachuse Fisharebest\Webtrees\TestCase;
23dbfdfe6bSGreg Roachuse Fisharebest\Webtrees\Tree;
24dbfdfe6bSGreg Roach
25dbfdfe6bSGreg Roach/**
26d4ec5ec0SGreg Roach * Test harness for the class MarkdownFactory
27dbfdfe6bSGreg Roach *
28dbfdfe6bSGreg Roach * @covers \Fisharebest\Webtrees\Factories\MarkdownFactory
29dbfdfe6bSGreg Roach */
30dbfdfe6bSGreg Roachclass MarkdownFactoryTest extends TestCase
31dbfdfe6bSGreg Roach{
32dbfdfe6bSGreg Roach    /**
33dbfdfe6bSGreg Roach     * @covers \Fisharebest\Webtrees\Factories\MarkdownFactory
34dbfdfe6bSGreg Roach     */
35dbfdfe6bSGreg Roach    public function testAutoLinkWithoutTree(): void
36dbfdfe6bSGreg Roach    {
37dbfdfe6bSGreg Roach        $factory  = new MarkdownFactory();
38dbfdfe6bSGreg Roach
39f01ab4acSGreg Roach        static::assertSame(
40dbfdfe6bSGreg Roach            "<p>FOO <a href=\"https://example.com\">https://example.com</a> BAR</p>\n",
416f595250SGreg Roach            $factory->autolink('FOO https://example.com BAR')
42dbfdfe6bSGreg Roach        );
43dbfdfe6bSGreg Roach    }
44dbfdfe6bSGreg Roach
45dbfdfe6bSGreg Roach    /**
46dbfdfe6bSGreg Roach     * @covers \Fisharebest\Webtrees\CommonMark\XrefExtension
47dbfdfe6bSGreg Roach     * @covers \Fisharebest\Webtrees\Factories\MarkdownFactory
48dbfdfe6bSGreg Roach     */
49dbfdfe6bSGreg Roach    public function testAutoLinkWithTree(): void
50dbfdfe6bSGreg Roach    {
51dbfdfe6bSGreg Roach        $factory = new MarkdownFactory();
526f595250SGreg Roach        $tree    = $this->createStub(Tree::class);
53dbfdfe6bSGreg Roach
54f01ab4acSGreg Roach        static::assertSame(
55dbfdfe6bSGreg Roach            "<p>FOO <a href=\"https://example.com\">https://example.com</a> BAR</p>\n",
566f595250SGreg Roach            $factory->autolink('FOO https://example.com BAR', $tree)
57dbfdfe6bSGreg Roach        );
58dbfdfe6bSGreg Roach    }
59dbfdfe6bSGreg Roach
60dbfdfe6bSGreg Roach    /**
61dbfdfe6bSGreg Roach     * @covers \Fisharebest\Webtrees\CommonMark\XrefExtension
62dbfdfe6bSGreg Roach     * @covers \Fisharebest\Webtrees\Factories\MarkdownFactory
63dbfdfe6bSGreg Roach     */
64dbfdfe6bSGreg Roach    public function testAutoLinkWithHtml(): void
65dbfdfe6bSGreg Roach    {
66dbfdfe6bSGreg Roach        $factory  = new MarkdownFactory();
67dbfdfe6bSGreg Roach
68f01ab4acSGreg Roach        static::assertSame(
69dbfdfe6bSGreg Roach            "<p>&lt;b&gt; <a href=\"https://example.com\">https://example.com</a> &lt;/b&gt;</p>\n",
706f595250SGreg Roach            $factory->autolink('<b> https://example.com </b>')
71dbfdfe6bSGreg Roach        );
72dbfdfe6bSGreg Roach    }
73dbfdfe6bSGreg Roach
74dbfdfe6bSGreg Roach    /**
75dbfdfe6bSGreg Roach     * @covers \Fisharebest\Webtrees\Factories\MarkdownFactory
76dbfdfe6bSGreg Roach     */
77dbfdfe6bSGreg Roach    public function testMarkdownWithoutTree(): void
78dbfdfe6bSGreg Roach    {
79dbfdfe6bSGreg Roach        $factory = new MarkdownFactory();
80dbfdfe6bSGreg Roach
81f01ab4acSGreg Roach        static::assertSame(
82dbfdfe6bSGreg Roach            "<p>FOO https://example.com BAR</p>\n",
836f595250SGreg Roach            $factory->markdown('FOO https://example.com BAR')
84dbfdfe6bSGreg Roach        );
85dbfdfe6bSGreg Roach
86f01ab4acSGreg Roach        static::assertSame(
87dbfdfe6bSGreg Roach            "<p>FOO <a href=\"https://example.com\">https://example.com</a> BAR</p>\n",
886f595250SGreg Roach            $factory->markdown('FOO <https://example.com> BAR')
89dbfdfe6bSGreg Roach        );
90dbfdfe6bSGreg Roach    }
91dbfdfe6bSGreg Roach
92dbfdfe6bSGreg Roach    /**
93dbfdfe6bSGreg Roach     * @covers \Fisharebest\Webtrees\Factories\MarkdownFactory
94dbfdfe6bSGreg Roach     */
95dbfdfe6bSGreg Roach    public function testMarkdownWithTree(): void
96dbfdfe6bSGreg Roach    {
97dbfdfe6bSGreg Roach        $tree    = $this->createStub(Tree::class);
98dbfdfe6bSGreg Roach        $factory = new MarkdownFactory();
99dbfdfe6bSGreg Roach
100f01ab4acSGreg Roach        static::assertSame(
101dbfdfe6bSGreg Roach            "<p>FOO https://example.com BAR</p>\n",
1026f595250SGreg Roach            $factory->markdown('FOO https://example.com BAR', $tree)
103dbfdfe6bSGreg Roach        );
104dbfdfe6bSGreg Roach
105f01ab4acSGreg Roach        static::assertSame(
106dbfdfe6bSGreg Roach            "<p>FOO <a href=\"https://example.com\">https://example.com</a> BAR</p>\n",
1076f595250SGreg Roach            $factory->markdown('FOO <https://example.com> BAR', $tree)
108dbfdfe6bSGreg Roach        );
109dbfdfe6bSGreg Roach    }
110dbfdfe6bSGreg Roach
111dbfdfe6bSGreg Roach    /**
112dbfdfe6bSGreg Roach     * @covers \Fisharebest\Webtrees\Factories\MarkdownFactory
113dbfdfe6bSGreg Roach     */
114dbfdfe6bSGreg Roach    public function testMarkdownWithHtml(): void
115dbfdfe6bSGreg Roach    {
116dbfdfe6bSGreg Roach        $factory = new MarkdownFactory();
117dbfdfe6bSGreg Roach
118f01ab4acSGreg Roach        static::assertSame(
119dbfdfe6bSGreg Roach            "<p>&lt;b&gt; <a href=\"https://example.com\">https://example.com</a> &lt;/b&gt;</p>\n",
1206f595250SGreg Roach            $factory->markdown('<b> <https://example.com> </b>')
121dbfdfe6bSGreg Roach        );
122dbfdfe6bSGreg Roach    }
123*db3f0368SGreg Roach
124*db3f0368SGreg Roach    /**
125*db3f0368SGreg Roach     * @covers \Fisharebest\Webtrees\Factories\MarkdownFactory
126*db3f0368SGreg Roach     */
127*db3f0368SGreg Roach    public function testSoftLineBreaks(): void
128*db3f0368SGreg Roach    {
129*db3f0368SGreg Roach        $factory = new MarkdownFactory();
130*db3f0368SGreg Roach
131*db3f0368SGreg Roach        static::assertSame(
132*db3f0368SGreg Roach            "<p>alpha<br>beta<br>gamma<br />\ndelta</p>\n",
133*db3f0368SGreg Roach            $factory->autolink("alpha\nbeta\ngamma  \ndelta")
134*db3f0368SGreg Roach        );
135*db3f0368SGreg Roach
136*db3f0368SGreg Roach        static::assertSame(
137*db3f0368SGreg Roach            "<p>alpha<br>beta<br>gamma<br />\ndelta</p>\n",
138*db3f0368SGreg Roach            $factory->markdown("alpha\nbeta\ngamma  \ndelta")
139*db3f0368SGreg Roach        );
140*db3f0368SGreg Roach    }
141*db3f0368SGreg Roach
142*db3f0368SGreg Roach    /**
143*db3f0368SGreg Roach     * @covers \Fisharebest\Webtrees\Factories\MarkdownFactory
144*db3f0368SGreg Roach     */
145*db3f0368SGreg Roach    public function testMultipleParagraphs(): void
146*db3f0368SGreg Roach    {
147*db3f0368SGreg Roach        $factory = new MarkdownFactory();
148*db3f0368SGreg Roach
149*db3f0368SGreg Roach        static::assertSame(
150*db3f0368SGreg Roach            "<p>alpha<br>beta</p>\n<p>gamma<br>delta</p>\n",
151*db3f0368SGreg Roach            $factory->autolink("alpha\nbeta\n\n\n\ngamma\ndelta")
152*db3f0368SGreg Roach        );
153*db3f0368SGreg Roach
154*db3f0368SGreg Roach        static::assertSame(
155*db3f0368SGreg Roach            "<p>alpha<br>beta</p>\n<p>gamma<br>delta</p>\n",
156*db3f0368SGreg Roach            $factory->markdown("alpha\nbeta\n\n\n\ngamma\ndelta")
157*db3f0368SGreg Roach        );
158*db3f0368SGreg Roach    }
159dbfdfe6bSGreg Roach}
160