@@ -362,6 +362,74 @@ public function testPackagesClasslessComponents()
362
362
'@endComponentClass##END-COMPONENT-CLASS## ' , trim ($ result ));
363
363
}
364
364
365
+ public function testClasslessComponentsWithAnonymousComponentNamespace ()
366
+ {
367
+ $ container = new Container ;
368
+
369
+ $ container ->instance (Application::class, $ app = m::mock (Application::class));
370
+ $ container ->instance (Factory::class, $ factory = m::mock (Factory::class));
371
+
372
+ $ app ->shouldReceive ('getNamespace ' )->andReturn ('App \\' );
373
+ $ factory ->shouldReceive ('exists ' )->andReturnUsing (function ($ arg ) {
374
+ // In our test, we'll do as if the 'public.frontend.anonymous-component'
375
+ // view exists and not the others.
376
+ return $ arg === 'public.frontend.anonymous-component ' ;
377
+ });
378
+
379
+ Container::setInstance ($ container );
380
+
381
+ $ blade = m::mock (BladeCompiler::class)->makePartial ();
382
+
383
+ $ blade ->shouldReceive ('getAnonymousComponentNamespaces ' )->andReturn ([
384
+ 'frontend ' => 'public.frontend ' ,
385
+ ]);
386
+
387
+ $ compiler = $ this ->compiler ([], [], $ blade );
388
+
389
+ $ result = $ compiler ->compileTags ('<x-frontend::anonymous-component :name=" \'Taylor \'" :age="31" wire:model="foo" /> ' );
390
+
391
+ $ this ->assertSame ("##BEGIN-COMPONENT-CLASS##@component('Illuminate\View\AnonymousComponent', 'frontend::anonymous-component', ['view' => 'public.frontend.anonymous-component','data' => ['name' => 'Taylor','age' => 31,'wire:model' => 'foo']])
392
+ <?php if (isset( \$attributes) && \$constructor = (new ReflectionClass(Illuminate\View\AnonymousComponent::class))->getConstructor()): ?>
393
+ <?php \$attributes = \$attributes->except(collect( \$constructor->getParameters())->map->getName()->all()); ?>
394
+ <?php endif; ?>
395
+ <?php \$component->withAttributes(['name' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute('Taylor'),'age' => 31,'wire:model' => 'foo']); ?> \n" .
396
+ '@endComponentClass##END-COMPONENT-CLASS## ' , trim ($ result ));
397
+ }
398
+
399
+ public function testClasslessComponentsWithAnonymousComponentNamespaceWithIndexView ()
400
+ {
401
+ $ container = new Container ;
402
+
403
+ $ container ->instance (Application::class, $ app = m::mock (Application::class));
404
+ $ container ->instance (Factory::class, $ factory = m::mock (Factory::class));
405
+
406
+ $ app ->shouldReceive ('getNamespace ' )->andReturn ('App \\' );
407
+ $ factory ->shouldReceive ('exists ' )->andReturnUsing (function (string $ viewNameBeingCheckedForExistence ) {
408
+ // In our test, we'll do as if the 'public.frontend.anonymous-component'
409
+ // view exists and not the others.
410
+ return $ viewNameBeingCheckedForExistence === 'admin.auth.components.anonymous-component.index ' ;
411
+ });
412
+
413
+ Container::setInstance ($ container );
414
+
415
+ $ blade = m::mock (BladeCompiler::class)->makePartial ();
416
+
417
+ $ blade ->shouldReceive ('getAnonymousComponentNamespaces ' )->andReturn ([
418
+ 'admin.auth ' => 'admin.auth.components ' ,
419
+ ]);
420
+
421
+ $ compiler = $ this ->compiler ([], [], $ blade );
422
+
423
+ $ result = $ compiler ->compileTags ('<x-admin.auth::anonymous-component :name=" \'Taylor \'" :age="31" wire:model="foo" /> ' );
424
+
425
+ $ this ->assertSame ("##BEGIN-COMPONENT-CLASS##@component('Illuminate\View\AnonymousComponent', 'admin.auth::anonymous-component', ['view' => 'admin.auth.components.anonymous-component.index','data' => ['name' => 'Taylor','age' => 31,'wire:model' => 'foo']])
426
+ <?php if (isset( \$attributes) && \$constructor = (new ReflectionClass(Illuminate\View\AnonymousComponent::class))->getConstructor()): ?>
427
+ <?php \$attributes = \$attributes->except(collect( \$constructor->getParameters())->map->getName()->all()); ?>
428
+ <?php endif; ?>
429
+ <?php \$component->withAttributes(['name' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute('Taylor'),'age' => 31,'wire:model' => 'foo']); ?> \n" .
430
+ '@endComponentClass##END-COMPONENT-CLASS## ' , trim ($ result ));
431
+ }
432
+
365
433
public function testAttributeSanitization ()
366
434
{
367
435
$ class = new class
@@ -451,10 +519,10 @@ protected function mockViewFactory($existsSucceeds = true)
451
519
Container::setInstance ($ container );
452
520
}
453
521
454
- protected function compiler ($ aliases = [])
522
+ protected function compiler (array $ aliases = [], array $ namespaces = [], ? BladeCompiler $ blade = null )
455
523
{
456
524
return new ComponentTagCompiler (
457
- $ aliases
525
+ $ aliases, $ namespaces , $ blade
458
526
);
459
527
}
460
528
}
0 commit comments