BladeEchoTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace Illuminate\Tests\View\Blade;
  3. class BladeEchoTest extends AbstractBladeTestCase
  4. {
  5. public function testEchosAreCompiled()
  6. {
  7. $this->assertSame('<?php echo $name; ?>', $this->compiler->compileString('{!!$name!!}'));
  8. $this->assertSame('<?php echo $name; ?>', $this->compiler->compileString('{!! $name !!}'));
  9. $this->assertSame('<?php echo $name; ?>', $this->compiler->compileString('{!!
  10. $name
  11. !!}'));
  12. $this->assertSame('<?php echo e($name); ?>', $this->compiler->compileString('{{{$name}}}'));
  13. $this->assertSame('<?php echo e($name); ?>', $this->compiler->compileString('{{$name}}'));
  14. $this->assertSame('<?php echo e($name); ?>', $this->compiler->compileString('{{ $name }}'));
  15. $this->assertSame('<?php echo e($name); ?>', $this->compiler->compileString('{{
  16. $name
  17. }}'));
  18. $this->assertSame("<?php echo e(\$name); ?>\n\n", $this->compiler->compileString("{{ \$name }}\n"));
  19. $this->assertSame("<?php echo e(\$name); ?>\r\n\r\n", $this->compiler->compileString("{{ \$name }}\r\n"));
  20. $this->assertSame("<?php echo e(\$name); ?>\n\n", $this->compiler->compileString("{{ \$name }}\n"));
  21. $this->assertSame("<?php echo e(\$name); ?>\r\n\r\n", $this->compiler->compileString("{{ \$name }}\r\n"));
  22. $this->assertSame('<?php echo e("Hello world or foo"); ?>',
  23. $this->compiler->compileString('{{ "Hello world or foo" }}'));
  24. $this->assertSame('<?php echo e("Hello world or foo"); ?>',
  25. $this->compiler->compileString('{{"Hello world or foo"}}'));
  26. $this->assertSame('<?php echo e($foo + $or + $baz); ?>', $this->compiler->compileString('{{$foo + $or + $baz}}'));
  27. $this->assertSame('<?php echo e("Hello world or foo"); ?>', $this->compiler->compileString('{{
  28. "Hello world or foo"
  29. }}'));
  30. $this->assertSame('<?php echo e(\'Hello world or foo\'); ?>',
  31. $this->compiler->compileString('{{ \'Hello world or foo\' }}'));
  32. $this->assertSame('<?php echo e(\'Hello world or foo\'); ?>',
  33. $this->compiler->compileString('{{\'Hello world or foo\'}}'));
  34. $this->assertSame('<?php echo e(\'Hello world or foo\'); ?>', $this->compiler->compileString('{{
  35. \'Hello world or foo\'
  36. }}'));
  37. $this->assertSame('<?php echo e(myfunc(\'foo or bar\')); ?>',
  38. $this->compiler->compileString('{{ myfunc(\'foo or bar\') }}'));
  39. $this->assertSame('<?php echo e(myfunc("foo or bar")); ?>',
  40. $this->compiler->compileString('{{ myfunc("foo or bar") }}'));
  41. $this->assertSame('<?php echo e(myfunc("$name or \'foo\'")); ?>',
  42. $this->compiler->compileString('{{ myfunc("$name or \'foo\'") }}'));
  43. }
  44. public function testEscapedWithAtEchosAreCompiled()
  45. {
  46. $this->assertSame('{{$name}}', $this->compiler->compileString('@{{$name}}'));
  47. $this->assertSame('{{ $name }}', $this->compiler->compileString('@{{ $name }}'));
  48. $this->assertSame('{{
  49. $name
  50. }}',
  51. $this->compiler->compileString('@{{
  52. $name
  53. }}'));
  54. $this->assertSame('{{ $name }}
  55. ',
  56. $this->compiler->compileString('@{{ $name }}
  57. '));
  58. }
  59. }