@@ -22,116 +22,164 @@ public function setUp(): void
22
22
{
23
23
parent ::setUp ();
24
24
saveWikiText ('sidebar ' , '{{simplenavi>}} ' , 'create test sidebar ' );
25
- saveWikiText ('namespace1:foo ' , 'bar ' , 'foobar ' );
26
- saveWikiText ('namespace2:foo ' , 'bar ' , 'foobar ' );
27
- saveWikiText ('namespace12:foo ' , 'bar ' , 'foobar ' );
28
- saveWikiText ('namespace123:foo ' , 'bar ' , 'foobar ' );
29
- saveWikiText ('namespace21:foo ' , 'bar ' , 'foobar ' );
25
+
26
+ $ pages = [
27
+ ['namespace1:foo ' , 'Namespace 1 Foo ' ],
28
+ ['namespace1:start ' , 'ZZZ Namespace 1 Start ' ],
29
+ ['namespace2:foo ' , 'Namespace 2 Foo ' ],
30
+ ['namespace2 ' , 'Namespace 2 Start ' ],
31
+ ['namespace12:foo ' , 'Namespace 12 Foo ' ],
32
+ ['namespace12:start ' , 'Namespace 12 Start ' ],
33
+ ['namespace123:namespace123 ' , 'AAA Namespace 123 Start ' ],
34
+ ['namespace123:foo ' , 'Namespace 123 Foo ' ],
35
+ ['namespace123:deep:start ' , 'Namespace 123 Deep Start ' ],
36
+ ['namespace123:deep:foo ' , 'Namespace 123 Deep Foo ' ],
37
+ ['namespace21:foo ' , 'Namespace 21 Foo ' ],
38
+ ['namespace21:start ' , 'Namespace 21 Start ' ],
39
+ ];
40
+
41
+ foreach ($ pages as $ page ) {
42
+ saveWikiText ('simplenavi: ' . $ page [0 ], '====== ' . $ page [1 ] . ' ====== ' , 'create test page ' );
43
+ }
30
44
31
45
}
32
46
33
- /**
34
- * @covers syntax_plugin_simplenavi
35
- */
36
- public function testOutputNatural ()
37
- {
38
- global $ ID , $ conf ;
39
- $ conf ['plugin ' ]['simplenavi ' ]['sort ' ] = 'natural ' ;
47
+ public function dataProvider () {
48
+
49
+ yield [
50
+ 'set ' => 'by ID, all branches closed ' ,
51
+ 'titlesort ' => false ,
52
+ 'natsort ' => false ,
53
+ 'current ' => 'simplenavi ' ,
54
+ 'expect ' => [
55
+ 'simplenavi:namespace1:start ' ,
56
+ 'simplenavi:namespace12:start ' ,
57
+ 'simplenavi:namespace123:namespace123 ' ,
58
+ 'simplenavi:namespace2 ' ,
59
+ 'simplenavi:namespace21:start ' ,
60
+ ]
61
+ ];
40
62
41
- $ ID = 'wiki:start ' ;
42
- $ request = new TestRequest ();
43
- $ input = [
44
- 'id ' => 'namespace1:foo ' ,
63
+ yield [
64
+ 'set ' => 'by ID, Natural Sort, all branches closed ' ,
65
+ 'titlesort ' => false ,
66
+ 'natsort ' => true ,
67
+ 'current ' => 'simplenavi ' ,
68
+ 'expect ' => [
69
+ 'simplenavi:namespace1:start ' ,
70
+ 'simplenavi:namespace2 ' ,
71
+ 'simplenavi:namespace12:start ' ,
72
+ 'simplenavi:namespace21:start ' ,
73
+ 'simplenavi:namespace123:namespace123 ' ,
74
+ ]
75
+ ];
76
+
77
+ yield [
78
+ 'set ' => 'by ID, branch open ' ,
79
+ 'titlesort ' => false ,
80
+ 'natsort ' => false ,
81
+ 'current ' => 'simplenavi:namespace123:deep:foo ' ,
82
+ 'expect ' => [
83
+ 'simplenavi:namespace1:start ' ,
84
+ 'simplenavi:namespace12:start ' ,
85
+ 'simplenavi:namespace123:namespace123 ' ,
86
+ 'simplenavi:namespace123:deep:start ' ,
87
+ 'simplenavi:namespace123:deep:foo ' ,
88
+ 'simplenavi:namespace123:foo ' ,
89
+ 'simplenavi:namespace2 ' ,
90
+ 'simplenavi:namespace21:start ' ,
91
+ ]
92
+ ];
93
+
94
+ yield [
95
+ 'set ' => 'by ID, Natural Sort, branch open ' ,
96
+ 'titlesort ' => false ,
97
+ 'natsort ' => true ,
98
+ 'current ' => 'simplenavi:namespace123:deep:foo ' ,
99
+ 'expect ' => [
100
+ 'simplenavi:namespace1:start ' ,
101
+ 'simplenavi:namespace2 ' ,
102
+ 'simplenavi:namespace12:start ' ,
103
+ 'simplenavi:namespace21:start ' ,
104
+ 'simplenavi:namespace123:namespace123 ' ,
105
+ 'simplenavi:namespace123:deep:start ' ,
106
+ 'simplenavi:namespace123:deep:foo ' ,
107
+ 'simplenavi:namespace123:foo ' ,
108
+ ]
109
+ ];
110
+
111
+ yield [
112
+ 'set ' => 'by Title, all branches closed ' ,
113
+ 'titlesort ' => true ,
114
+ 'natsort ' => false ,
115
+ 'current ' => 'simplenavi ' ,
116
+ 'expect ' => [
117
+ 'simplenavi:namespace123:namespace123 ' ,
118
+ 'simplenavi:namespace12:start ' ,
119
+ 'simplenavi:namespace2 ' ,
120
+ 'simplenavi:namespace21:start ' ,
121
+ 'simplenavi:namespace1:start ' ,
122
+ ]
123
+ ];
124
+
125
+ yield [
126
+ 'set ' => 'by Title, Natural Search, all branches closed ' ,
127
+ 'titlesort ' => true ,
128
+ 'natsort ' => true ,
129
+ 'current ' => 'simplenavi ' ,
130
+ 'expect ' => [
131
+ 'simplenavi:namespace123:namespace123 ' ,
132
+ 'simplenavi:namespace2 ' ,
133
+ 'simplenavi:namespace12:start ' ,
134
+ 'simplenavi:namespace21:start ' ,
135
+ 'simplenavi:namespace1:start ' ,
136
+ ]
137
+ ];
138
+
139
+ yield [
140
+ 'set ' => 'by Title, branch open ' ,
141
+ 'titlesort ' => true ,
142
+ 'natsort ' => false ,
143
+ 'current ' => 'simplenavi:namespace123:deep:foo ' ,
144
+ 'expect ' => [
145
+ 'simplenavi:namespace123:namespace123 ' ,
146
+ 'simplenavi:namespace123:deep:start ' ,
147
+ 'simplenavi:namespace123:deep:foo ' ,
148
+ 'simplenavi:namespace123:foo ' ,
149
+ 'simplenavi:namespace12:start ' ,
150
+ 'simplenavi:namespace2 ' ,
151
+ 'simplenavi:namespace21:start ' ,
152
+ 'simplenavi:namespace1:start ' ,
153
+ ]
154
+ ];
155
+
156
+ yield [
157
+ 'set ' => 'by Title, Natural Sort, branch open ' ,
158
+ 'titlesort ' => true ,
159
+ 'natsort ' => true ,
160
+ 'current ' => 'simplenavi:namespace123:deep:foo ' ,
161
+ 'expect ' => [
162
+ 'simplenavi:namespace123:namespace123 ' ,
163
+ 'simplenavi:namespace123:deep:start ' ,
164
+ 'simplenavi:namespace123:deep:foo ' ,
165
+ 'simplenavi:namespace123:foo ' ,
166
+ 'simplenavi:namespace2 ' ,
167
+ 'simplenavi:namespace12:start ' ,
168
+ 'simplenavi:namespace21:start ' ,
169
+ 'simplenavi:namespace1:start ' ,
170
+ ]
45
171
];
46
- saveWikiText ('wiki:start ' , 'some text ' , 'Test init ' );
47
- $ response = $ request ->post ($ input );
48
- $ naviBegin = strpos ($ response ->getContent (), '<!-- ********** ASIDE ********** --> ' ) + 36 ;
49
- $ naviEnd = strpos ($ response ->getContent (), '<!-- /aside --> ' );
50
- $ navi = substr ($ response ->getContent (), $ naviBegin , $ naviEnd - $ naviBegin );
51
- $ navilines = explode ("\n" , $ navi );
52
- $ listlines = [];
53
- foreach ($ navilines as $ line ) {
54
- if (substr ($ line , 0 , 4 ) != '<li ' ) continue ;
55
- if (strpos ($ line , 'namespace ' ) === false ) continue ;
56
- $ listlines [] = $ line ;
57
- }
58
172
59
- $ this ->assertTrue (
60
- strpos ($ listlines [0 ], 'href="/./doku.php?id=namespace1:start" ' ) !== false ,
61
- 'namespace1 should be before other namespaces and espacially before its subpages and namespaces '
62
- );
63
- $ this ->assertTrue (
64
- strpos ($ listlines [1 ], 'href="/./doku.php?id=namespace1:foo" ' ) !== false ,
65
- 'level2 should follow open level1 '
66
- );
67
- $ this ->assertTrue (
68
- strpos ($ listlines [2 ], 'href="/./doku.php?id=namespace2:start" ' ) !== false ,
69
- 'namespace2 should be after namespace1 and its pages. '
70
- );
71
- $ this ->assertTrue (
72
- strpos ($ listlines [3 ], 'href="/./doku.php?id=namespace12:start" ' ) !== false ,
73
- 'namespace12 should be after namespace2. '
74
- );
75
- $ this ->assertTrue (
76
- strpos ($ listlines [4 ], 'href="/./doku.php?id=namespace21:start" ' ) !== false ,
77
- 'namespace21 should be after namespace12. '
78
- );
79
- $ this ->assertTrue (
80
- strpos ($ listlines [5 ], 'href="/./doku.php?id=namespace123:start" ' ) !== false ,
81
- 'namespace123 should be after namespace21. '
82
- );
83
173
}
84
174
85
175
/**
86
- * @covers syntax_plugin_simplenavi
176
+ * @dataProvider dataProvider
87
177
*/
88
- public function testOutputAscii ( )
178
+ public function testSorting ( $ set , $ titlesort , $ natsort , $ current , $ expect )
89
179
{
90
- global $ ID , $ conf ;
91
- $ conf ['plugin ' ]['simplenavi ' ]['sort ' ] = 'ascii ' ;
92
-
93
- $ ID = 'wiki:start ' ;
94
- $ request = new TestRequest ();
95
- $ input = [
96
- 'id ' => 'namespace1:foo ' ,
97
- ];
98
- saveWikiText ('wiki:start ' , 'some text ' , 'Test init ' );
99
- $ response = $ request ->post ($ input );
100
- $ naviBegin = strpos ($ response ->getContent (), '<!-- ********** ASIDE ********** --> ' ) + 36 ;
101
- $ naviEnd = strpos ($ response ->getContent (), '<!-- /aside --> ' );
102
- $ navi = substr ($ response ->getContent (), $ naviBegin , $ naviEnd - $ naviBegin );
103
- $ navilines = explode ("\n" , $ navi );
104
- $ listlines = [];
105
- foreach ($ navilines as $ line ) {
106
- if (substr ($ line , 0 , 4 ) != '<li ' ) continue ;
107
- if (strpos ($ line , 'namespace ' ) === false ) continue ;
108
- $ listlines [] = $ line ;
109
- }
110
-
111
- $ this ->assertTrue (
112
- strpos ($ listlines [0 ], 'href="/./doku.php?id=namespace1:start" ' ) !== false ,
113
- 'namespace1 should be before other namespaces and espacially before its subpages and namespaces '
114
- );
115
- $ this ->assertTrue (
116
- strpos ($ listlines [1 ], 'href="/./doku.php?id=namespace1:foo" ' ) !== false ,
117
- 'level2 should follow open level1. '
118
- );
119
- $ this ->assertTrue (
120
- strpos ($ listlines [2 ], 'href="/./doku.php?id=namespace12:start" ' ) !== false ,
121
- 'namespace12 should be after namespace1 and its pages. '
122
- );
123
- $ this ->assertTrue (
124
- strpos ($ listlines [3 ], 'href="/./doku.php?id=namespace123:start" ' ) !== false ,
125
- 'namespace123 should be after namespace12. '
126
- );
127
- $ this ->assertTrue (strpos (
128
- $ listlines [4 ], 'href="/./doku.php?id=namespace2:start" ' ) !== false ,
129
- 'namespace2 should be after namespace123. '
130
- );
131
- $ this ->assertTrue (
132
- strpos ($ listlines [5 ], 'href="/./doku.php?id=namespace21:start" ' ) !== false ,
133
- 'namespace21 should be after namespace2. '
134
- );
180
+ $ simpleNavi = new \syntax_plugin_simplenavi ();
181
+ $ items = $ simpleNavi ->getSortedItems ('simplenavi ' , $ current , $ titlesort , $ natsort );
182
+ $ this ->assertSame ($ expect , array_column ($ items , 'id ' ), $ set );
135
183
}
136
184
137
185
}
0 commit comments