1dbfdfe6bSGreg Roach<?php 2dbfdfe6bSGreg Roach 3dbfdfe6bSGreg Roach/** 4dbfdfe6bSGreg Roach * webtrees: online genealogy 5d11be702SGreg Roach * Copyright (C) 2023 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 22202c018bSGreg Roachuse Fisharebest\Webtrees\CommonMark\XrefExtension; 23dbfdfe6bSGreg Roachuse Fisharebest\Webtrees\TestCase; 24dbfdfe6bSGreg Roachuse Fisharebest\Webtrees\Tree; 25202c018bSGreg Roachuse PHPUnit\Framework\Attributes\CoversClass; 26dbfdfe6bSGreg Roach 27202c018bSGreg Roach#[CoversClass(MarkdownFactory::class)] 28202c018bSGreg Roach#[CoversClass(XrefExtension::class)] 29dbfdfe6bSGreg Roachclass MarkdownFactoryTest extends TestCase 30dbfdfe6bSGreg Roach{ 31dbfdfe6bSGreg Roach public function testAutoLinkWithoutTree(): void 32dbfdfe6bSGreg Roach { 33dbfdfe6bSGreg Roach $factory = new MarkdownFactory(); 34dbfdfe6bSGreg Roach 35f01ab4acSGreg Roach static::assertSame( 3610e06497SGreg Roach '<p>FOO <a href="https://example.com">https://example.com</a> BAR</p>', 376f595250SGreg Roach $factory->autolink('FOO https://example.com BAR') 38dbfdfe6bSGreg Roach ); 39dbfdfe6bSGreg Roach } 40dbfdfe6bSGreg Roach 41dbfdfe6bSGreg Roach public function testAutoLinkWithTree(): void 42dbfdfe6bSGreg Roach { 43dbfdfe6bSGreg Roach $factory = new MarkdownFactory(); 44*62ff2f18SGreg Roach $tree = $this->createMock(Tree::class); 45dbfdfe6bSGreg Roach 46f01ab4acSGreg Roach static::assertSame( 4710e06497SGreg Roach '<p>FOO <a href="https://example.com">https://example.com</a> BAR</p>', 486f595250SGreg Roach $factory->autolink('FOO https://example.com BAR', $tree) 49dbfdfe6bSGreg Roach ); 50dbfdfe6bSGreg Roach } 51dbfdfe6bSGreg Roach 52dbfdfe6bSGreg Roach public function testAutoLinkWithHtml(): void 53dbfdfe6bSGreg Roach { 54dbfdfe6bSGreg Roach $factory = new MarkdownFactory(); 55dbfdfe6bSGreg Roach 56f01ab4acSGreg Roach static::assertSame( 5710e06497SGreg Roach '<p><b> <a href="https://example.com">https://example.com</a> </b></p>', 586f595250SGreg Roach $factory->autolink('<b> https://example.com </b>') 59dbfdfe6bSGreg Roach ); 60dbfdfe6bSGreg Roach } 61dbfdfe6bSGreg Roach 62dbfdfe6bSGreg Roach public function testMarkdownWithoutTree(): void 63dbfdfe6bSGreg Roach { 64dbfdfe6bSGreg Roach $factory = new MarkdownFactory(); 65dbfdfe6bSGreg Roach 66f01ab4acSGreg Roach static::assertSame( 6710e06497SGreg Roach '<p>FOO https://example.com BAR</p>', 686f595250SGreg Roach $factory->markdown('FOO https://example.com BAR') 69dbfdfe6bSGreg Roach ); 70dbfdfe6bSGreg Roach 71f01ab4acSGreg Roach static::assertSame( 7210e06497SGreg Roach '<p>FOO <a href="https://example.com">https://example.com</a> BAR</p>', 736f595250SGreg Roach $factory->markdown('FOO <https://example.com> BAR') 74dbfdfe6bSGreg Roach ); 75dbfdfe6bSGreg Roach } 76dbfdfe6bSGreg Roach 77dbfdfe6bSGreg Roach public function testMarkdownWithTree(): void 78dbfdfe6bSGreg Roach { 79*62ff2f18SGreg Roach $tree = $this->createMock(Tree::class); 80dbfdfe6bSGreg Roach $factory = new MarkdownFactory(); 81dbfdfe6bSGreg Roach 82f01ab4acSGreg Roach static::assertSame( 8363a2c22bSGreg Roach '<p>FOO https://example.com BAR</p>', 846f595250SGreg Roach $factory->markdown('FOO https://example.com BAR', $tree) 85dbfdfe6bSGreg Roach ); 86dbfdfe6bSGreg Roach 87f01ab4acSGreg Roach static::assertSame( 8863a2c22bSGreg Roach '<p>FOO <a href="https://example.com">https://example.com</a> BAR</p>', 896f595250SGreg Roach $factory->markdown('FOO <https://example.com> BAR', $tree) 90dbfdfe6bSGreg Roach ); 91dbfdfe6bSGreg Roach } 92dbfdfe6bSGreg Roach 93dbfdfe6bSGreg Roach public function testMarkdownWithHtml(): void 94dbfdfe6bSGreg Roach { 95dbfdfe6bSGreg Roach $factory = new MarkdownFactory(); 96dbfdfe6bSGreg Roach 97f01ab4acSGreg Roach static::assertSame( 9863a2c22bSGreg Roach '<p><b> <a href="https://example.com">https://example.com</a> </b></p>', 996f595250SGreg Roach $factory->markdown('<b> <https://example.com> </b>') 100dbfdfe6bSGreg Roach ); 101dbfdfe6bSGreg Roach } 102db3f0368SGreg Roach 103db3f0368SGreg Roach public function testSoftLineBreaks(): void 104db3f0368SGreg Roach { 105db3f0368SGreg Roach $factory = new MarkdownFactory(); 106db3f0368SGreg Roach 107db3f0368SGreg Roach static::assertSame( 10863a2c22bSGreg Roach '<p>alpha<br />beta<br />gamma<br />delta</p>', 109db3f0368SGreg Roach $factory->autolink("alpha\nbeta\ngamma \ndelta") 110db3f0368SGreg Roach ); 111db3f0368SGreg Roach 112db3f0368SGreg Roach static::assertSame( 11363a2c22bSGreg Roach '<p>alpha<br />beta<br />gamma<br />delta</p>', 114db3f0368SGreg Roach $factory->markdown("alpha\nbeta\ngamma \ndelta") 115db3f0368SGreg Roach ); 116db3f0368SGreg Roach } 117db3f0368SGreg Roach 118db3f0368SGreg Roach public function testMultipleParagraphs(): void 119db3f0368SGreg Roach { 120db3f0368SGreg Roach $factory = new MarkdownFactory(); 121db3f0368SGreg Roach 122db3f0368SGreg Roach static::assertSame( 12363a2c22bSGreg Roach '<p>alpha<br />beta</p><p>gamma<br />delta</p>', 124db3f0368SGreg Roach $factory->autolink("alpha\nbeta\n\n\n\ngamma\ndelta") 125db3f0368SGreg Roach ); 126db3f0368SGreg Roach 127db3f0368SGreg Roach static::assertSame( 12863a2c22bSGreg Roach '<p>alpha<br />beta</p><p>gamma<br />delta</p>', 129db3f0368SGreg Roach $factory->markdown("alpha\nbeta\n\n\n\ngamma\ndelta") 130db3f0368SGreg Roach ); 131db3f0368SGreg Roach } 132dbfdfe6bSGreg Roach} 133