/
FaqHelperTest.php
72 lines (58 loc) · 2.09 KB
/
FaqHelperTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
namespace phpMyFAQ\Helper;
use phpMyFAQ\Configuration;
use phpMyFAQ\Database\Sqlite3;
use phpMyFAQ\Entity\FaqEntity;
use phpMyFAQ\System;
use PHPUnit\Framework\TestCase;
class FaqHelperTest extends TestCase
{
/** @var Configuration */
private Configuration $configuration;
/** @var FaqHelper*/
private FaqHelper $faqHelper;
protected function setUp(): void
{
parent::setUp();
$dbHandle = new Sqlite3();
$dbHandle->connect(PMF_TEST_DIR . '/test.db', '', '');
$this->configuration = new Configuration($dbHandle);
$this->configuration->set('main.currentVersion', System::getVersion());
$this->configuration->set('main.referenceURL', 'https://localhost:443/');
$this->faqHelper = new FaqHelper($this->configuration);
}
public function testRenderMarkupContent(): void
{
$this->assertEquals(
'<div class="language-html">Foobar</div>',
$this->faqHelper->renderMarkupContent('<div class="language-markup">Foobar</div>')
);
}
public function testRewriteUrlFragments(): void
{
$content = '<a href="#Foobar">Hello, World</a>';
$result = $this->faqHelper->rewriteUrlFragments($content, 'https://localhost:443/');
$this->assertEquals(
'<a href="https://localhost:443/#Foobar">Hello, World</a>',
$result
);
}
public function testCreateFaqUrl(): void
{
$faqEntity = new FaqEntity();
$faqEntity
->setId(42)
->setLanguage('de');
$this->assertEquals(
'https://localhost:443/index.php?action=faq&cat=1&id=42&artlang=de',
$this->faqHelper->createFaqUrl($faqEntity, 1)
);
}
public function testCleanUpContent(): void
{
$content = '<p>Some text <script>alert("Hello, world!");</script><img src=foo onerror=alert(document.cookie)></p>';
$expectedOutput = '<p>Some text <img src="foo"></p>';
$actualOutput = $this->faqHelper->cleanUpContent($content);
$this->assertEquals($expectedOutput, $actualOutput);
}
}