Fixing content type ordering when content_type is not defined.
[akelos.git] / test / unit / lib / AkActionView / helpers / text_helper.php
blob4b23dfb1dc5cd7444e123a3ff06cc83abd33434c
1 <?php
3 require_once('_HelpersUnitTester.php');
4 require_once(AK_LIB_DIR.DS.'AkActionView'.DS.'helpers'.DS.'asset_tag_helper.php');
5 require_once(AK_LIB_DIR.DS.'AkActionView'.DS.'helpers'.DS.'text_helper.php');
6 require_once(AK_LIB_DIR.DS.'AkActionView'.DS.'helpers'.DS.'tag_helper.php');
9 class TextHelperTests extends HelpersUnitTester
12 function SetUp()
14 $this->text = new TextHelper();
17 function test_truncate()
19 // normal with 10 char limit
20 $this->assertEqual($this->text->truncate('truncates the last ten characters', 10), 'truncat...');
22 //limit of 3 characters
23 $this->assertEqual($this->text->truncate('truncates', 3), '...');
25 //less of the limit of 3 characters
26 $this->assertEqual($this->text->truncate('truncates', 2), 'truncates');
28 //with an empty truncate_string
29 $this->assertEqual($this->text->truncate('truncates', 5, ''), 'trunc');
31 //with a break position greater than the limit
32 $this->assertEqual($this->text->truncate('0123456789_0',8,'...', '_'), '01234...');
34 //with a break position lesser than the limit
35 $this->assertEqual($this->text->truncate('0123_567890',8,'...', '_'), '0...');
37 //with a break position lesser than the truncate string length
38 $this->assertEqual($this->text->truncate('0_123567890',8,'...', '_'), '0_123567890');
41 function test_highlight()
43 $this->assertEqual($this->text->highlight('I am highlighting the phrase','highlighting'),'I am <strong class="highlight">highlighting</strong> the phrase');
44 $this->assertEqual($this->text->highlight('I am highlighting the phrase',array('highlighting','the')),'I am <strong class="highlight">highlighting</strong> <strong class="highlight">the</strong> phrase');
45 $this->assertEqual($this->text->highlight('I am highlighting the phrase','highlighting', '<span class="my_highlight">\1</span>'),'I am <span class="my_highlight">highlighting</span> the phrase');
48 function test_excerpt()
50 $this->assertEqual($this->text->excerpt("hello my world", "my", 3),'...lo my wo...');
51 $this->assertEqual($this->text->excerpt("hello my world", "my", 5,'---'),'---ello my worl---');
52 $this->assertEqual($this->text->excerpt("hello my world", "my", 0),'...my...');
55 function test_pluralize()
57 $this->assertEqual($this->text->pluralize(0, 'Property', 'Properties'),'Properties');
58 $this->assertEqual($this->text->pluralize(1, 'Property'),'Property');
59 $this->assertEqual($this->text->pluralize(2, 'Property'),'Properties');
60 $this->assertEqual($this->text->pluralize(2, 'Address'),'Addresses');
61 $this->assertEqual($this->text->pluralize(2, 'Son'),'Sons');
64 function test_word_wrap()
66 $this->assertEqual($this->text->word_wrap('Wraps a string to a given number of characters', 20),"Wraps a string to a\ngiven number of\ncharacters");
68 function test_format()
70 $this->assertEqual($this->text->format('Format this string which is very long and need to be formated !!!')," Format this string which is very long and need to be formated !!!\n\n");
73 function test_textilize()
75 $this->assertEqual($this->text->textilize('__Wraps__'),'<p><i>Wraps</i></p>');
76 $this->assertEqual($this->text->textilize('_Wraps_'),'<p><em>Wraps</em></p>');
77 $this->assertEqual($this->text->textilize('p[no]. paragraph'),'<p lang="no">paragraph</p>');
78 $this->assertEqual($this->text->textilize('h3{color:red}. header 3'),'<h3 style="color:red;">header 3</h3>');
81 function test_textilize_without_paragraph()
83 $this->assertEqual($this->text->textilize_without_paragraph('__Wraps__'),'<i>Wraps</i>');
84 $this->assertEqual($this->text->textilize_without_paragraph('p[no]. paragraph'),'paragraph');
87 function test_simple_format()
89 $this->assertEqual($this->text->simple_format("Test\r\n"),"<p>Test\n</p>");
90 $this->assertEqual($this->text->simple_format("Test\n"),"<p>Test\n</p>");
91 $this->assertEqual($this->text->simple_format("Test\r"),"<p>Test\n</p>");
92 $this->assertEqual($this->text->simple_format("Test\n\nTest"),"<p>Test</p>\n<p>Test</p>");
93 $this->assertEqual($this->text->simple_format("Test\n\n"),"<p>Test</p><br /><br />");
94 $this->assertEqual($this->text->simple_format("Test\n\n\n\n\n\n"),"<p>Test</p><br /><br />");
97 function test_auto_link_email_addresses()
99 $this->assertEqual($this->text->auto_link_email_addresses('sending an email to salavert@example.com and to hilario@example.com'),'sending an email to <a href=\'mailto:salavert@example.com\'>salavert@example.com</a> and to <a href=\'mailto:hilario@example.com\'>hilario@example.com</a>');
100 $this->assertEqual($this->text->auto_link_email_addresses('salavert@@example.com'),'salavert@@example.com');
101 $this->assertEqual($this->text->auto_link_email_addresses('email sent to salavert@example.c'),'email sent to <a href=\'mailto:salavert@example.c\'>salavert@example.c</a>');
104 function test_auto_link_urls()
106 $this->assertEqual($this->text->auto_link_urls('http://www.thebigmover.com'),'<a href="http://www.thebigmover.com">http://www.thebigmover.com</a>');
107 $this->assertEqual($this->text->auto_link_urls('www.thebigmover.com'),'<a href="http://www.thebigmover.com">www.thebigmover.com</a>');
108 $this->assertEqual($this->text->auto_link_urls('www.thebigmover.com nested www.thebigmover.com/search'),'<a href="http://www.thebigmover.com">www.thebigmover.com</a> nested <a href="http://www.thebigmover.com/search">www.thebigmover.com/search</a>');
109 $this->assertEqual($this->text->auto_link_urls('Visit http://www.thebigmover.com now'),'Visit <a href="http://www.thebigmover.com">http://www.thebigmover.com</a> now');
110 $this->assertEqual($this->text->auto_link_urls('Visit http://www.thebigmover.com now and later http://www.akelos.com'),'Visit <a href="http://www.thebigmover.com">http://www.thebigmover.com</a> now and later <a href="http://www.akelos.com">http://www.akelos.com</a>');
113 function test_strip_links()
115 $this->assertEqual($this->text->strip_links('email sent to <a href=\'mailto:salavert@example.c\'>salavert@example.c</a>'),'email sent to salavert@example.c');
116 $this->assertEqual($this->text->strip_links('sending an email to <a href="mailto:salavert@example.com">salavert@example.com</a> and to <a href="mailto:hilario@example.com">hilario@example.com</a>'),'sending an email to salavert@example.com and to hilario@example.com');
119 function test_strip_selected_tags()
121 $this->assertEqual($this->text->strip_selected_tags('sending <b>email</b> to <a href="mailto:salavert@example.com">salavert@example.com</a>','a','b'),'sending email to salavert@example.com');
122 $this->assertEqual($this->text->strip_selected_tags('sending <b>email</b> to <a href="mailto:salavert@example.com">salavert@example.com</a>',array('a','b')),'sending email to salavert@example.com');
123 $this->assertEqual($this->text->strip_selected_tags('sending <b>email</b> to <a href="mailto:salavert@example.com">salavert@example.com</a>','a'),'sending <b>email</b> to salavert@example.com');
126 function test_auto_link()
128 $this->assertEqual($this->text->auto_link('email sent to salavert@example.com from http://www.thebigmover.com','all'),'email sent to <a href=\'mailto:salavert@example.com\'>salavert@example.com</a> from <a href="http://www.thebigmover.com">http://www.thebigmover.com</a>');
129 $this->assertEqual($this->text->auto_link('email sent to salavert@example.com','email_addresses'),'email sent to <a href=\'mailto:salavert@example.com\'>salavert@example.com</a>');
130 $this->assertEqual($this->text->auto_link('email sent from http://www.thebigmover.com','urls'),'email sent from <a href="http://www.thebigmover.com">http://www.thebigmover.com</a>');
133 function test_strip_tags()
135 $this->assertEqual($this->text->strip_tags('<a href="nowhere" onclick="javascript:alert(\'oops\');">link</a>'),'link');
138 function test_markdown()
140 $this->assertEqual($this->text->markdown('> ## This is a header.
142 > 1. This is the first list item.
143 > 2. This is the second list item.
145 > Here\'s some example code:
147 > return shell_exec("echo $input | $markdown_script");'),'<blockquote>
148 <h2>This is a header.</h2>
150 <ol>
151 <li>This is the first list item.</li>
152 <li>This is the second list item.</li>
153 </ol>
155 <p>Here\'s some example code:</p>
157 <pre><code>return shell_exec("echo $input | $markdown_script");
158 </code></pre>
159 </blockquote>');
164 ak_test('TextHelperTests');