2
2
3
3
require_once DOKU_INC . 'inc/parser/xhtml.php ' ;
4
4
5
+ class Doku_Renderer_xhtml_mock extends Doku_Renderer_xhtml {
6
+
7
+ function internallink ($ id , $ name = null , $ search = null , $ returnonly = false , $ linktype = 'content ' ) {
8
+ $ inputvalues = array (
9
+ 'id ' => $ id ,
10
+ 'name ' => $ name ,
11
+ 'search ' => $ search ,
12
+ 'returnonly ' => $ returnonly ,
13
+ 'linktype ' => $ linktype
14
+ );
15
+ return "<internallink> " . serialize ($ inputvalues ) . "</internallink> " ;
16
+ }
17
+ }
18
+
5
19
/**
6
20
* @group plugin_data
7
21
* @group plugins
@@ -12,6 +26,10 @@ class syntax_plugin_data_entry_test extends DokuWikiTest {
12
26
13
27
private $ exampleEntry ;
14
28
29
+ public function setUp () {
30
+ parent ::setUp ();
31
+ }
32
+
15
33
function __construct () {
16
34
$ this ->exampleEntry = "---- dataentry projects ---- \n"
17
35
. "type : web development \n"
@@ -65,36 +83,131 @@ function testHandle() {
65
83
$ this ->assertEquals ($ cols , $ result ['cols ' ], 'Cols array corrupted ' );
66
84
}
67
85
86
+ function test_pageEntry_noTitle () {
87
+ $ test_entry = '---- dataentry ----
88
+ test1_page: foo
89
+ ---- ' ;
90
+
91
+ /** @var syntax_plugin_data_entry $plugin */
92
+ $ plugin = plugin_load ('syntax ' ,'data_entry ' );
93
+
94
+ $ handler = new Doku_Handler ();
95
+ $ data = $ plugin ->handle ($ test_entry , 0 , 10 , $ handler );
96
+ $ renderer = new Doku_Renderer_xhtml_mock ();
97
+ $ plugin ->render ('xhtml ' ,$ renderer ,$ data );
98
+ $ result = $ renderer ->doc ;
99
+ $ result = substr ($ result ,0 ,strpos ($ result ,'</internallink> ' ));
100
+ $ result = substr ($ result ,strpos ($ result ,'<internallink> ' )+14 );
101
+ $ result = unserialize ($ result );
102
+
103
+ $ this ->assertSame (':foo ' ,$ result ['id ' ]);
104
+ $ this ->assertSame (null ,$ result ['name ' ], 'page does not accept a title. useheading decides ' );
105
+ }
106
+
107
+ function test_pageEntry_withTitle () {
108
+ $ test_entry = '---- dataentry ----
109
+ test1_page: foo|bar
110
+ ---- ' ;
111
+
112
+ /** @var syntax_plugin_data_entry $plugin */
113
+ $ plugin = plugin_load ('syntax ' ,'data_entry ' );
114
+
115
+ $ handler = new Doku_Handler ();
116
+ $ data = $ plugin ->handle ($ test_entry , 0 , 10 , $ handler );
117
+ $ renderer = new Doku_Renderer_xhtml_mock ();
118
+ $ plugin ->render ('xhtml ' ,$ renderer ,$ data );
119
+ $ result = $ renderer ->doc ;
120
+ $ result = substr ($ result ,0 ,strpos ($ result ,'</internallink> ' ));
121
+ $ result = substr ($ result ,strpos ($ result ,'<internallink> ' )+14 );
122
+ $ result = unserialize ($ result );
123
+
124
+ $ this ->assertSame (':foo_bar ' ,$ result ['id ' ], 'for type page a title becomes part of the id ' );
125
+ $ this ->assertSame (null ,$ result ['name ' ], 'page never accepts a title. useheading decides ' );
126
+ }
127
+
128
+ function test_pageidEntry_noTitle () {
129
+ $ test_entry = '---- dataentry ----
130
+ test1_pageid: foo
131
+ ---- ' ;
132
+
133
+ /** @var syntax_plugin_data_entry $plugin */
134
+ $ plugin = plugin_load ('syntax ' ,'data_entry ' );
135
+
136
+ $ handler = new Doku_Handler ();
137
+ $ data = $ plugin ->handle ($ test_entry , 0 , 10 , $ handler );
138
+ $ renderer = new Doku_Renderer_xhtml_mock ();
139
+ $ plugin ->render ('xhtml ' ,$ renderer ,$ data );
140
+ $ result = $ renderer ->doc ;
141
+ $ result = substr ($ result ,0 ,strpos ($ result ,'</internallink> ' ));
142
+ $ result = substr ($ result ,strpos ($ result ,'<internallink> ' )+14 );
143
+ $ result = unserialize ($ result );
144
+
145
+ $ this ->assertSame ('foo ' ,$ result ['id ' ]);
146
+ $ this ->assertSame ('foo ' ,$ result ['name ' ], 'pageid: use the pageid as title if no title is provided. ' );
147
+ }
148
+
149
+ function test_pageidEntry_withTitle () {
150
+ $ test_entry = '---- dataentry ----
151
+ test1_pageid: foo|bar
152
+ ---- ' ;
153
+
154
+ /** @var syntax_plugin_data_entry $plugin */
155
+ $ plugin = plugin_load ('syntax ' ,'data_entry ' );
156
+
157
+ $ handler = new Doku_Handler ();
158
+ $ data = $ plugin ->handle ($ test_entry , 0 , 10 , $ handler );
159
+ $ renderer = new Doku_Renderer_xhtml_mock ();
160
+ $ plugin ->render ('xhtml ' ,$ renderer ,$ data );
161
+ $ result = $ renderer ->doc ;
162
+ $ result = substr ($ result ,0 ,strpos ($ result ,'</internallink> ' ));
163
+ $ result = substr ($ result ,strpos ($ result ,'<internallink> ' )+14 );
164
+ $ result = unserialize ($ result );
165
+
166
+ $ this ->assertSame ('foo ' ,$ result ['id ' ], "wrong id handed to internal link " );
167
+ $ this ->assertSame ('bar ' ,$ result ['name ' ], 'pageid: use the provided title ' );
168
+ }
169
+
68
170
function test_titleEntry_noTitle () {
69
171
$ test_entry = '---- dataentry ----
70
- test_title: bar
172
+ test1_title: foo
71
173
---- ' ;
72
- $ plugin = new syntax_plugin_data_entry ();
174
+
175
+ /** @var syntax_plugin_data_entry $plugin */
176
+ $ plugin = plugin_load ('syntax ' ,'data_entry ' );
73
177
74
178
$ handler = new Doku_Handler ();
75
179
$ data = $ plugin ->handle ($ test_entry , 0 , 10 , $ handler );
76
- $ renderer = new Doku_Renderer_xhtml ();
180
+ $ renderer = new Doku_Renderer_xhtml_mock ();
77
181
$ plugin ->render ('xhtml ' ,$ renderer ,$ data );
78
182
$ result = $ renderer ->doc ;
79
- $ result = substr ($ result ,0 ,strpos ($ result ,'</a> ' )+4 );
80
- $ result = substr ($ result ,strpos ($ result ,'<a ' ));
81
- $ this ->assertSame ('<a href="/./doku.php?id=bar" class="wikilink2" title="bar" rel="nofollow">bar</a> ' ,$ result );
183
+ $ result = substr ($ result ,0 ,strpos ($ result ,'</internallink> ' ));
184
+ $ result = substr ($ result ,strpos ($ result ,'<internallink> ' )+14 );
185
+ $ result = unserialize ($ result );
186
+
187
+ $ this ->assertSame (':foo ' ,$ result ['id ' ]);
188
+ $ this ->assertSame (null ,$ result ['name ' ], 'no title should be given to internal link. Let useheading decide. ' );
82
189
}
83
190
191
+
84
192
function test_titleEntry_withTitle () {
85
193
$ test_entry = '---- dataentry ----
86
- test_title : link:to:page|TitleOfPage
194
+ test3_title : link:to:page|TitleOfPage
87
195
---- ' ;
88
- $ plugin = new syntax_plugin_data_entry ();
196
+
197
+ /** @var syntax_plugin_data_entry $plugin */
198
+ $ plugin = plugin_load ('syntax ' ,'data_entry ' );
89
199
90
200
$ handler = new Doku_Handler ();
91
201
$ data = $ plugin ->handle ($ test_entry , 0 , 10 , $ handler );
92
- $ renderer = new Doku_Renderer_xhtml ();
202
+ $ renderer = new Doku_Renderer_xhtml_mock ();
93
203
$ plugin ->render ('xhtml ' ,$ renderer ,$ data );
94
204
$ result = $ renderer ->doc ;
95
- $ result = substr ($ result ,0 ,strpos ($ result ,'</a> ' )+4 );
96
- $ result = substr ($ result ,strpos ($ result ,'<a ' ));
97
- $ this ->assertSame ('<a href="/./doku.php?id=link:to:page" class="wikilink2" title="link:to:page" rel="nofollow">TitleOfPage</a> ' ,$ result );
205
+ $ result = substr ($ result ,0 ,strpos ($ result ,'</internallink> ' ));
206
+ $ result = substr ($ result ,strpos ($ result ,'<internallink> ' )+14 );
207
+ $ result = unserialize ($ result );
208
+
209
+ $ this ->assertSame (':link:to:page ' ,$ result ['id ' ]);
210
+ $ this ->assertSame ('TitleOfPage ' ,$ result ['name ' ], 'The Title provided should be the title shown. ' );
98
211
}
99
212
100
213
function test_editToWiki () {
0 commit comments