BladeBreakStatementsTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace Illuminate\Tests\View\Blade;
  3. class BladeBreakStatementsTest extends AbstractBladeTestCase
  4. {
  5. public function testBreakStatementsAreCompiled()
  6. {
  7. $string = '@for ($i = 0; $i < 10; $i++)
  8. test
  9. @break
  10. @endfor';
  11. $expected = '<?php for($i = 0; $i < 10; $i++): ?>
  12. test
  13. <?php break; ?>
  14. <?php endfor; ?>';
  15. $this->assertEquals($expected, $this->compiler->compileString($string));
  16. }
  17. public function testBreakStatementsWithExpressionAreCompiled()
  18. {
  19. $string = '@for ($i = 0; $i < 10; $i++)
  20. test
  21. @break(TRUE)
  22. @endfor';
  23. $expected = '<?php for($i = 0; $i < 10; $i++): ?>
  24. test
  25. <?php if(TRUE) break; ?>
  26. <?php endfor; ?>';
  27. $this->assertEquals($expected, $this->compiler->compileString($string));
  28. }
  29. public function testBreakStatementsWithArgumentAreCompiled()
  30. {
  31. $string = '@for ($i = 0; $i < 10; $i++)
  32. test
  33. @break(2)
  34. @endfor';
  35. $expected = '<?php for($i = 0; $i < 10; $i++): ?>
  36. test
  37. <?php break 2; ?>
  38. <?php endfor; ?>';
  39. $this->assertEquals($expected, $this->compiler->compileString($string));
  40. }
  41. public function testBreakStatementsWithSpacedArgumentAreCompiled()
  42. {
  43. $string = '@for ($i = 0; $i < 10; $i++)
  44. test
  45. @break( 2 )
  46. @endfor';
  47. $expected = '<?php for($i = 0; $i < 10; $i++): ?>
  48. test
  49. <?php break 2; ?>
  50. <?php endfor; ?>';
  51. $this->assertEquals($expected, $this->compiler->compileString($string));
  52. }
  53. public function testBreakStatementsWithFaultyArgumentAreCompiled()
  54. {
  55. $string = '@for ($i = 0; $i < 10; $i++)
  56. test
  57. @break(-2)
  58. @endfor';
  59. $expected = '<?php for($i = 0; $i < 10; $i++): ?>
  60. test
  61. <?php break 1; ?>
  62. <?php endfor; ?>';
  63. $this->assertEquals($expected, $this->compiler->compileString($string));
  64. }
  65. }