Skip to content

Commit fcd760c

Browse files
committed
tests: add tests for namespaced view overrides
1 parent deb6945 commit fcd760c

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

tests/system/View/ViewTest.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,4 +413,57 @@ public function testViewExcerpt(): void
413413
$this->assertSame('CodeIgniter is a PHP full-stack web framework...', $view->excerpt('CodeIgniter is a PHP full-stack web framework that is light, fast, flexible and secure.', 48));
414414
$this->assertSame('CodeIgniter - это полнофункциональный веб-фреймворк...', $view->excerpt('CodeIgniter - это полнофункциональный веб-фреймворк на PHP, который является легким, быстрым, гибким и безопасным.', 54));
415415
}
416+
417+
public function testRenderNamespacedViewPriorityToAppViews(): void
418+
{
419+
$loader = $this->createMock(FileLocatorInterface::class);
420+
$loader->expects($this->never())->method('locateFile');
421+
422+
$view = new View($this->config, $this->viewsDir, $loader);
423+
424+
$view->setVar('testString', 'Hello World');
425+
$expected = '<h1>Hello World</h1>';
426+
427+
$output = $view->render('Nested\simple');
428+
429+
$this->assertStringContainsString($expected, $output);
430+
}
431+
432+
public function testRenderNamespacedViewFallsBackToLoader(): void
433+
{
434+
$namespacedView = 'Some\Library\View';
435+
436+
$realFile = $this->viewsDir . '/simple.php';
437+
438+
$loader = $this->createMock(FileLocatorInterface::class);
439+
$loader->expects($this->once())
440+
->method('locateFile')
441+
->with($namespacedView . '.php', 'Views', 'php')
442+
->willReturn($realFile);
443+
444+
$view = new View($this->config, $this->viewsDir, $loader);
445+
446+
$view->setVar('testString', 'Hello World');
447+
$output = $view->render($namespacedView);
448+
449+
$this->assertStringContainsString('<h1>Hello World</h1>', $output);
450+
}
451+
452+
public function testRenderNamespacedViewWithExplicitExtension(): void
453+
{
454+
$namespacedView = 'Some\Library\View.html';
455+
456+
$realFile = $this->viewsDir . '/simple.php';
457+
458+
$loader = $this->createMock(FileLocatorInterface::class);
459+
$loader->expects($this->once())
460+
->method('locateFile')
461+
->with($namespacedView, 'Views', 'html')
462+
->willReturn($realFile);
463+
464+
$view = new View($this->config, $this->viewsDir, $loader);
465+
$view->setVar('testString', 'Hello World');
466+
467+
$view->render($namespacedView);
468+
}
416469
}

0 commit comments

Comments
 (0)