1<?php
2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
3//
4// All Rights Reserved. See copyright.txt for details and a complete list of authors.
5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
6// $Id$
7
8/**
9 * @group unit
10 *
11 */
12
13class EditLib_ParseToWiki_CharacterTest extends TikiTestCase
14{
15
16	private $el = null; // the EditLib
17
18
19	function setUp()
20	{
21		TikiLib::lib('edit');
22		$this->el = new EditLib();
23	}
24
25
26	function tearDown()
27	{
28	}
29
30
31	/**
32	 * Font Family and Font Size
33	 *
34	 * => {FONT(family="tahoma", size="12pt")}text{FONT}
35	 * - 'font-family'
36	 * - 'font-size'
37	 *
38	 * @group marked-as-incomplete
39	 */
40	function testFontFamily()
41	{
42		$this->markTestIncomplete('Work in progress.');
43
44		/*
45		 * family
46		 */
47		$ex = '{FONT(family="tahoma")}text{FONT}';
48		$inData = '<span style="font-family:tahoma;">text<span>';
49		$out = $this->el->parseToWiki($inData);
50		$this->assertEquals($ex, $out);
51
52
53		/*
54		 * size
55		 */
56		$ex = '{FONT(size="12px")}text{FONT}';
57		$inData = '<span style="font-size:12px;">text<span>';
58		$out = $this->el->parseToWiki($inData);
59		$this->assertEquals($ex, $out);
60
61		$ex = '{FONT(size="12pt")}text{FONT}';
62		$inData = '<span style="font-size:12pt;">text<span>';
63		$out = $this->el->parseToWiki($inData);
64		$this->assertEquals($ex, $out);
65
66		$ex = '{FONT(size="1.2em")}text{FONT}';
67		$inData = '<span style="font-size:1.2em;">text<span>';
68		$out = $this->el->parseToWiki($inData);
69		$this->assertEquals($ex, $out);
70
71
72		/*
73		 * family and size
74		 */
75		$ex = '{FONT(family="tahoma", size="12pt")}';
76		$inData = '<span style="font-family=tahoma";font-size:1.2pt;">text<span>';
77		$out = $this->el->parseToWiki($inData);
78		$this->assertEquals($ex, $out);
79	}
80
81
82	/**
83	 * Bold
84	 *
85	 * => __
86	 * - <b>
87	 * - <strong>
88	 * - 'font-weight:bold'
89	 */
90	function testBold()
91	{
92
93		// simple
94		$ex = '__bold__';
95
96		$inData = '<b>bold</b>';
97		$out = $this->el->parseToWiki($inData);
98		$this->assertEquals($ex, $out);
99
100		$inData = '<strong>bold</strong>';
101		$out = $this->el->parseToWiki($inData);
102		$this->assertEquals($ex, $out);
103
104		$inData = '<span style="font-weight:bold;">bold</span>';
105		$out = $this->el->parseToWiki($inData);
106		$this->assertEquals($ex, $out);
107
108		// line break
109		$ex = '__bold__\n__BOLD__regular';
110
111		$inData = '<b>bold<br />BOLD</b>regular';
112		$out = $this->el->parseToWiki($inData);
113		$out = preg_replace('/\n/', '\n', $out); // fix LF encoding for comparison
114		$this->assertEquals($ex, $out);
115
116		$inData = '<strong>bold<br />BOLD</strong>regular';
117		$out = $this->el->parseToWiki($inData);
118		$out = preg_replace('/\n/', '\n', $out); // fix LF encoding for comparison
119		$this->assertEquals($ex, $out);
120
121		$inData = '<span style="font-weight:bold;">bold<br />BOLD</span>regular';
122		$out = $this->el->parseToWiki($inData);
123		$out = preg_replace('/\n/', '\n', $out); // fix LF encoding for comparison
124		$this->assertEquals($ex, $out);
125	}
126
127
128	/**
129	 * Italic
130	 *
131	 * => ''
132	 * - <em>
133	 * - <i>
134	 * - 'font-style:italic'
135	 */
136	function testItalic()
137	{
138
139		$ex = '\'\'italic\'\'';
140
141		$inData = '<em>italic</em>';
142		$out = $this->el->parseToWiki($inData);
143		$this->assertEquals($ex, $out);
144
145		$inData = '<i>italic</i>';
146		$out = $this->el->parseToWiki($inData);
147		$this->assertEquals($ex, $out);
148
149		$inData = '<span style="font-style:italic;">italic</span>';
150		$out = $this->el->parseToWiki($inData);
151		$this->assertEquals($ex, $out);
152
153		// line break
154		$ex = '\'\'italic\'\'\n\'\'ITALIC\'\'regular';
155
156		$inData = '<em>italic<br />ITALIC</em>regular';
157		$out = $this->el->parseToWiki($inData);
158		$out = preg_replace('/\n/', '\n', $out); // fix LF encoding for comparison
159		$this->assertEquals($ex, $out);
160
161		$inData = '<i>italic<br />ITALIC</i>regular';
162		$out = $this->el->parseToWiki($inData);
163		$out = preg_replace('/\n/', '\n', $out); // fix LF encoding for comparison
164		$this->assertEquals($ex, $out);
165
166		$inData = '<span style="font-style:italic;">italic<br />ITALIC</span>regular';
167		$out = $this->el->parseToWiki($inData);
168		$out = preg_replace('/\n/', '\n', $out); // fix LF encoding for comparison
169		$this->assertEquals($ex, $out);
170	}
171
172
173	/**
174	 * Underlined
175	 *
176	 * => ===
177	 * - <u>
178	 * - 'text-decoration:underline'
179	 */
180	function testUnderlined()
181	{
182
183		$ex = '===underlined===';
184
185		$inData = '<u>underlined</u>';
186		$out = $this->el->parseToWiki($inData);
187		$this->assertEquals($ex, $out);
188
189		$inData = '<span style="text-decoration:underline;">underlined</span>';
190		$out = $this->el->parseToWiki($inData);
191		$this->assertEquals($ex, $out);
192
193		// line break
194		$ex = '===underlined===\n===UNDERLINED===';
195
196		$inData = '<u>underlined<br />UNDERLINED</u>';
197		$out = $this->el->parseToWiki($inData);
198		$out = preg_replace('/\n/', '\n', $out); // fix LF encoding for comparison
199		$this->assertEquals($ex, $out);
200
201		$inData = '<span style="text-decoration:underline;">underlined<br />UNDERLINED</span>';
202		$out = $this->el->parseToWiki($inData);
203		$out = preg_replace('/\n/', '\n', $out); // fix LF encoding for comparison
204		$this->assertEquals($ex, $out);
205	}
206
207
208	/**
209	 * Strikethrough
210	 *
211	 * => --
212	 * - <strike>
213	 * - <del>
214	 * - <s>
215	 * - 'text-decoration:line-through'
216	 */
217	function testStrikethrough()
218	{
219
220		$ex = '--strikethrough--';
221
222		$inData = '<strike>strikethrough</strike>';
223		$out = $this->el->parseToWiki($inData);
224		$this->assertEquals($ex, $out);
225
226		$inData = '<del>strikethrough</del>';
227		$out = $this->el->parseToWiki($inData);
228		$this->assertEquals($ex, $out);
229
230		$inData = '<s>strikethrough</s>';
231		$out = $this->el->parseToWiki($inData);
232		$this->assertEquals($ex, $out);
233
234		$inData = '<span style="text-decoration:line-through;">strikethrough</span>';
235		$out = $this->el->parseToWiki($inData);
236		$this->assertEquals($ex, $out);
237
238		// line break
239		$ex = '--strikethrough--\n--STRIKETHROUGH--';
240
241		$inData = '<strike>strikethrough<br />STRIKETHROUGH</strike>';
242		$out = $this->el->parseToWiki($inData);
243		$out = preg_replace('/\n/', '\n', $out); // fix LF encoding for comparison
244		$this->assertEquals($ex, $out);
245
246		$inData = '<del>strikethrough<br />STRIKETHROUGH</del>';
247		$out = $this->el->parseToWiki($inData);
248		$out = preg_replace('/\n/', '\n', $out); // fix LF encoding for comparison
249		$this->assertEquals($ex, $out);
250
251		$inData = '<s>strikethrough<br />STRIKETHROUGH</s>';
252		$out = $this->el->parseToWiki($inData);
253		$out = preg_replace('/\n/', '\n', $out); // fix LF encoding for comparison
254		$this->assertEquals($ex, $out);
255
256		$inData = '<strike>strikethrough<br />STRIKETHROUGH</strike>';
257		$out = $this->el->parseToWiki($inData);
258		$out = preg_replace('/\n/', '\n', $out); // fix LF encoding for comparison
259		$this->assertEquals($ex, $out);
260	}
261
262
263
264	/**
265	 * Subscript
266	 *
267	 * => {SUB()}
268	 * - <sub>
269	 */
270	function testSubscript()
271	{
272
273		$ex = '{SUB()}subscript{SUB}';
274
275		$inData = '<sub>subscript</sub>';
276		$out = $this->el->parseToWiki($inData);
277		$this->assertEquals($ex, $out);
278	}
279
280
281	/**
282	 * Superscript
283	 *
284	 * => {SUP()}
285	 * - <sup>
286	 */
287	function testSuperscript()
288	{
289
290		$ex = '{SUP()}subscript{SUP}';
291
292		$inData = '<sup>subscript</sup>';
293		$out = $this->el->parseToWiki($inData);
294		$this->assertEquals($ex, $out);
295	}
296
297
298	/**
299	 * Monospaced
300	 *
301	 * => -+
302	 * - <code>
303	 *
304	 * @group marked-as-incomplete
305	 */
306	function testMonospace()
307	{
308
309		$ex = '-+monospaced+-';
310
311		$inData = '<code>monospaced</code>';
312		$out = $this->el->parseToWiki($inData);
313		$this->assertEquals($ex, $out);
314
315		// line break
316		$this->markTestIncomplete('Work in progress.');
317		$ex = '-+monospaced+-\n-+MONOSPACED+-';
318		$inData = '<code>monospaced<br />MONOSPACED</code>';
319		$out = $this->el->parseToWiki($inData);
320		$this->assertEquals($ex, $out);
321	}
322
323
324	/**
325	 * Teletype
326	 *
327	 * => {DIV(type="tt")}
328	 * - <tt>
329	 */
330	function testTeletype()
331	{
332
333		$ex = '{DIV(type="tt")}typewriter{DIV}';
334
335		$inData = '<tt>typewriter</tt>';
336		$out = $this->el->parseToWiki($inData);
337		$this->assertEquals($ex, $out);
338	}
339
340
341	/**
342	 * Text and background color
343	 *
344	 * => ~~
345	 * - 'background'
346	 * - 'background-color'
347	 */
348	function testColor()
349	{
350
351		/*
352		 * text only
353		 */
354		$ex = '~~#FF0000:color~~';
355
356		$inData = '<span style="color:#FF0000;">color</span>';
357		$out = $this->el->parseToWiki($inData);
358		$this->assertEquals($ex, $out);
359
360
361		/*
362		 * background only
363		 */
364		$ex = '~~ ,#FFFF00:color~~';
365
366		$inData = '<span style="background:#FFFF00;">color</span>';
367		$out = $this->el->parseToWiki($inData);
368		$this->assertEquals($ex, $out);
369
370		$inData = '<span style="background-color:#FFFF00;">color</span>';
371		$out = $this->el->parseToWiki($inData);
372		$this->assertEquals($ex, $out);
373
374
375		/*
376		 * text and background
377		 */
378		$ex = '~~#FF0000,#0000FF:color~~';
379
380		$inData = '<span style="color:rgb(255, 0, 0);background-color:rgb(0, 0, 255);">color</span>';
381		$out = $this->el->parseToWiki($inData);
382		$this->assertEquals($ex, $out);
383
384		$inData = '<span style="color:#FF0000;background-color:#0000FF;">color</span>';
385		$out = $this->el->parseToWiki($inData);
386		$this->assertEquals($ex, $out);
387
388		$inData = '<span style="color:#FF0000;background:#0000FF;">color</span>';
389		$out = $this->el->parseToWiki($inData);
390		$this->assertEquals($ex, $out);
391
392		$inData = '<span style="background-color:#0000FF;color:#FF0000;">color</span>';
393		$out = $this->el->parseToWiki($inData);
394		$this->assertEquals($ex, $out);
395
396		$inData = '<span style="background:#0000FF;color:#FF0000;">color</span>';
397		$out = $this->el->parseToWiki($inData);
398		$this->assertEquals($ex, $out);
399
400
401		/*
402		 * line break
403		 */
404		$ex = '~~#FF0000,#0000FF:color text 1~~\n~~#FF0000,#0000FF:color text 2~~';
405
406		$inData = '<span style="color:rgb(255, 0, 0);background-color:rgb(0, 0, 255);">color text 1<br />color text 2</span>';
407		$out = $this->el->parseToWiki($inData);
408		$out = preg_replace('/\n/', '\n', $out); // fix LF encoding for comparison
409		$this->assertEquals($ex, $out);
410	}
411}
412