1<?php
2/**
3 * @group plugin_definitionlist
4 */
5class plugin_definitionlist_syntax_test extends DokuWikiTest {
6
7    protected $pluginsEnabled = array('definitionlist');
8    protected $renderer = null;
9
10    function setUp() {
11        parent::setUp();
12
13        $this->renderer = new Doku_Renderer_xhtml();
14    }
15
16    protected function render($rawwiki,$format='xhtml') {
17        $instructions = p_get_instructions($rawwiki);
18        return p_render($format, $instructions, $info);
19    }
20
21    function test_basic_singleline() {
22        $in = NL.'  ; Term : Definition'.NL;
23        $expected = '<dl class="plugin_definitionlist">'.NL
24                   .'<dt><span class="term"> Term</span></dt>'.NL
25                   .'<dd>Definition</dd>'.NL
26                   .'</dl>'.NL;
27
28        $this->assertEquals($expected, $this->render($in));
29    }
30
31    function test_basic_multiline() {
32        $in = NL.'  ; Term'.NL
33                .'  : Definition'.NL;
34        $expected = '<dl class="plugin_definitionlist">'.NL
35                   .'<dt><span class="term"> Term</span></dt>'.NL
36                   .'<dd> Definition</dd>'.NL
37                   .'</dl>'.NL;
38
39        $this->assertEquals($expected, $this->render($in));
40    }
41
42    function test_multiple_definitions() {
43        $in = NL.'  ; Term'.NL
44                .'  : Definition one'.NL
45                .'  : Definition two'.NL;
46        $expected = '<dl class="plugin_definitionlist">'.NL
47                   .'<dt><span class="term"> Term</span></dt>'.NL
48                   .'<dd> Definition one</dd>'.NL
49                   .'<dd> Definition two</dd>'.NL
50                   .'</dl>'.NL;
51
52        $this->assertEquals($expected, $this->render($in));
53    }
54
55    function test_newline_in_definition() {
56        $in = NL.'  ; Term'.NL
57                .'  : Definition one'.NL
58                .'continues'.NL;
59        $expected = '<dl class="plugin_definitionlist">'.NL
60                   .'<dt><span class="term"> Term</span></dt>'.NL
61                   .'<dd> Definition one'.NL
62                   .'continues</dd>'.NL
63                   .'</dl>'.NL;
64
65        $this->assertEquals($expected, $this->render($in));
66    }
67
68    function test_newline_in_definition_with_following_para() {
69        $in = NL.'  ; Term'.NL
70                .'  : Definition one'.NL
71                .'continues'.NL
72                .NL
73                .'Then new paragraph.'.NL;
74        $expected = '<dl class="plugin_definitionlist">'.NL
75                   .'<dt><span class="term"> Term</span></dt>'.NL
76                   .'<dd> Definition one'.NL
77                   .'continues</dd>'.NL
78                   .'</dl>'.NL
79                   .NL
80                   .'<p>'.NL
81                   .'Then new paragraph.'.NL
82                   .'</p>'.NL;
83
84        $this->assertEquals($expected, $this->render($in));
85    }
86
87    function test_basic_with_following_preformatted() {
88        $in = NL.'  ; Term'.NL
89                .'  : Definition'.NL
90                .NL
91                .'  Preformatted'.NL;
92        $expected = '<dl class="plugin_definitionlist">'.NL
93                   .'<dt><span class="term"> Term</span></dt>'.NL
94                   .'<dd> Definition</dd>'.NL
95                   .'</dl>'.NL
96                   .'<pre class="code">Preformatted</pre>'.NL;
97
98        $this->assertEquals($expected, $this->render($in));
99    }
100
101    function test_nonfancy() {
102        global $conf;
103        $conf['plugin']['definitionlist']['dt_fancy'] = 0;
104
105        $in1 = NL.'  ; Term'.NL
106                 .'  : Definition'.NL;
107        $in2 = NL.'  ; Term : Definition'.NL;
108        $expected1 = '<dl class="plugin_definitionlist">'.NL
109                   .'<dt> Term</dt>'.NL
110                   .'<dd> Definition</dd>'.NL
111                   .'</dl>'.NL;
112        $expected2 = '<dl class="plugin_definitionlist">'.NL
113                   .'<dt> Term</dt>'.NL
114                   .'<dd>Definition</dd>'.NL
115                   .'</dl>'.NL;
116
117
118        $this->assertEquals($expected1, $this->render($in1));
119        $this->assertEquals($expected2, $this->render($in2));
120    }
121
122    function test_custom_class_name() {
123        global $conf;
124        $conf['plugin']['definitionlist']['classname'] = 'foo';
125
126        $in = NL.'  ; Term'.NL
127                .'  : Definition'.NL;
128        $expected = '<dl class="foo">'.NL
129                   .'<dt><span class="term"> Term</span></dt>'.NL
130                   .'<dd> Definition</dd>'.NL
131                   .'</dl>'.NL;
132
133
134        $this->assertEquals($expected, $this->render($in));
135    }
136
137    function test_two_dlists_with_blank_line_between() {
138        $in = NL.'  ; Term : Definition'.NL
139             .NL.'  ; Another term : Def'.NL;
140        $expected = '<dl class="plugin_definitionlist">'.NL
141                   .'<dt><span class="term"> Term</span></dt>'.NL
142                   .'<dd>Definition</dd>'.NL
143                   .'</dl>'.NL
144                   .'<dl class="plugin_definitionlist">'.NL
145                   .'<dt><span class="term"> Another term</span></dt>'.NL
146                   .'<dd>Def</dd>'.NL
147                   .'</dl>'.NL;
148
149        $this->assertEquals($expected, $this->render($in));
150    }
151
152    function test_dd_with_ul() {
153        $in = NL.'  ; Term'.NL
154                .'  : Some parts:'.NL
155                .'  * Part 1'.NL
156                .'  * Part 2'.NL
157                .NL
158                .'  ; Term 2'.NL
159                .'  : Def'.NL;
160        $expected = '<dl class="plugin_definitionlist">'.NL
161                   .'<dt><span class="term"> Term</span></dt>'.NL
162                   .'<dd> Some parts:<ul>'.NL
163                   .'<li class="level1"><div class="li"> Part 1</div>'.NL
164                   .'</li>'.NL
165                   .'<li class="level1"><div class="li"> Part 2</div>'.NL
166                   .'</li>'.NL
167                   .'</ul>'.NL
168                   .'</dd>'.NL
169                   .'<dt><span class="term"> Term 2</span></dt>'.NL
170                   .'<dd> Def</dd>'.NL
171                   .'</dl>'.NL;
172
173        $this->assertEquals($expected, $this->render($in));
174    }
175
176    function test_dd_with_ul_followed_by_ordered_list() {
177        $in = NL.'  ; Term'.NL
178                .'  : Some parts:'.NL
179                .'  * Part 1'.NL
180                .'  * Part 2'.NL
181                .NL
182                .NL
183                .'  - Item'.NL;
184        $expected = '<dl class="plugin_definitionlist">'.NL
185                   .'<dt><span class="term"> Term</span></dt>'.NL
186                   .'<dd> Some parts:<ul>'.NL
187                   .'<li class="level1"><div class="li"> Part 1</div>'.NL
188                   .'</li>'.NL
189                   .'<li class="level1"><div class="li"> Part 2</div>'.NL
190                   .'</li>'.NL
191                   .'</ul>'.NL
192                   .'</dd>'.NL
193                   .'</dl>'.NL
194                   .'<ol>'.NL
195                   .'<li class="level1"><div class="li"> Item</div>'.NL
196                   .'</li>'.NL
197                   .'</ol>'.NL;
198
199        $this->assertEquals($expected, $this->render($in));
200    }
201
202    function test_dd_with_ul_followed_by_2nd_dl() {
203        $in = NL.'  ; Term'.NL
204                .'  : Some parts:'.NL
205                .'  * Part 1'.NL
206                .'  * Part 2'.NL
207                .NL
208                .NL
209                .'  ; Term 2'.NL
210                .'  : Def'.NL;
211        $expected = '<dl class="plugin_definitionlist">'.NL
212                   .'<dt><span class="term"> Term</span></dt>'.NL
213                   .'<dd> Some parts:<ul>'.NL
214                   .'<li class="level1"><div class="li"> Part 1</div>'.NL
215                   .'</li>'.NL
216                   .'<li class="level1"><div class="li"> Part 2</div>'.NL
217                   .'</li>'.NL
218                   .'</ul>'.NL
219                   .'</dd>'.NL
220                   .'</dl>'.NL
221                   .'<dl class="plugin_definitionlist">'.NL
222                   .'<dt><span class="term"> Term 2</span></dt>'.NL
223                   .'<dd> Def</dd>'.NL
224                   .'</dl>'.NL;
225
226        $this->assertEquals($expected, $this->render($in));
227    }
228
229}
230