forked from BookStackApp/BookStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPageRepoTest.php
More file actions
78 lines (68 loc) · 2.14 KB
/
Copy pathPageRepoTest.php
File metadata and controls
78 lines (68 loc) · 2.14 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
namespace Tests;
use BookStack\Entities\Repos\PageRepo;
class PageRepoTest extends TestCase
{
/**
* @var PageRepo $pageRepo
*/
protected $pageRepo;
protected function setUp()
{
parent::setUp();
$this->pageRepo = app()->make(PageRepo::class);
}
public function test_get_page_nav_sets_correct_properties()
{
$content = '<h1 id="testa">Hello</h1><h2 id="testb">There</h2><h3 id="testc">Donkey</h3>';
$navMap = $this->pageRepo->getPageNav($content);
$this->assertCount(3, $navMap);
$this->assertArraySubset([
'nodeName' => 'h1',
'link' => '#testa',
'text' => 'Hello',
'level' => 1,
], $navMap[0]);
$this->assertArraySubset([
'nodeName' => 'h2',
'link' => '#testb',
'text' => 'There',
'level' => 2,
], $navMap[1]);
$this->assertArraySubset([
'nodeName' => 'h3',
'link' => '#testc',
'text' => 'Donkey',
'level' => 3,
], $navMap[2]);
}
public function test_get_page_nav_does_not_show_empty_titles()
{
$content = '<h1 id="testa">Hello</h1><h2 id="testb"> </h2><h3 id="testc"></h3>';
$navMap = $this->pageRepo->getPageNav($content);
$this->assertCount(1, $navMap);
$this->assertArraySubset([
'nodeName' => 'h1',
'link' => '#testa',
'text' => 'Hello'
], $navMap[0]);
}
public function test_get_page_nav_shifts_headers_if_only_smaller_ones_are_used()
{
$content = '<h4 id="testa">Hello</h4><h5 id="testb">There</h5><h6 id="testc">Donkey</h6>';
$navMap = $this->pageRepo->getPageNav($content);
$this->assertCount(3, $navMap);
$this->assertArraySubset([
'nodeName' => 'h4',
'level' => 1,
], $navMap[0]);
$this->assertArraySubset([
'nodeName' => 'h5',
'level' => 2,
], $navMap[1]);
$this->assertArraySubset([
'nodeName' => 'h6',
'level' => 3,
], $navMap[2]);
}
}