BladeComponentsTest.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace Illuminate\Tests\View\Blade;
  3. class BladeComponentsTest extends AbstractBladeTestCase
  4. {
  5. public function testComponentsAreCompiled()
  6. {
  7. $this->assertSame('<?php $__env->startComponent(\'foo\', ["foo" => "bar"]); ?>', $this->compiler->compileString('@component(\'foo\', ["foo" => "bar"])'));
  8. $this->assertSame('<?php $__env->startComponent(\'foo\'); ?>', $this->compiler->compileString('@component(\'foo\')'));
  9. }
  10. public function testClassComponentsAreCompiled()
  11. {
  12. $this->assertSame('<?php if (isset($component)) { $__componentOriginal35bda42cbf6f9717b161c4f893644ac7a48b0d98 = $component; } ?>
  13. <?php $component = $__env->getContainer()->make(Test::class, ["foo" => "bar"]); ?>
  14. <?php $component->withName(\'test\'); ?>
  15. <?php if ($component->shouldRender()): ?>
  16. <?php $__env->startComponent($component->resolveView(), $component->data()); ?>', $this->compiler->compileString('@component(\'Test::class\', \'test\', ["foo" => "bar"])'));
  17. }
  18. public function testEndComponentsAreCompiled()
  19. {
  20. $this->compiler->newComponentHash('foo');
  21. $this->assertSame('<?php echo $__env->renderComponent(); ?>', $this->compiler->compileString('@endcomponent'));
  22. }
  23. public function testEndComponentClassesAreCompiled()
  24. {
  25. $this->compiler->newComponentHash('foo');
  26. $this->assertSame('<?php echo $__env->renderComponent(); ?>
  27. <?php endif; ?>
  28. <?php if (isset($__componentOriginal0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33)): ?>
  29. <?php $component = $__componentOriginal0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33; ?>
  30. <?php unset($__componentOriginal0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33); ?>
  31. <?php endif; ?>', $this->compiler->compileString('@endcomponentClass'));
  32. }
  33. public function testSlotsAreCompiled()
  34. {
  35. $this->assertSame('<?php $__env->slot(\'foo\', null, ["foo" => "bar"]); ?>', $this->compiler->compileString('@slot(\'foo\', null, ["foo" => "bar"])'));
  36. $this->assertSame('<?php $__env->slot(\'foo\'); ?>', $this->compiler->compileString('@slot(\'foo\')'));
  37. }
  38. public function testEndSlotsAreCompiled()
  39. {
  40. $this->assertSame('<?php $__env->endSlot(); ?>', $this->compiler->compileString('@endslot'));
  41. }
  42. }