BladeVerbatimTest.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace Illuminate\Tests\View\Blade;
  3. class BladeVerbatimTest extends AbstractBladeTestCase
  4. {
  5. public function testVerbatimBlocksAreCompiled()
  6. {
  7. $string = '@verbatim {{ $a }} @if($b) {{ $b }} @endif @endverbatim';
  8. $expected = ' {{ $a }} @if($b) {{ $b }} @endif ';
  9. $this->assertEquals($expected, $this->compiler->compileString($string));
  10. }
  11. public function testVerbatimBlocksWithMultipleLinesAreCompiled()
  12. {
  13. $string = 'Some text
  14. @verbatim
  15. {{ $a }}
  16. @if($b)
  17. {{ $b }}
  18. @endif
  19. @endverbatim';
  20. $expected = 'Some text
  21. {{ $a }}
  22. @if($b)
  23. {{ $b }}
  24. @endif
  25. ';
  26. $this->assertEquals($expected, $this->compiler->compileString($string));
  27. }
  28. public function testMultipleVerbatimBlocksAreCompiled()
  29. {
  30. $string = '@verbatim {{ $a }} @endverbatim {{ $b }} @verbatim {{ $c }} @endverbatim';
  31. $expected = ' {{ $a }} <?php echo e($b); ?> {{ $c }} ';
  32. $this->assertEquals($expected, $this->compiler->compileString($string));
  33. }
  34. public function testRawBlocksAreRenderedInTheRightOrder()
  35. {
  36. $string = '@php echo "#1"; @endphp @verbatim {{ #2 }} @endverbatim @verbatim {{ #3 }} @endverbatim @php echo "#4"; @endphp';
  37. $expected = '<?php echo "#1"; ?> {{ #2 }} {{ #3 }} <?php echo "#4"; ?>';
  38. $this->assertSame($expected, $this->compiler->compileString($string));
  39. }
  40. public function testMultilineTemplatesWithRawBlocksAreRenderedInTheRightOrder()
  41. {
  42. $string = '{{ $first }}
  43. @php
  44. echo $second;
  45. @endphp
  46. @if ($conditional)
  47. {{ $third }}
  48. @endif
  49. @include("users")
  50. @verbatim
  51. {{ $fourth }} @include("test")
  52. @endverbatim
  53. @php echo $fifth; @endphp';
  54. $expected = '<?php echo e($first); ?>
  55. <?php
  56. echo $second;
  57. ?>
  58. <?php if($conditional): ?>
  59. <?php echo e($third); ?>
  60. <?php endif; ?>
  61. <?php echo $__env->make("users", \Illuminate\Support\Arr::except(get_defined_vars(), [\'__data\', \'__path\']))->render(); ?>
  62. {{ $fourth }} @include("test")
  63. <?php echo $fifth; ?>';
  64. $this->assertSame($expected, $this->compiler->compileString($string));
  65. }
  66. public function testRawBlocksDontGetMixedUpWhenSomeAreRemovedByBladeComments()
  67. {
  68. $string = '{{-- @verbatim Block #1 @endverbatim --}} @php "Block #2" @endphp';
  69. $expected = ' <?php "Block #2" ?>';
  70. $this->assertSame($expected, $this->compiler->compileString($string));
  71. }
  72. }