BladeJsTest.php 1.1 KB

123456789101112131415161718192021222324252627282930
  1. <?php
  2. namespace Illuminate\Tests\View\Blade;
  3. class BladeJsTest extends AbstractBladeTestCase
  4. {
  5. public function testStatementIsCompiledWithoutAnyOptions()
  6. {
  7. $string = '<div x-data="@js($data)"></div>';
  8. $expected = '<div x-data="<?php echo \Illuminate\Support\Js::from($data)->toHtml() ?>"></div>';
  9. $this->assertEquals($expected, $this->compiler->compileString($string));
  10. }
  11. public function testJsonFlagsCanBeSet()
  12. {
  13. $string = '<div x-data="@js($data, JSON_FORCE_OBJECT)"></div>';
  14. $expected = '<div x-data="<?php echo \Illuminate\Support\Js::from($data, JSON_FORCE_OBJECT)->toHtml() ?>"></div>';
  15. $this->assertEquals($expected, $this->compiler->compileString($string));
  16. }
  17. public function testEncodingDepthCanBeSet()
  18. {
  19. $string = '<div x-data="@js($data, JSON_FORCE_OBJECT, 256)"></div>';
  20. $expected = '<div x-data="<?php echo \Illuminate\Support\Js::from($data, JSON_FORCE_OBJECT, 256)->toHtml() ?>"></div>';
  21. $this->assertEquals($expected, $this->compiler->compileString($string));
  22. }
  23. }