|
@@ 42-51 (lines=10) @@
|
| 39 |
|
return App::make('twig.environment'); |
| 40 |
|
} |
| 41 |
|
|
| 42 |
|
public function testTemplateFromStringFunction() |
| 43 |
|
{ |
| 44 |
|
$twig = $this->getTwig(); |
| 45 |
|
|
| 46 |
|
$template = "{% set name = 'John' %}"; |
| 47 |
|
$template .= '{{ include(template_from_string("Hello {{ name }}")) }}'; |
| 48 |
|
|
| 49 |
|
$twigTemplate = $twig->createTemplate($template); |
| 50 |
|
$this->assertEquals($twigTemplate->render([]), 'Hello John'); |
| 51 |
|
} |
| 52 |
|
|
| 53 |
|
public function testTruncateFilterForFive() |
| 54 |
|
{ |
|
@@ 63-71 (lines=9) @@
|
| 60 |
|
$this->assertEquals($twigTemplate->render([]), 'Gordo...'); |
| 61 |
|
} |
| 62 |
|
|
| 63 |
|
public function testTruncateFilterForDefault() |
| 64 |
|
{ |
| 65 |
|
$twig = $this->getTwig(); |
| 66 |
|
|
| 67 |
|
$template = "{{ 'Lorem ipsum dolor sit amet, consectetur adipiscing elit' | truncate }}"; |
| 68 |
|
|
| 69 |
|
$twigTemplate = $twig->createTemplate($template); |
| 70 |
|
$this->assertEquals($twigTemplate->render([]), 'Lorem ipsum dolor sit amet, co...'); |
| 71 |
|
} |
| 72 |
|
|
| 73 |
|
public function testTruncateFilterWithSeparator() |
| 74 |
|
{ |
|
@@ 83-91 (lines=9) @@
|
| 80 |
|
$this->assertEquals($twigTemplate->render([]), 'Gordo-'); |
| 81 |
|
} |
| 82 |
|
|
| 83 |
|
public function testWordWrapFilter() |
| 84 |
|
{ |
| 85 |
|
$twig = $this->getTwig(); |
| 86 |
|
|
| 87 |
|
$template = "{{ 'Lorem ipsum dolor sit amet, consectetur adipiscing elit' | wordwrap(10) }}"; |
| 88 |
|
|
| 89 |
|
$twigTemplate = $twig->createTemplate($template); |
| 90 |
|
$this->assertEquals($twigTemplate->render([]), "Lorem ipsu\nm dolor si\nt amet, co\nnsectetur \nadipiscing\n elit"); |
| 91 |
|
} |
| 92 |
|
|
| 93 |
|
public function testShuffleFilter() |
| 94 |
|
{ |
|
@@ 126-134 (lines=9) @@
|
| 123 |
|
// $this->assertEquals($twigTemplate->render([]), '1 minute ago'); |
| 124 |
|
} |
| 125 |
|
|
| 126 |
|
public function testStrftimeFunction() |
| 127 |
|
{ |
| 128 |
|
$twig = $this->getTwig(); |
| 129 |
|
|
| 130 |
|
$template = "{{ '2016-03-24 23:05' | strftime('%d.%m.%Y %H:%M:%S') }}"; |
| 131 |
|
|
| 132 |
|
$twigTemplate = $twig->createTemplate($template); |
| 133 |
|
$this->assertEquals($twigTemplate->render([]), '24.03.2016 23:05:00'); |
| 134 |
|
} |
| 135 |
|
|
| 136 |
|
public function testUppercaseFunction() |
| 137 |
|
{ |
|
@@ 136-144 (lines=9) @@
|
| 133 |
|
$this->assertEquals($twigTemplate->render([]), '24.03.2016 23:05:00'); |
| 134 |
|
} |
| 135 |
|
|
| 136 |
|
public function testUppercaseFunction() |
| 137 |
|
{ |
| 138 |
|
$twig = $this->getTwig(); |
| 139 |
|
|
| 140 |
|
$template = "{{ 'Jack' | uppercase }}"; |
| 141 |
|
|
| 142 |
|
$twigTemplate = $twig->createTemplate($template); |
| 143 |
|
$this->assertEquals($twigTemplate->render([]), 'JACK'); |
| 144 |
|
} |
| 145 |
|
|
| 146 |
|
public function testLowercaseFunction() |
| 147 |
|
{ |
|
@@ 146-154 (lines=9) @@
|
| 143 |
|
$this->assertEquals($twigTemplate->render([]), 'JACK'); |
| 144 |
|
} |
| 145 |
|
|
| 146 |
|
public function testLowercaseFunction() |
| 147 |
|
{ |
| 148 |
|
$twig = $this->getTwig(); |
| 149 |
|
|
| 150 |
|
$template = "{{ 'JACK' | lowercase }}"; |
| 151 |
|
|
| 152 |
|
$twigTemplate = $twig->createTemplate($template); |
| 153 |
|
$this->assertEquals($twigTemplate->render([]), 'jack'); |
| 154 |
|
} |
| 155 |
|
|
| 156 |
|
public function testUcfirstFunction() |
| 157 |
|
{ |
|
@@ 156-164 (lines=9) @@
|
| 153 |
|
$this->assertEquals($twigTemplate->render([]), 'jack'); |
| 154 |
|
} |
| 155 |
|
|
| 156 |
|
public function testUcfirstFunction() |
| 157 |
|
{ |
| 158 |
|
$twig = $this->getTwig(); |
| 159 |
|
|
| 160 |
|
$template = "{{ 'jack' | ucfirst }}"; |
| 161 |
|
|
| 162 |
|
$twigTemplate = $twig->createTemplate($template); |
| 163 |
|
$this->assertEquals($twigTemplate->render([]), 'Jack'); |
| 164 |
|
} |
| 165 |
|
|
| 166 |
|
public function testLcfirstFunction() |
| 167 |
|
{ |
|
@@ 166-174 (lines=9) @@
|
| 163 |
|
$this->assertEquals($twigTemplate->render([]), 'Jack'); |
| 164 |
|
} |
| 165 |
|
|
| 166 |
|
public function testLcfirstFunction() |
| 167 |
|
{ |
| 168 |
|
$twig = $this->getTwig(); |
| 169 |
|
|
| 170 |
|
$template = "{{ 'JACK' | lcfirst }}"; |
| 171 |
|
|
| 172 |
|
$twigTemplate = $twig->createTemplate($template); |
| 173 |
|
$this->assertEquals($twigTemplate->render([]), 'jACK'); |
| 174 |
|
} |
| 175 |
|
|
| 176 |
|
public function testLtrimFunction() |
| 177 |
|
{ |
|
@@ 176-184 (lines=9) @@
|
| 173 |
|
$this->assertEquals($twigTemplate->render([]), 'jACK'); |
| 174 |
|
} |
| 175 |
|
|
| 176 |
|
public function testLtrimFunction() |
| 177 |
|
{ |
| 178 |
|
$twig = $this->getTwig(); |
| 179 |
|
|
| 180 |
|
$template = "{{ ' jack' | ltrim }}"; |
| 181 |
|
|
| 182 |
|
$twigTemplate = $twig->createTemplate($template); |
| 183 |
|
$this->assertEquals($twigTemplate->render([]), 'jack'); |
| 184 |
|
} |
| 185 |
|
|
| 186 |
|
public function testRtrimFunction() |
| 187 |
|
{ |
|
@@ 186-194 (lines=9) @@
|
| 183 |
|
$this->assertEquals($twigTemplate->render([]), 'jack'); |
| 184 |
|
} |
| 185 |
|
|
| 186 |
|
public function testRtrimFunction() |
| 187 |
|
{ |
| 188 |
|
$twig = $this->getTwig(); |
| 189 |
|
|
| 190 |
|
$template = "{{ 'jack ' | rtrim }}"; |
| 191 |
|
|
| 192 |
|
$twigTemplate = $twig->createTemplate($template); |
| 193 |
|
$this->assertEquals($twigTemplate->render([]), 'jack'); |
| 194 |
|
} |
| 195 |
|
|
| 196 |
|
public function testStrRepeatFunction() |
| 197 |
|
{ |
|
@@ 196-204 (lines=9) @@
|
| 193 |
|
$this->assertEquals($twigTemplate->render([]), 'jack'); |
| 194 |
|
} |
| 195 |
|
|
| 196 |
|
public function testStrRepeatFunction() |
| 197 |
|
{ |
| 198 |
|
$twig = $this->getTwig(); |
| 199 |
|
|
| 200 |
|
$template = "{{ ' best' | str_repeat(3) }}"; |
| 201 |
|
|
| 202 |
|
$twigTemplate = $twig->createTemplate($template); |
| 203 |
|
$this->assertEquals($twigTemplate->render([]), ' best best best'); |
| 204 |
|
} |
| 205 |
|
|
| 206 |
|
public function testPluralFunction() |
| 207 |
|
{ |
|
@@ 216-224 (lines=9) @@
|
| 213 |
|
$this->assertEquals($twigTemplate->render([]), 'mails'); |
| 214 |
|
} |
| 215 |
|
|
| 216 |
|
public function testStrpadFunction() |
| 217 |
|
{ |
| 218 |
|
$twig = $this->getTwig(); |
| 219 |
|
|
| 220 |
|
$template = "{{ 'test' | strpad(10) }}"; |
| 221 |
|
|
| 222 |
|
$twigTemplate = $twig->createTemplate($template); |
| 223 |
|
$this->assertEquals($twigTemplate->render([]), ' test '); |
| 224 |
|
} |
| 225 |
|
|
| 226 |
|
public function testStripTagsFunction() |
| 227 |
|
{ |
|
@@ 226-234 (lines=9) @@
|
| 223 |
|
$this->assertEquals($twigTemplate->render([]), ' test '); |
| 224 |
|
} |
| 225 |
|
|
| 226 |
|
public function testStripTagsFunction() |
| 227 |
|
{ |
| 228 |
|
$twig = $this->getTwig(); |
| 229 |
|
|
| 230 |
|
$template = "{{ '<p><b>text</b></p>' | strip_tags('<p>') }}"; |
| 231 |
|
|
| 232 |
|
$twigTemplate = $twig->createTemplate($template); |
| 233 |
|
$this->assertEquals($twigTemplate->render([]), '<p>text</p>'); |
| 234 |
|
} |
| 235 |
|
|
| 236 |
|
public function testLeftpadFunction() |
| 237 |
|
{ |
|
@@ 236-244 (lines=9) @@
|
| 233 |
|
$this->assertEquals($twigTemplate->render([]), '<p>text</p>'); |
| 234 |
|
} |
| 235 |
|
|
| 236 |
|
public function testLeftpadFunction() |
| 237 |
|
{ |
| 238 |
|
$twig = $this->getTwig(); |
| 239 |
|
|
| 240 |
|
$template = "{{ 'test' | leftpad(7) }}"; |
| 241 |
|
|
| 242 |
|
$twigTemplate = $twig->createTemplate($template); |
| 243 |
|
$this->assertEquals($twigTemplate->render([]), ' test'); |
| 244 |
|
} |
| 245 |
|
|
| 246 |
|
public function testRightpadFunction() |
| 247 |
|
{ |
|
@@ 256-264 (lines=9) @@
|
| 253 |
|
$this->assertEquals($twigTemplate->render([]), 'testooo'); |
| 254 |
|
} |
| 255 |
|
|
| 256 |
|
public function testRtlFunction() |
| 257 |
|
{ |
| 258 |
|
$twig = $this->getTwig(); |
| 259 |
|
|
| 260 |
|
$template = "{{ 'Hello world!' | rtl }}"; |
| 261 |
|
|
| 262 |
|
$twigTemplate = $twig->createTemplate($template); |
| 263 |
|
$this->assertEquals($twigTemplate->render([]), '!dlrow olleH'); |
| 264 |
|
} |
| 265 |
|
|
| 266 |
|
public function testSortByFieldFunction() |
| 267 |
|
{ |
|
@@ 329-337 (lines=9) @@
|
| 326 |
|
$this->assertContains('string(4) "test"', $twigTemplate->render([])); |
| 327 |
|
} |
| 328 |
|
|
| 329 |
|
public function testVardumpFilter() |
| 330 |
|
{ |
| 331 |
|
$twig = $this->getTwig(); |
| 332 |
|
|
| 333 |
|
$template = "{{ 'test' | var_dump }}"; |
| 334 |
|
|
| 335 |
|
$twigTemplate = $twig->createTemplate($template); |
| 336 |
|
$this->assertContains('string(4) "test"', $twigTemplate->render([])); |
| 337 |
|
} |
| 338 |
|
|
| 339 |
|
public function testConfigFunction() |
| 340 |
|
{ |
|
@@ 364-373 (lines=10) @@
|
| 361 |
|
$this->assertEquals($twigTemplate->render([]), 'test value'); |
| 362 |
|
} |
| 363 |
|
|
| 364 |
|
public function testTransFunction() |
| 365 |
|
{ |
| 366 |
|
$twig = $this->getTwig(); |
| 367 |
|
Config::set('app.locale', 'en'); |
| 368 |
|
|
| 369 |
|
$template = "{{ trans('validation.accepted') }}"; |
| 370 |
|
|
| 371 |
|
$twigTemplate = $twig->createTemplate($template); |
| 372 |
|
$this->assertEquals($twigTemplate->render([]), 'The :attribute must be accepted.'); |
| 373 |
|
} |
| 374 |
|
|
| 375 |
|
public function testTransFunctionWithParam() |
| 376 |
|
{ |
|
@@ 375-384 (lines=10) @@
|
| 372 |
|
$this->assertEquals($twigTemplate->render([]), 'The :attribute must be accepted.'); |
| 373 |
|
} |
| 374 |
|
|
| 375 |
|
public function testTransFunctionWithParam() |
| 376 |
|
{ |
| 377 |
|
$twig = $this->getTwig(); |
| 378 |
|
Config::set('app.locale', 'en'); |
| 379 |
|
|
| 380 |
|
$template = "{{ trans('backend::lang.access_log.hint', {'days': 60}) }}"; |
| 381 |
|
|
| 382 |
|
$twigTemplate = $twig->createTemplate($template); |
| 383 |
|
$this->assertContains('60 days', $twigTemplate->render([])); |
| 384 |
|
} |
| 385 |
|
} |
| 386 |
|
|