Files
unsupervised-scheduler/tests/bootstrap.php
T
thatguygriffandClaude Fable 5 9d89bc6d0e
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
Add link-target and auto-redirect options to booking/login blocks
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]>
2026-07-05 16:16:52 -03:00

109 lines
2.8 KiB
PHP

<?php
declare(strict_types=1);
require_once dirname(__DIR__) . '/vendor/autoload.php';
// Minimal WordPress constants required by plugin code under test.
if (! defined('ABSPATH')) {
define('ABSPATH', sys_get_temp_dir() . '/wordpress/');
}
define('WPINC', 'wp-includes');
define('USC_VERSION', '1.0.0');
define('USC_PLUGIN_FILE', dirname(__DIR__) . '/unsupervised-schedular.php');
define('USC_PLUGIN_DIR', dirname(__DIR__) . '/');
define('USC_PLUGIN_URL', 'http://example.com/wp-content/plugins/unsupervised-schedular/');
// Minimal WP_REST_Request stub: a simple parameter bag.
if (! class_exists('WP_REST_Request')) {
class WP_REST_Request
{
/** @param array<string, mixed> $params */
public function __construct(private array $params = [])
{
}
public function get_param(string $key): mixed
{
return $this->params[$key] ?? null;
}
public function set_param(string $key, mixed $value): void
{
$this->params[$key] = $value;
}
public function get_body(): string
{
return (string) ($this->params['__body'] ?? '');
}
public function get_header(string $key): string
{
return (string) ($this->params[$key] ?? '');
}
}
}
// Minimal WP_REST_Response stub exposing the data and status.
if (! class_exists('WP_REST_Response')) {
class WP_REST_Response
{
public function __construct(public mixed $data = null, public int $status = 200)
{
}
public function get_data(): mixed
{
return $this->data;
}
public function get_status(): int
{
return $this->status;
}
}
}
// Minimal WP_Post stub exposing the fields the plugin reads.
if (! class_exists('WP_Post')) {
class WP_Post
{
public int $ID = 0;
public string $post_content = '';
}
}
// Minimal WP_Error stub for code under test that returns error objects.
if (! class_exists('WP_Error')) {
class WP_Error
{
/** @var array<string, list<string>> */
public array $errors = [];
/** @var array<string, mixed> */
public array $error_data = [];
public function __construct(string $code = '', string $message = '', mixed $data = '')
{
if ('' !== $code) {
$this->errors[$code][] = $message;
if ('' !== $data) {
$this->error_data[$code] = $data;
}
}
}
public function get_error_code(): string
{
return (string) (array_key_first($this->errors) ?? '');
}
public function get_error_message(): string
{
$code = $this->get_error_code();
return '' !== $code ? ($this->errors[$code][0] ?? '') : '';
}
}
}