page = new BookingPage(); } public function testLoggedOutVisitorIsLinkedToTheWordPressLoginByDefault(): void { Functions\when('is_user_logged_in')->justReturn(false); Functions\when('get_permalink')->justReturn('https://example.com/book/'); Functions\when('wp_login_url')->alias( static fn(string $redirect): string => 'https://example.com/wp-login.php?redirect_to=' . $redirect ); $html = $this->page->render([]); self::assertStringContainsString( 'href="https://example.com/wp-login.php?redirect_to=https://example.com/book/"', $html ); self::assertStringContainsString('log in to book a lesson', $html); } public function testLoggedOutVisitorIsLinkedToTheChosenLoginPage(): void { Functions\when('is_user_logged_in')->justReturn(false); Functions\when('get_permalink')->alias( static fn(int $id = 0): string|false => 5 === $id ? 'https://example.com/login/' : false ); Functions\expect('wp_login_url')->never(); $html = $this->page->render(['loginPageId' => 5]); self::assertStringContainsString('href="https://example.com/login/"', $html); } public function testShortcodeStyleAttributeSelectsTheLoginPageToo(): void { Functions\when('is_user_logged_in')->justReturn(false); Functions\when('get_permalink')->alias( static fn(int $id = 0): string|false => 5 === $id ? 'https://example.com/login/' : false ); $html = $this->page->render(['login_page_id' => '5']); self::assertStringContainsString('href="https://example.com/login/"', $html); } public function testLoginUrlFallsBackToWordPressLoginWhenThePageIsGone(): void { // The chosen page was deleted: get_permalink() returns false for it // and for the current (test) context alike. Functions\when('get_permalink')->justReturn(false); Functions\when('wp_login_url')->alias( static fn(string $redirect): string => '' === $redirect ? 'https://example.com/wp-login.php' : 'https://example.com/wp-login.php?redirect_to=' . $redirect ); self::assertSame('https://example.com/wp-login.php', $this->page->loginUrl(5)); } }