@@ -538,6 +538,68 @@ public function testAssertNotTemplateName(): void
538
538
$ this ->assertNotTemplateName ('template/does/not/exist ' );
539
539
}
540
540
541
+ /**
542
+ * Test case for a controller returning a view with deeply nested children
543
+ * View hierarchy:
544
+ * layout/layout -> baz/index/childview -> child1 -> child3
545
+ * -> child2
546
+ */
547
+ public function testSearchTemplatesVerifiesDeeplyNestedTemplateName (): void
548
+ {
549
+ $ this ->dispatch ('/childview ' );
550
+
551
+ // Check that the rendered content
552
+ $ this ->assertQueryContentContains ('p ' , 'Parent ' );
553
+ $ this ->assertQueryContentContains ('p ' , 'Child 1 ' );
554
+ $ this ->assertQueryContentContains ('p ' , 'Child 2 ' );
555
+ $ this ->assertQueryContentContains ('p ' , 'Child 3 ' );
556
+
557
+ $ this ->assertTemplateName ('layout/layout ' );
558
+ $ this ->assertTemplateName ('baz/index/childview ' );
559
+ $ this ->assertTemplateName ('child1 ' );
560
+ $ this ->assertTemplateName ('child2 ' );
561
+ $ this ->assertTemplateName ('child3 ' );
562
+ $ this ->assertNotTemplateName ('foo ' );
563
+ }
564
+
565
+ /**
566
+ * Check that the assertion fails when template is NOT found where it was supposed to found
567
+ */
568
+ public function testAssertTemplateNameFailsWhenNotFound (): void
569
+ {
570
+ $ this ->dispatch ('/childview ' );
571
+
572
+ try {
573
+ $ this ->assertTemplateName ('foo ' );
574
+ } catch (ExpectationFailedException $ exception ) {
575
+ $ this ->assertStringContainsString (
576
+ 'Failed asserting that view model tree contains template "foo" ' ,
577
+ $ exception ->getMessage ()
578
+ );
579
+ return ;
580
+ }
581
+ $ this ->fail ('Expected Exception not thrown ' );
582
+ }
583
+
584
+ /**
585
+ * Check that the assertion fails when template is found where it was NOT supposed to found
586
+ */
587
+ public function testAssertNotTemplateNameFailsWhenFound (): void
588
+ {
589
+ $ this ->dispatch ('/childview ' );
590
+
591
+ try {
592
+ $ this ->assertNotTemplateName ('child1 ' );
593
+ } catch (ExpectationFailedException $ exception ) {
594
+ $ this ->assertStringContainsString (
595
+ 'Failed asserting that view model tree does not contain template "child1" ' ,
596
+ $ exception ->getMessage ()
597
+ );
598
+ return ;
599
+ }
600
+ $ this ->fail ('Expected Exception not thrown ' );
601
+ }
602
+
541
603
public function testCustomResponseObject (): void
542
604
{
543
605
$ this ->dispatch ('/custom-response ' );
0 commit comments