@@ -115,6 +115,24 @@ public function testBasicComponentParsing()
115
115
'@endComponentClass##END-COMPONENT-CLASS##</div> ' , trim ($ result ));
116
116
}
117
117
118
+ public function testNestedDefaultComponentParsing ()
119
+ {
120
+ $ container = new Container ;
121
+ $ container ->instance (Application::class, $ app = m::mock (Application::class));
122
+ $ container ->instance (Factory::class, $ factory = m::mock (Factory::class));
123
+ $ app ->shouldReceive ('getNamespace ' )->once ()->andReturn ('App \\' );
124
+ Container::setInstance ($ container );
125
+
126
+ $ result = $ this ->compiler ()->compileTags ('<div><x-card /></div> ' );
127
+
128
+ $ this ->assertSame ("<div>##BEGIN-COMPONENT-CLASS##@component('App\View\Components\Card\Card', 'card', [])
129
+ <?php if (isset( \$attributes) && \$attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
130
+ <?php \$attributes = \$attributes->except(\App\View\Components\Card\Card::ignoredParameterNames()); ?>
131
+ <?php endif; ?>
132
+ <?php \$component->withAttributes([]); ?> \n" .
133
+ '@endComponentClass##END-COMPONENT-CLASS##</div> ' , trim ($ result ));
134
+ }
135
+
118
136
public function testBasicComponentWithEmptyAttributesParsing ()
119
137
{
120
138
$ this ->mockViewFactory ();
@@ -501,6 +519,25 @@ public function testClasslessComponentsWithIndexView()
501
519
'@endComponentClass##END-COMPONENT-CLASS## ' , trim ($ result ));
502
520
}
503
521
522
+ public function testClasslessComponentsWithComponentView ()
523
+ {
524
+ $ container = new Container ;
525
+ $ container ->instance (Application::class, $ app = m::mock (Application::class));
526
+ $ container ->instance (Factory::class, $ factory = m::mock (Factory::class));
527
+ $ app ->shouldReceive ('getNamespace ' )->andReturn ('App \\' );
528
+ $ factory ->shouldReceive ('exists ' )->andReturn (false , false , true );
529
+ Container::setInstance ($ container );
530
+
531
+ $ result = $ this ->compiler ()->compileTags ('<x-anonymous-component :name=" \'Taylor \'" :age="31" wire:model="foo" /> ' );
532
+
533
+ $ this ->assertSame ("##BEGIN-COMPONENT-CLASS##@component('Illuminate\View\AnonymousComponent', 'anonymous-component', ['view' => 'components.anonymous-component.anonymous-component','data' => ['name' => 'Taylor','age' => 31,'wire:model' => 'foo']])
534
+ <?php if (isset( \$attributes) && \$attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
535
+ <?php \$attributes = \$attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
536
+ <?php endif; ?>
537
+ <?php \$component->withAttributes(['name' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute('Taylor'),'age' => 31,'wire:model' => 'foo']); ?> \n" .
538
+ '@endComponentClass##END-COMPONENT-CLASS## ' , trim ($ result ));
539
+ }
540
+
504
541
public function testPackagesClasslessComponents ()
505
542
{
506
543
$ container = new Container ;
@@ -528,7 +565,7 @@ public function testClasslessComponentsWithAnonymousComponentNamespace()
528
565
$ container ->instance (Factory::class, $ factory = m::mock (Factory::class));
529
566
530
567
$ app ->shouldReceive ('getNamespace ' )->once ()->andReturn ('App \\' );
531
- $ factory ->shouldReceive ('exists ' )->times (3 )->andReturnUsing (function ($ arg ) {
568
+ $ factory ->shouldReceive ('exists ' )->times (4 )->andReturnUsing (function ($ arg ) {
532
569
// In our test, we'll do as if the 'public.frontend.anonymous-component'
533
570
// view exists and not the others.
534
571
return $ arg === 'public.frontend.anonymous-component ' ;
@@ -562,7 +599,7 @@ public function testClasslessComponentsWithAnonymousComponentNamespaceWithIndexV
562
599
$ container ->instance (Factory::class, $ factory = m::mock (Factory::class));
563
600
564
601
$ app ->shouldReceive ('getNamespace ' )->once ()->andReturn ('App \\' );
565
- $ factory ->shouldReceive ('exists ' )->times (4 )->andReturnUsing (function (string $ viewNameBeingCheckedForExistence ) {
602
+ $ factory ->shouldReceive ('exists ' )->times (5 )->andReturnUsing (function (string $ viewNameBeingCheckedForExistence ) {
566
603
// In our test, we'll do as if the 'public.frontend.anonymous-component'
567
604
// view exists and not the others.
568
605
return $ viewNameBeingCheckedForExistence === 'admin.auth.components.anonymous-component.index ' ;
@@ -588,6 +625,40 @@ public function testClasslessComponentsWithAnonymousComponentNamespaceWithIndexV
588
625
'@endComponentClass##END-COMPONENT-CLASS## ' , trim ($ result ));
589
626
}
590
627
628
+ public function testClasslessComponentsWithAnonymousComponentNamespaceWithComponentView ()
629
+ {
630
+ $ container = new Container ;
631
+
632
+ $ container ->instance (Application::class, $ app = m::mock (Application::class));
633
+ $ container ->instance (Factory::class, $ factory = m::mock (Factory::class));
634
+
635
+ $ app ->shouldReceive ('getNamespace ' )->once ()->andReturn ('App \\' );
636
+ $ factory ->shouldReceive ('exists ' )->times (6 )->andReturnUsing (function (string $ viewNameBeingCheckedForExistence ) {
637
+ // In our test, we'll do as if the 'public.frontend.anonymous-component'
638
+ // view exists and not the others.
639
+ return $ viewNameBeingCheckedForExistence === 'admin.auth.components.anonymous-component.anonymous-component ' ;
640
+ });
641
+
642
+ Container::setInstance ($ container );
643
+
644
+ $ blade = m::mock (BladeCompiler::class)->makePartial ();
645
+
646
+ $ blade ->shouldReceive ('getAnonymousComponentNamespaces ' )->once ()->andReturn ([
647
+ 'admin.auth ' => 'admin.auth.components ' ,
648
+ ]);
649
+
650
+ $ compiler = $ this ->compiler ([], [], $ blade );
651
+
652
+ $ result = $ compiler ->compileTags ('<x-admin.auth::anonymous-component :name=" \'Taylor \'" :age="31" wire:model="foo" /> ' );
653
+
654
+ $ this ->assertSame ("##BEGIN-COMPONENT-CLASS##@component('Illuminate\View\AnonymousComponent', 'admin.auth::anonymous-component', ['view' => 'admin.auth.components.anonymous-component.anonymous-component','data' => ['name' => 'Taylor','age' => 31,'wire:model' => 'foo']])
655
+ <?php if (isset( \$attributes) && \$attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
656
+ <?php \$attributes = \$attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
657
+ <?php endif; ?>
658
+ <?php \$component->withAttributes(['name' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute('Taylor'),'age' => 31,'wire:model' => 'foo']); ?> \n" .
659
+ '@endComponentClass##END-COMPONENT-CLASS## ' , trim ($ result ));
660
+ }
661
+
591
662
public function testClasslessComponentsWithAnonymousComponentPath ()
592
663
{
593
664
$ container = new Container ;
@@ -621,6 +692,39 @@ public function testClasslessComponentsWithAnonymousComponentPath()
621
692
'@endComponentClass##END-COMPONENT-CLASS## ' , trim ($ result ));
622
693
}
623
694
695
+ public function testClasslessComponentsWithAnonymousComponentPathComponentName ()
696
+ {
697
+ $ container = new Container ;
698
+
699
+ $ container ->instance (Application::class, $ app = m::mock (Application::class));
700
+ $ container ->instance (Factory::class, $ factory = m::mock (Factory::class));
701
+
702
+ $ app ->shouldReceive ('getNamespace ' )->once ()->andReturn ('App \\' );
703
+
704
+ $ factory ->shouldReceive ('exists ' )->andReturnUsing (function ($ arg ) {
705
+ return $ arg === md5 ('test-directory ' ).'::panel.panel ' ;
706
+ });
707
+
708
+ Container::setInstance ($ container );
709
+
710
+ $ blade = m::mock (BladeCompiler::class)->makePartial ();
711
+
712
+ $ blade ->shouldReceive ('getAnonymousComponentPaths ' )->once ()->andReturn ([
713
+ ['path ' => 'test-directory ' , 'prefix ' => null , 'prefixHash ' => md5 ('test-directory ' )],
714
+ ]);
715
+
716
+ $ compiler = $ this ->compiler ([], [], $ blade );
717
+
718
+ $ result = $ compiler ->compileTags ('<x-panel /> ' );
719
+
720
+ $ this ->assertSame ("##BEGIN-COMPONENT-CLASS##@component('Illuminate\View\AnonymousComponent', 'panel', ['view' => ' " .md5 ('test-directory ' )."::panel.panel','data' => []])
721
+ <?php if (isset( \$attributes) && \$attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
722
+ <?php \$attributes = \$attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
723
+ <?php endif; ?>
724
+ <?php \$component->withAttributes([]); ?> \n" .
725
+ '@endComponentClass##END-COMPONENT-CLASS## ' , trim ($ result ));
726
+ }
727
+
624
728
public function testClasslessIndexComponentsWithAnonymousComponentPath ()
625
729
{
626
730
$ container = new Container ;
@@ -689,7 +793,7 @@ public function testItThrowsAnExceptionForNonExistingClass()
689
793
$ container ->instance (Application::class, $ app = m::mock (Application::class));
690
794
$ container ->instance (Factory::class, $ factory = m::mock (Factory::class));
691
795
$ app ->shouldReceive ('getNamespace ' )->once ()->andReturn ('App \\' );
692
- $ factory ->shouldReceive ('exists ' )->twice ( )->andReturn (false );
796
+ $ factory ->shouldReceive ('exists ' )->times ( 3 )->andReturn (false );
693
797
Container::setInstance ($ container );
694
798
695
799
$ this ->expectException (InvalidArgumentException::class);
@@ -855,3 +959,15 @@ public function render()
855
959
return 'container ' ;
856
960
}
857
961
}
962
+
963
+ namespace App \View \Components \Card ;
964
+
965
+ use Illuminate \View \Component ;
966
+
967
+ class Card extends Component
968
+ {
969
+ public function render ()
970
+ {
971
+ return 'card ' ;
972
+ }
973
+ }
0 commit comments