CI / Coding Standards (pull_request) Successful in 51s
CI / No Debug Code (pull_request) Successful in 3s
CI / Tests (PHP 8.2) (pull_request) Successful in 50s
CI / Tests (PHP 8.3) (pull_request) Successful in 1m2s
CI / Build Plugin Zip (pull_request) Has been skipped
CI / Tests (PHP 8.1) (pull_request) Successful in 53s
CI / PHPStan (pull_request) Successful in 1m24s
The booking block gains a loginPageId attribute choosing which page its logged-out "log in to book a lesson" link points to (default remains the WordPress login screen), and the student-login block gains a bookingPageId attribute controlling the logged-in "View available lessons" link and the post-login redirect target (default remains the current page). Both blocks also gain an autoRedirect toggle, off by default, that sends the visitor straight to the target page; block rendering starts after output, so the redirect runs on template_redirect by parsing the queried page's content for the block, with a self-target guard against redirect loops. The link targets are also available to the shortcodes as login_page_id/booking_page_id. Also fixes a pre-existing fatal: WordPress passes an empty string (not an array) to shortcode callbacks when a shortcode is used without attributes, so bare [us_booking] etc. threw a TypeError against the strictly-typed render(array $atts) methods. ShortcodeRegistrar now wraps each callback to normalize non-array attribute values. Closes #51 Co-Authored-By: Claude Fable 5 <[email protected]>
95 lines
3.0 KiB
PHP
95 lines
3.0 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Unsupervised\Schedular\Tests\Unit\Auth;
|
|
|
|
use Brain\Monkey\Functions;
|
|
use Unsupervised\Schedular\Auth\LoginPage;
|
|
use Unsupervised\Schedular\Tests\Unit\TestCase;
|
|
|
|
class LoginPageTest extends TestCase
|
|
{
|
|
private LoginPage $page;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->page = new LoginPage();
|
|
}
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
unset($_POST['us_login']);
|
|
parent::tearDown();
|
|
}
|
|
|
|
public function testLoggedInVisitorIsLinkedToTheCurrentPageByDefault(): void
|
|
{
|
|
Functions\when('is_user_logged_in')->justReturn(true);
|
|
Functions\when('get_permalink')->alias(
|
|
static fn(int $id = 0): string|false => 0 === $id ? 'https://example.com/login/' : false
|
|
);
|
|
|
|
$html = $this->page->render([]);
|
|
|
|
self::assertStringContainsString('href="https://example.com/login/"', $html);
|
|
self::assertStringContainsString('View available lessons', $html);
|
|
}
|
|
|
|
public function testLoggedInVisitorIsLinkedToTheChosenBookingPage(): void
|
|
{
|
|
Functions\when('is_user_logged_in')->justReturn(true);
|
|
Functions\when('get_permalink')->alias(
|
|
static fn(int $id = 0): string|false => 9 === $id ? 'https://example.com/book/' : 'https://example.com/login/'
|
|
);
|
|
|
|
$html = $this->page->render(['bookingPageId' => 9]);
|
|
|
|
self::assertStringContainsString('href="https://example.com/book/"', $html);
|
|
}
|
|
|
|
public function testShortcodeStyleAttributeSelectsTheBookingPageToo(): void
|
|
{
|
|
Functions\when('is_user_logged_in')->justReturn(true);
|
|
Functions\when('get_permalink')->alias(
|
|
static fn(int $id = 0): string|false => 9 === $id ? 'https://example.com/book/' : 'https://example.com/login/'
|
|
);
|
|
|
|
$html = $this->page->render(['booking_page_id' => '9']);
|
|
|
|
self::assertStringContainsString('href="https://example.com/book/"', $html);
|
|
}
|
|
|
|
public function testLoggedOutVisitorSeesTheLoginForm(): void
|
|
{
|
|
Functions\when('is_user_logged_in')->justReturn(false);
|
|
Functions\when('get_permalink')->justReturn('https://example.com/login/');
|
|
Functions\when('sanitize_url')->returnArg();
|
|
Functions\when('wp_nonce_field')->justReturn('');
|
|
|
|
$html = $this->page->render([]);
|
|
|
|
self::assertStringContainsString('us-login-form', $html);
|
|
self::assertStringContainsString('name="us_login"', $html);
|
|
}
|
|
|
|
public function testBookingUrlIsNullWithoutAChosenPage(): void
|
|
{
|
|
self::assertNull($this->page->bookingUrl(0));
|
|
}
|
|
|
|
public function testBookingUrlIsNullWhenTheChosenPageIsGone(): void
|
|
{
|
|
Functions\when('get_permalink')->justReturn(false);
|
|
|
|
self::assertNull($this->page->bookingUrl(9));
|
|
}
|
|
|
|
public function testBookingUrlIsThePagePermalink(): void
|
|
{
|
|
Functions\when('get_permalink')->justReturn('https://example.com/book/');
|
|
|
|
self::assertSame('https://example.com/book/', $this->page->bookingUrl(9));
|
|
}
|
|
}
|