Repository navigation
Expand file tree
/
Copy pathFaqExtractorTest.php
More file actions
61 lines (49 loc) · 2.08 KB
/
Copy pathFaqExtractorTest.php
File metadata and controls
61 lines (49 loc) · 2.08 KB
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
<?php
declare(strict_types=1);
namespace LightTest\Unit\App\Service;
use Light\App\Service\FaqExtractor;
use LightTest\Unit\UnitTest;
class FaqExtractorTest extends UnitTest
{
public function testExtractPullsTheQuestionAnswerPairsOutOfTheFaqSection(): void
{
$body = "Some intro text.\n\n## FAQ\n\n"
. "**Q: What is it?**\nA: It's an example.\n\n"
. "**Q: Why does it matter?**\nA: Because tests need coverage.";
$result = FaqExtractor::extract($body);
$this->assertSame('Some intro text.', $result['body']);
$this->assertSame(
[
[
'question' => 'What is it?',
'answer' => "It's an example.",
'questionText' => 'What is it?',
'answerText' => "It's an example.",
],
[
'question' => 'Why does it matter?',
'answer' => 'Because tests need coverage.',
'questionText' => 'Why does it matter?',
'answerText' => 'Because tests need coverage.',
],
],
$result['faq']
);
}
public function testExtractKeepsMarkdownForRenderingAndStripsBackticksForPlainText(): void
{
$body = "## FAQ\n\n**Q: Is `dot-cache` needed?**\nA: Use `dot-cache` and ``dot-cli``.";
$result = FaqExtractor::extract($body);
$this->assertSame('Is `dot-cache` needed?', $result['faq'][0]['question']);
$this->assertSame('Use `dot-cache` and ``dot-cli``.', $result['faq'][0]['answer']);
$this->assertSame('Is dot-cache needed?', $result['faq'][0]['questionText']);
$this->assertSame('Use dot-cache and dot-cli.', $result['faq'][0]['answerText']);
}
public function testExtractReturnsAnEmptyFaqWhenThereIsNoFaqSection(): void
{
$body = "Some intro text.\n\nMore content.";
$result = FaqExtractor::extract($body);
$this->assertSame([], $result['faq']);
$this->assertSame($body, $result['body']);
}
}