navigationService = $this->createMock(NavigationService::class); $this->themeService = $this->createMock(ThemeService::class); $this->page = $this->createMock(Page::class); $this->user = $this->createMock(User::class); $this->template = new DefaultPageHeaderTemplate( $this->navigationService, $this->themeService ); } protected function tearDown(): void { parent::tearDown(); unset($this->template, $this->navigationService, $this->themeService, $this->page, $this->user); } /** * @test */ public function it_renders_basic_header_with_page_title(): void { $this->page->method('getTitle')->willReturn('Test Page'); $this->page->method('getMetaDescription')->willReturn('Test description'); $this->themeService->method('getCurrentTheme')->willReturn('default'); $result = $this->template->render($this->page); $this->assertStringContainsString('Test Page', $result); $this->assertStringContainsString('', $result); } /** * @test */ public function it_renders_header_with_user_authentication(): void { $this->page->method('getTitle')->willReturn('Dashboard'); $this->user->method('getName')->willReturn('John Doe'); $this->user->method('getEmail')->willReturn('john@example.com'); $this->user->method('isAuthenticated')->willReturn(true); $result = $this->template->render($this->page, $this->user); $this->assertStringContainsString('John Doe', $result); $this->assertStringContainsString('john@example.com', $result); } /** * @test */ public function it_renders_header_for_anonymous_user(): void { $this->page->method('getTitle')->willReturn('Public Page'); $this->user->method('isAuthenticated')->willReturn(false); $result = $this->template->render($this->page, $this->user); $this->assertStringContainsString('Login', $result); $this->assertStringContainsString('Register', $result); $this->assertStringNotContainsString('Logout', $result); } /** * @test */ public function it_includes_navigation_menu(): void { $this->page->method('getTitle')->willReturn('Test Page'); $this->navigationService->method('getMainMenu')->willReturn([ ['label' => 'Home', 'url' => '/'], ['label' => 'About', 'url' => '/about'], ['label' => 'Contact', 'url' => '/contact'] ]); $result = $this->template->render($this->page); $this->assertStringContainsString('Home', $result); $this->assertStringContainsString('About', $result); $this->assertStringContainsString('Contact', $result); } /** * @test */ public function it_applies_theme_specific_styling(): void { $this->page->method('getTitle')->willReturn('Themed Page'); $this->themeService->method('getCurrentTheme')->willReturn('dark'); $this->themeService->method('getThemeStyles')->willReturn([ 'header-bg' => '#333333', 'header-text' => '#ffffff' ]); $result = $this->template->render($this->page); $this->assertStringContainsString('#333333', $result); $this->assertStringContainsString('#ffffff', $result); $this->assertStringContainsString('theme-dark', $result); } /** * @test */ public function it_handles_empty_page_title(): void { $this->page->method('getTitle')->willReturn(''); $this->page->method('getSlug')->willReturn('test-page'); $result = $this->template->render($this->page); $this->assertStringContainsString('Untitled Page', $result); } /** * @test */ public function it_handles_null_page_title(): void { $this->page->method('getTitle')->willReturn(null); $this->page->method('getSlug')->willReturn('test-page'); $result = $this->template->render($this->page); $this->assertStringContainsString('Untitled Page', $result); } /** * @test */ public function it_sanitizes_page_title_for_xss(): void { $this->page->method('getTitle')->willReturn(''); $result = $this->template->render($this->page); $this->assertStringNotContainsString('