blade.test.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. use Laravel\Blade;
  3. class BladeTest extends PHPUnit_Framework_TestCase {
  4. /**
  5. * Test the compilation of echo statements.
  6. *
  7. * @group laravel
  8. */
  9. public function testEchosAreConvertedProperly()
  10. {
  11. $blade1 = '{{$a}}';
  12. $blade2 = '{{e($a)}}';
  13. $this->assertEquals('<?php echo $a; ?>', Blade::compile_string($blade1));
  14. $this->assertEquals('<?php echo e($a); ?>', Blade::compile_string($blade2));
  15. }
  16. /**
  17. * Test the compilation of control structures.
  18. *
  19. * @group laravel
  20. */
  21. public function testControlStructuresAreCreatedCorrectly()
  22. {
  23. $blade1 = "@if (true)\nfoo\n@endif";
  24. $blade2 = "@if (count(".'$something'.") > 0)\nfoo\n@endif";
  25. $blade3 = "@if (true)\nfoo\n@elseif (false)\nbar\n@endif";
  26. $blade4 = "@if (true)\nfoo\n@else\nbar\n@endif";
  27. $this->assertEquals("<?php if (true): ?>\nfoo\n<?php endif; ?>", Blade::compile_string($blade1));
  28. $this->assertEquals("<?php if (count(".'$something'.") > 0): ?>\nfoo\n<?php endif; ?>", Blade::compile_string($blade2));
  29. $this->assertEquals("<?php if (true): ?>\nfoo\n<?php elseif (false): ?>\nbar\n<?php endif; ?>", Blade::compile_string($blade3));
  30. $this->assertEquals("<?php if (true): ?>\nfoo\n<?php else: ?>\nbar\n<?php endif; ?>", Blade::compile_string($blade4));
  31. }
  32. /**
  33. * Test the compilation of yield statements.
  34. *
  35. * @group laravel
  36. */
  37. public function testYieldsAreCompiledCorrectly()
  38. {
  39. $blade = "@yield('something')";
  40. $this->assertEquals("<?php echo \\Laravel\\Section::yield('something'); ?>", Blade::compile_string($blade));
  41. }
  42. /**
  43. * Test the compilation of section statements.
  44. *
  45. * @group laravel
  46. */
  47. public function testSectionsAreCompiledCorrectly()
  48. {
  49. $blade = "@section('something')\nfoo\n@endsection";
  50. $this->assertEquals("<?php \\Laravel\\Section::start('something'); ?>\nfoo\n<?php \\Laravel\\Section::stop(); ?>", Blade::compile_string($blade));
  51. }
  52. }