CWIS Developer Documentation
StdLib_NeatlyTruncateString--Test.php
Go to the documentation of this file.
1 <?PHP
2 
6 class NeatlyTruncateString_Test extends PHPUnit\Framework\TestCase
7 {
8 
12  public function testNTS()
13  {
14  $this->assertEquals(
15  "test",
16  StdLib::NeatlyTruncateString("test", 10) );
17 
18  $this->assertEquals(
19  "this test...",
21  "this test test test", 10) );
22 
23  $this->assertEquals(
24  "asdfgasdfg...",
26  "asdfgasdfgasdfgasdfg", 10) );
27 
28  $this->assertEquals(
29  "test te...",
31  "test test test", 7, TRUE));
32 
33  $this->assertEquals(
34  "<b>test</b>",
36  "<b>test</b>", 10));
37 
38  $this->assertEquals(
39  "<b>test test...</b>",
41  "<b>test test test test test</b>", 10));
42 
43  $this->assertEquals(
44  "<b>test...</b>",
46  "<b>test asdfgasdfgasdfgadsfg</b>", 10));
47 
48  $this->assertEquals(
49  "<b>test <i>test</i>...</b>",
51  "<b>test <i>test</i> test</b> test", 10));
52 
53  $this->assertEquals(
54  "<b>test <i>asdfg</i>...</b>",
56  "<b>test <i>asdfg</i>asdfg</b>", 10));
57 
58  $this->assertEquals(
59  "<b>test&nbsp;test&nbsp;...</b>",
61  "<b>test&nbsp;test&nbsp;test&nbsp;test&nbsp;</b>", 10));
62 
63  $this->assertEquals(
64  "<a href='http://www.example.com/'>test</a> <b>test</b>...",
66  "<a href='http://www.example.com/'>test</a> <b>test</b> test test", 10));
67 
68  $this->assertEquals(
69  "<b>abc < abc...</b>",
71  "<b>abc < abc test test</b>", 10));
72 
73  $this->assertEquals(
74  "<b>abc & abc ...</b>",
76  "<b>abc & abc & abc & abc</b>", 10));
77 
78  $this->assertEquals(
79  "<b>&testasdfg...</b>",
81  "<b>&testasdfg asdfgasdfg</b>", 10));
82  }
83 }
Test cases for NeatlyTruncateString in StdLib.
static NeatlyTruncateString($String, $MaxLength, $BreakAnywhere=FALSE)
Attempt to truncate a string as neatly as possible with respect to word breaks, punctuation, and HTML tags.
Definition: StdLib.php:239