pastebin

Paste Search Dynamic
Recent pastes
BlockMacros block texy
  1. <?php
  2.  
  3. /**
  4.  * Test: LatteEngine and Texy.
  5.  */
  6.  
  7. use TesterAssert;
  8.  
  9.  
  10. require __DIR__ . '/../bootstrap.php';
  11.  
  12.  
  13. class MockTexy
  14. {
  15.         public function process($text, $singleLine = false)
  16.         {
  17.                 return '<pre>' . $text . '</pre>';
  18.         }
  19. }
  20.  
  21.  
  22. $latte = new LatteEngine;
  23. $latte->setLoader(new LatteLoadersStringLoader);
  24. $latte->addFilter('texy', [new MockTexy, 'process']);
  25.  
  26. $params['hello'] = '<i>Hello</i>';
  27. $params['people'] = ['John', 'Mary', 'Paul'];
  28.  
  29. $result = $latte->renderToString(<<<'EOD'
  30. {contentType text}
  31. {block|lower|texy}
  32. {$hello}
  33. ---------
  34. - Escaped: {$hello}
  35. - Non-escaped: {$hello|noescape}
  36.  
  37. - Escaped expression: {="<" . "b" . ">hello" . "</b>"}
  38.  
  39. - Non-escaped expression: {="<" . "b" . ">hello" . "</b>"|noescape}
  40.  
  41. - array access: {$people[1]}
  42.  
  43. [* image.jpg *]
  44. {/block}
  45. EOD
  46. , $params);
  47.  
  48. assert::match(<<<'EOD'
  49. <pre><i>hello</i>
  50. ---------
  51. - escaped: <i>hello</i>
  52. - non-escaped: <i>hello</i>
  53.  
  54. - escaped expression: <b>hello</b>
  55.  
  56. - non-escaped expression: <b>hello</b>
  57.  
  58. - array access: mary
  59.  
  60. [* image.jpg *]
  61. </pre>
  62. EOD
  63. , $result);
Parsed in 0.048 seconds