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_ParseToWysiwyg_TextTest extends TikiTestCase
14{
15	private $el = null; // the EditLib
16
17	function setUp()
18	{
19		TikiLib::lib('edit');
20		$this->el = new EditLib();
21	}
22
23
24	function tearDown()
25	{
26		global $prefs;
27		// restore preference default state
28		$prefs['feature_use_three_colon_centertag'] = 'n';
29	}
30
31
32	/**
33	 * Align divs 'left'
34	 *
35	 * @group marked-as-incomplete
36	 */
37	function testBlockAlignLeft()
38	{
39		global $prefs;
40
41		$this->markTestIncomplete('Work in progress.');
42
43		$ex = 'This text is aligned left';
44
45
46		/*
47		 * default
48		 */
49		$inData = 'This text is aligned left';
50		$out = $this->el->parseToWysiwyg($inData);
51		$this->assertEquals($ex, $out);
52
53
54		/*
55		 * explicit
56		 */
57		$ex = '<div style="text-align: left;">This text is aligned left</div>';
58		$inData = '{DIV(align="left")}This text is aligned left{DIV}';
59		$out = $this->el->parseToWysiwyg($inData);
60		$this->assertEquals($ex, $out);
61	}
62
63
64	/**
65	 * Align divs 'center'
66	 *
67	 * @group marked-as-incomplete
68	 */
69	function testBlockAlignCentered()
70	{
71		global $prefs;
72
73		$this->markTestIncomplete('Work in progress.');
74
75
76		/*
77		 * two colon
78		 */
79		$prefs['feature_use_three_colon_centertag'] = 'n';
80		$ex = '<div style="text-align: center;">This text is centered</div>';
81		$inData = '::This text is centered::';
82		$out = $this->el->parseToWysiwyg($inData);
83		$this->assertEquals($ex, $out);
84
85
86		/*
87		 * three colon
88		 */
89		$prefs['feature_use_three_colon_centertag'] = 'y';
90		$ex = '<div style="text-align: center;">This text is centered</div>';
91		$inData = ':::This text is centered:::';
92		$out = $this->el->parseToWysiwyg($inData);
93		$this->assertEquals($ex, $out);
94	}
95
96
97	/**
98	 * Align divs 'right'
99	 *
100	 * @group marked-as-incomplete
101	 */
102	function testBlockAlignRight()
103	{
104		global $prefs;
105
106		$this->markTestIncomplete('Work in progress.');
107
108		$ex = '<div style="text-align: right;">This text is aligned right</div>';
109		$inData = '{DIV(align="right")}This text is aligned right{DIV}';
110		$out = $this->el->parseToWysiwyg($inData);
111		$this->assertEquals($ex, $out);
112	}
113
114
115	/**
116	 * Align divs 'justify'
117	 *
118	 * @group marked-as-incomplete
119	 */
120	function testBlockAlignJustified()
121	{
122		global $prefs;
123
124		$this->markTestIncomplete('Work in progress.');
125
126		$ex = '<div style="text-align: justify;">This text is justified</div>';
127		$inData = '{DIV(align="justify")}This text is justified{DIV}';
128		$out = $this->el->parseToWysiwyg($inData);
129		$this->assertEquals($ex, $out);
130	}
131
132
133	/**
134	 * Align paragraphs 'left'
135	 *
136	 * @group marked-as-incomplete
137	 */
138	function testParagraphAlignLeft()
139	{
140		$this->markTestIncomplete('Work in progress.');
141
142		$ex = '<p style="text-align: left;">This text is aligned</p>';
143		$inData = '{DIV(type="p", align="left")}This text is aligned{DIV}';
144		$out = $this->el->parseToWysiwyg($inData);
145		$this->assertEquals($ex, $out);
146	}
147
148
149	/**
150	 * Centered headings must use style attribute
151	 */
152	function testCenterdHeadings()
153	{
154		global $prefs;
155
156		#
157		# unnumbered
158		#
159		$prefs['feature_use_three_colon_centertag'] = 'n';
160		$prefs['wiki_heading_links'] = 'n';
161		$inData = '!::Heading::';
162		$ex = '<h1 style="text-align: center;" class="showhide_heading" id="Heading">Heading</h1>';
163		$out = trim($this->el->parseToWysiwyg($inData));
164		$this->assertEquals($ex, $out);
165
166		$prefs['feature_use_three_colon_centertag'] = 'y';
167		$inData = '!:::Heading:::';
168		$ex = '<h1 style="text-align: center;" class="showhide_heading" id="Heading">Heading</h1>';
169		$out = trim($this->el->parseToWysiwyg($inData));
170		$this->assertEquals($ex, $out);
171
172
173		/*
174		 * numbered
175		 */
176		$prefs['feature_use_three_colon_centertag'] = 'n';
177		$inData = '!#::Heading::';
178		$ex = '<h1 style="text-align: center;" class="showhide_heading" id="Heading">1. Heading</h1>';
179		$out = trim($this->el->parseToWysiwyg($inData));
180		$this->assertEquals($ex, $out);
181
182		$prefs['feature_use_three_colon_centertag'] = 'y';
183		$inData = '!#:::Heading:::';
184		$ex = '<h1 style="text-align: center;" class="showhide_heading" id="Heading">1. Heading</h1>';
185		$out = trim($this->el->parseToWysiwyg($inData));
186		$this->assertEquals($ex, $out);
187	}
188
189
190	/**
191	 * Headings 1-6
192	 */
193	function testNumberedHeadings()
194	{
195		$inData = '!#Heading Level 1';
196		$ex = '<h1 class="showhide_heading" id="Heading_Level_1">1. Heading Level&nbsp;1</h1>';
197		$out = trim($this->el->parseToWysiwyg($inData));
198		$this->assertEquals($ex, $out);
199
200		$inData .= "\n"; // must keep lover level headings, otherwise we will get an error (undefined number)
201		$inData .= '!!#Heading Level 2';
202		$ex .= "\n";
203		$ex .= '<h2 class="showhide_heading" id="Heading_Level_2">1.1. Heading Level&nbsp;2</h2>';
204		$out = trim($this->el->parseToWysiwyg($inData));
205		$this->assertEquals($ex, $out);
206
207		$inData .= "\n";
208		$inData .= '!!!#Heading Level 3';
209		$ex .= "\n";
210		$ex .= '<h3 class="showhide_heading" id="Heading_Level_3">1.1.1. Heading Level&nbsp;3</h3>';
211		$out = trim($this->el->parseToWysiwyg($inData));
212		$this->assertEquals($ex, $out);
213
214		$inData .= "\n";
215		$inData .= '!!!!#Heading Level 4';
216		$ex .= "\n";
217		$ex .= '<h4 class="showhide_heading" id="Heading_Level_4">1.1.1.1. Heading Level&nbsp;4</h4>';
218		$out = trim($this->el->parseToWysiwyg($inData));
219		$this->assertEquals($ex, $out);
220
221		$inData .= "\n";
222		$inData .= '!!!!!#Heading Level 5';
223		$ex .= "\n";
224		$ex .= '<h5 class="showhide_heading" id="Heading_Level_5">1.1.1.1.1. Heading Level&nbsp;5</h5>';
225		$out = trim($this->el->parseToWysiwyg($inData));
226		$this->assertEquals($ex, $out);
227
228		$inData .= "\n";
229		$inData .= '!!!!!!#Heading Level 6';
230		$ex .= "\n";
231		$ex .= '<h6 class="showhide_heading" id="Heading_Level_6">1.1.1.1.1.1. Heading Level&nbsp;6</h6>';
232		$out = trim($this->el->parseToWysiwyg($inData));
233		$this->assertEquals($ex, $out);
234	}
235
236
237	/**
238	 * Align paragraphs 'center'
239	 *
240	 * @group marked-as-incomplete
241	 */
242	function testParagraphAlignCentered()
243	{
244		$this->markTestIncomplete('Work in progress.');
245
246		$ex = '<p style="text-align: center;">This text is aligned</p>';
247		$inData = '{DIV(type="p", align="center")}This text is aligned{DIV}';
248		$out = $this->el->parseToWysiwyg($inData);
249		$this->assertEquals($ex, $out);
250	}
251
252
253	/**
254	 * Align paragraphs 'right'
255	 *
256	 * @group marked-as-incomplete
257	 */
258	function testParagraphAlignRight()
259	{
260		$this->markTestIncomplete('Work in progress.');
261
262		$ex = '<p style="text-align: right;">This text is aligned</p>';
263		$inData = '{DIV(type="p", align="right")}This text is aligned{DIV}';
264		$out = $this->el->parseToWysiwyg($inData);
265		$this->assertEquals($ex, $out);
266	}
267
268
269	/**
270	 * Align paragraphs 'justify'
271	 *
272	 * @group marked-as-incomplete
273	 */
274	function testParagraphAlignJustified()
275	{
276		$this->markTestIncomplete('Work in progress.');
277
278		$ex = '<p style="text-align: justify;">This text is aligned</p>';
279		$inData = '{DIV(type="p", align="justify")}This text is aligned{DIV}';
280		$out = $this->el->parseToWysiwyg($inData);
281		$this->assertEquals($ex, $out);
282	}
283
284
285	/**
286	 * Headings 1-6
287	 */
288	function testUnnumberedHeadings()
289	{
290		$inData = '!Heading Level 1';
291		$ex = '<h1 class="showhide_heading" id="Heading_Level_1">Heading Level&nbsp;1</h1>';
292		$out = trim($this->el->parseToWysiwyg($inData));
293		$this->assertEquals($ex, $out);
294
295		$inData = '!!Heading Level 2';
296		$ex = '<h2 class="showhide_heading" id="Heading_Level_2">Heading Level&nbsp;2</h2>';
297		$out = trim($this->el->parseToWysiwyg($inData));
298		$this->assertEquals($ex, $out);
299
300		$inData = '!!!Heading Level 3';
301		$ex = '<h3 class="showhide_heading" id="Heading_Level_3">Heading Level&nbsp;3</h3>';
302		$out = trim($this->el->parseToWysiwyg($inData));
303		$this->assertEquals($ex, $out);
304
305		$inData = '!!!!Heading Level 4';
306		$ex = '<h4 class="showhide_heading" id="Heading_Level_4">Heading Level&nbsp;4</h4>';
307		$out = trim($this->el->parseToWysiwyg($inData));
308		$this->assertEquals($ex, $out);
309
310		$inData = '!!!!!Heading Level 5';
311		$ex = '<h5 class="showhide_heading" id="Heading_Level_5">Heading Level&nbsp;5</h5>';
312		$out = trim($this->el->parseToWysiwyg($inData));
313		$this->assertEquals($ex, $out);
314
315		$inData = '!!!!!!Heading Level 6';
316		$ex = '<h6 class="showhide_heading" id="Heading_Level_6">Heading Level&nbsp;6</h6>';
317		$out = trim($this->el->parseToWysiwyg($inData));
318		$this->assertEquals($ex, $out);
319	}
320}
321