1 | <?php |
||
11 | class TextExtensionTest extends \PHPUnit_Framework_TestCase |
||
12 | { |
||
13 | use TestHelper; |
||
14 | |||
15 | protected function getExtension() |
||
16 | { |
||
17 | return new TextExtension(); |
||
18 | } |
||
19 | |||
20 | |||
21 | public function testParagraph() |
||
22 | { |
||
23 | $this->assertRender("<p>foo<br>\nbar</p>\n<p>monkey</p>", "{{ 'foo\nbar\n\nmonkey'|paragraph() }}"); |
||
24 | } |
||
25 | |||
26 | |||
27 | public function testLine() |
||
28 | { |
||
29 | $this->assertRender("foo", "{{ 'foo\nbar\nbaz'|line() }}"); |
||
30 | } |
||
31 | |||
32 | public function testLineTwo() |
||
33 | { |
||
34 | $this->assertRender("bar", "{{ 'foo\nbar\nbaz'|line(2) }}"); |
||
35 | } |
||
36 | |||
37 | public function testLineToHigh() |
||
38 | { |
||
39 | $this->assertRender("", "{{ 'foo\nbar\nbaz'|line(100) }}"); |
||
40 | } |
||
41 | |||
42 | |||
43 | public function testLess() |
||
44 | { |
||
45 | $this->assertRender("foo...", "{{ 'foo<!-- pagebreak -->baz'|less() }}"); |
||
46 | } |
||
47 | |||
48 | public function testLessCustom() |
||
49 | { |
||
50 | $this->assertRender("foo..", "{{ 'fooXbarXbaz'|less('..', 'X') }}"); |
||
51 | } |
||
52 | |||
53 | public function testTruncate() |
||
54 | { |
||
55 | $this->assertRender("foo ..", "{{ 'foo bar baz'|truncate(4, '..') }}"); |
||
56 | } |
||
57 | |||
58 | |||
59 | public function testLinkify() |
||
60 | { |
||
61 | $this->assertRender( |
||
62 | '<a href="http://www.example.com">www.example.com</a>, color.bar and ' |
||
63 | . '<a href="mailto:[email protected]">[email protected]</a>', |
||
64 | '{{ "www.example.com, color.bar and [email protected]"|linkify }}' |
||
65 | ); |
||
66 | } |
||
67 | |||
68 | public function testLinkifyAll() |
||
69 | { |
||
70 | $this->assertRender( |
||
71 | '<a href="http://www.example.com">www.example.com</a>, <a href="http://color.bar">color.bar</a> and ' |
||
72 | . '<a href="mailto:[email protected]">[email protected]</a>', |
||
73 | '{{ "www.example.com, color.bar and [email protected]"|linkify(["http", "mail"], [], "all") }}' |
||
74 | ); |
||
75 | } |
||
76 | |||
77 | public function testLinkifyHttps() |
||
78 | { |
||
79 | $this->assertRender( |
||
80 | '<a href="https://www.example.com">www.example.com</a>', |
||
81 | '{{ "www.example.com"|linkify("https") }}' |
||
82 | ); |
||
83 | } |
||
84 | |||
85 | public function testLinkifyMail() |
||
86 | { |
||
87 | $this->assertRender( |
||
88 | '<a href="mailto:[email protected]">[email protected]</a> and ' |
||
89 | . '<a href="mailto:[email protected]">[email protected]</a>', |
||
90 | '{{ "[email protected] and [email protected]"|linkify }}' |
||
91 | ); |
||
92 | } |
||
93 | |||
94 | public function testLinkifyFtp() |
||
95 | { |
||
96 | $this->assertRender( |
||
97 | '<a href="ftp://www.example.com">www.example.com</a>', |
||
98 | '{{ "ftp://www.example.com"|linkify("ftp") }}' |
||
99 | ); |
||
100 | } |
||
101 | |||
102 | public function testLinkifyFtpAll() |
||
103 | { |
||
104 | $this->assertRender( |
||
105 | '<a href="ftp://www.example.com">www.example.com</a>', |
||
106 | '{{ "www.example.com"|linkify("ftp", [], "all") }}' |
||
107 | ); |
||
108 | } |
||
109 | |||
110 | public function testLinkifyOther() |
||
111 | { |
||
112 | $this->assertRender( |
||
113 | '<a href="foo:abc.def.hif">abc.def.hif</a>', |
||
114 | '{{ "foo:abc.def.hif"|linkify("foo") }}' |
||
115 | ); |
||
116 | } |
||
117 | |||
118 | public function testLinkifyOtherAll() |
||
119 | { |
||
120 | $this->assertRender( |
||
121 | '<a href="foo:abc.def.hif">abc.def.hif</a>', |
||
122 | '{{ "abc.def.hif"|linkify("foo", [], "all") }}' |
||
123 | ); |
||
124 | } |
||
125 | |||
126 | public function testLinkifyWithAttributes() |
||
127 | { |
||
128 | $this->assertRender( |
||
129 | '<a foo="bar" color="blue" href="http://www.example.com">www.example.com</a> and ' |
||
130 | . '<a foo="bar" color="blue" href="mailto:[email protected]">[email protected]</a>', |
||
131 | '{{ "www.example.com and [email protected]"|linkify(["http", "mail"], {foo: "bar", color: "blue"}) }}' |
||
132 | ); |
||
133 | } |
||
134 | |||
135 | public function testLinkifyWithExistingLink() |
||
136 | { |
||
137 | $this->assertRender( |
||
138 | '<a href="http://www.example.com">www.example.com</a> and ' |
||
139 | . '<a href="http://www.example.net">www.example.net</a>', |
||
140 | '{{ "<a href=\\"http://www.example.com\\">www.example.com</a> and www.example.net"|linkify }}' |
||
141 | ); |
||
142 | } |
||
143 | |||
144 | |||
145 | public function filterProvider() |
||
146 | { |
||
147 | return [ |
||
148 | ['paragraph'], |
||
149 | ['line'], |
||
150 | ['less'], |
||
151 | ['truncate'], |
||
152 | ['linkify'] |
||
153 | ]; |
||
154 | } |
||
155 | |||
156 | /** |
||
157 | * @dataProvider filterProvider |
||
158 | * |
||
159 | * @param string $filter |
||
160 | */ |
||
161 | public function testWithNull($filter) |
||
162 | { |
||
163 | $this->assertRender('-', '{{ null|' . $filter . '("//")|default("-") }}'); |
||
164 | } |
||
165 | } |
||
166 |