diff --git a/inc/admin-pages/customer-panel/class-account-admin-page.php b/inc/admin-pages/customer-panel/class-account-admin-page.php index 8c2bf13b..6a6ec95d 100644 --- a/inc/admin-pages/customer-panel/class-account-admin-page.php +++ b/inc/admin-pages/customer-panel/class-account-admin-page.php @@ -98,7 +98,7 @@ class Account_Admin_Page extends Base_Customer_Facing_Admin_Page { protected $current_customer; /** - * The return_to URL for sovereign-tenant context. + * The return_to URL for external redirects. * * @since 2.0.0 * @var string|null diff --git a/inc/admin-pages/customer-panel/class-add-new-site-admin-page.php b/inc/admin-pages/customer-panel/class-add-new-site-admin-page.php index e0cbc64c..8b827fea 100644 --- a/inc/admin-pages/customer-panel/class-add-new-site-admin-page.php +++ b/inc/admin-pages/customer-panel/class-add-new-site-admin-page.php @@ -114,7 +114,7 @@ class Add_New_Site_Admin_Page extends Base_Customer_Facing_Admin_Page { protected $current_membership; /** - * The return_to URL for sovereign-tenant context. + * The return_to URL for external redirects. * * @since 2.0.0 * @var string|null diff --git a/inc/admin-pages/customer-panel/class-checkout-admin-page.php b/inc/admin-pages/customer-panel/class-checkout-admin-page.php index 44aeab44..5d5f044e 100644 --- a/inc/admin-pages/customer-panel/class-checkout-admin-page.php +++ b/inc/admin-pages/customer-panel/class-checkout-admin-page.php @@ -80,7 +80,7 @@ class Checkout_Admin_Page extends \WP_Ultimo\Admin_Pages\Base_Customer_Facing_Ad protected $fold_menu = true; /** - * The return_to URL for sovereign-tenant context. + * The return_to URL for external redirects. * * @since 2.0.0 * @var string|null diff --git a/inc/admin-pages/customer-panel/class-my-sites-admin-page.php b/inc/admin-pages/customer-panel/class-my-sites-admin-page.php index b634d273..ebc32725 100644 --- a/inc/admin-pages/customer-panel/class-my-sites-admin-page.php +++ b/inc/admin-pages/customer-panel/class-my-sites-admin-page.php @@ -98,7 +98,7 @@ class My_Sites_Admin_Page extends Base_Customer_Facing_Admin_Page { public $current_membership; /** - * The return_to URL for sovereign-tenant context. + * The return_to URL for external redirects. * * @since 2.0.0 * @var string|null diff --git a/inc/admin-pages/customer-panel/class-template-switching-admin-page.php b/inc/admin-pages/customer-panel/class-template-switching-admin-page.php index a1412505..586c0d2a 100644 --- a/inc/admin-pages/customer-panel/class-template-switching-admin-page.php +++ b/inc/admin-pages/customer-panel/class-template-switching-admin-page.php @@ -88,7 +88,7 @@ class Template_Switching_Admin_Page extends \WP_Ultimo\Admin_Pages\Base_Customer protected $menu_settings = false; /** - * The return_to URL for sovereign-tenant context. + * The return_to URL for external redirects. * * @since 2.0.0 * @var string|null @@ -166,7 +166,7 @@ public function output(): void { * * phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only display flag, no state change. */ - $action = isset($_GET['wu_template_action']) ? sanitize_key(wp_unslash($_GET['wu_template_action'])) : ''; + $action = isset($_GET['wu_template_action']) ? sanitize_key(wp_unslash($_GET['wu_template_action'])) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only display flag, no state change. $message = 'reset' === $action ? __('Template reset successfully!', 'ultimate-multisite') : __('Template switched successfully!', 'ultimate-multisite'); diff --git a/inc/checkout/class-cart.php b/inc/checkout/class-cart.php index 0504a60b..5acd7eed 100644 --- a/inc/checkout/class-cart.php +++ b/inc/checkout/class-cart.php @@ -261,19 +261,6 @@ class Cart implements \JsonSerializable { * @param array $args An array containing the cart arguments. */ public function __construct($args) { - /* - * Guard against instantiation in sovereign tenant context. - * Checkout should only run on the main site. - */ - if (wu_is_sovereign_tenant()) { - $this->attributes = (object) []; - $this->errors = new \WP_Error( - 'sovereign_checkout_disabled', - __('Checkout is disabled in sovereign tenant context.', 'ultimate-multisite') - ); - return; - } - /* * Why are we using shortcode atts, you might ask? * @@ -364,6 +351,10 @@ public function __construct($args) { */ $this->attributes = (object) $args; + if (apply_filters('wu_cart_skip_initialization', false, $args, $this)) { + return; + } + /** * Allow developers to make additional changes to * the checkout object. diff --git a/inc/checkout/class-checkout-pages.php b/inc/checkout/class-checkout-pages.php index ceab574f..e8894059 100644 --- a/inc/checkout/class-checkout-pages.php +++ b/inc/checkout/class-checkout-pages.php @@ -131,36 +131,12 @@ public function init(): void { add_action('save_post', [$this, 'handle_compat_mode_setting']); } - /* - * In sovereign tenant context, redirect checkout URLs to the main site. - */ - if (wu_is_sovereign_tenant()) { - add_filter('post_type_link', [$this, 'redirect_checkout_urls_in_sovereign_context'], 10, 2); - add_filter('page_link', [$this, 'redirect_checkout_urls_in_sovereign_context'], 10, 2); - } - } - - /** - * Gets the main site checkout URL. - * - * Used to redirect sovereign tenants to the main site for checkout. - * - * @since 2.5.2 - * @return string The main site checkout URL. - */ - public function get_main_site_checkout_url(): string { - - $main_site = get_blog_details(get_network()->site_id); - - if (! $main_site) { - return network_site_url('/register/'); - } - - return trailingslashit($main_site->siteurl) . 'register/'; + add_filter('post_type_link', [$this, 'filter_checkout_urls'], 10, 2); + add_filter('page_link', [$this, 'filter_checkout_urls'], 10, 2); } /** - * Redirects checkout URLs to the main site in sovereign tenant context. + * Filters checkout URLs. * * @since 2.5.2 * @@ -168,7 +144,7 @@ public function get_main_site_checkout_url(): string { * @param \WP_Post $post The post object. * @return string The modified permalink. */ - public function redirect_checkout_urls_in_sovereign_context($permalink, $post) { + public function filter_checkout_urls($permalink, $post) { if (! is_a($post, '\WP_Post')) { return $permalink; @@ -178,7 +154,7 @@ public function redirect_checkout_urls_in_sovereign_context($permalink, $post) { // Check if this post is a checkout-related page if (in_array($post->ID, array_filter($signup_pages), true)) { - return $this->get_main_site_checkout_url(); + return apply_filters('wu_checkout_pages_checkout_url', $permalink, $post, $this); } return $permalink; @@ -599,8 +575,6 @@ protected function rewrite_subsite_aware_login_url($url) { public function rewrite_new_user_notification_email($email, $user, $blogname) { unset($user, $blogname); - unset($user, $blogname); - if (empty($email['message']) || ! is_array($email)) { return $email; } @@ -634,8 +608,6 @@ function ($matches) { public function rewrite_password_notification_email($defaults, $key, $user_login, $user_data) { unset($key, $user_login, $user_data); - unset($key, $user_login, $user_data); - if (empty($defaults['message']) || ! is_array($defaults)) { return $defaults; } @@ -669,8 +641,6 @@ function ($matches) { public function rewrite_email_change_content($email_text, $new_user_email) { unset($new_user_email); - unset($new_user_email); - if (empty($email_text) || ! is_string($email_text)) { return $email_text; } diff --git a/inc/checkout/class-checkout.php b/inc/checkout/class-checkout.php index fa52fd72..423f2e24 100644 --- a/inc/checkout/class-checkout.php +++ b/inc/checkout/class-checkout.php @@ -232,25 +232,6 @@ public function init(): void { add_action('wu_checkout_errors', [$this, 'maybe_display_checkout_errors']); } - /** - * Gets the main site checkout URL. - * - * Used to redirect sovereign tenants to the main site for checkout. - * - * @since 2.5.2 - * @return string The main site checkout URL. - */ - public function get_main_site_checkout_url(): string { - - $main_site = get_blog_details(get_network()->site_id); - - if (! $main_site) { - return network_site_url('/register/'); - } - - return trailingslashit($main_site->siteurl) . 'register/'; - } - /** * Add checkout rewrite rules. * @@ -582,16 +563,7 @@ public function get_auto_submittable_fields() { */ public function maybe_handle_order_submission(): void { - if (wu_is_sovereign_tenant()) { - wp_send_json_error( - [ - 'code' => 'sovereign_checkout_disabled', - 'message' => __('Checkout runs on the main site.', 'ultimate-multisite'), - 'main_site_url' => $this->get_main_site_checkout_url(), - ], - 400 - ); - + if (apply_filters('wu_checkout_skip_order_submission', false, $this)) { return; } @@ -1876,16 +1848,7 @@ public function validate_form(): void { */ public function create_order(): void { - if (wu_is_sovereign_tenant()) { - wp_send_json_error( - [ - 'code' => 'sovereign_checkout_disabled', - 'message' => __('Checkout runs on the main site.', 'ultimate-multisite'), - 'main_site_url' => $this->get_main_site_checkout_url(), - ], - 400 - ); - + if (apply_filters('wu_checkout_skip_create_order', false, $this)) { return; } @@ -1950,16 +1913,7 @@ public function create_order(): void { */ public function check_user_exists(): void { - if (wu_is_sovereign_tenant()) { - wp_send_json_error( - [ - 'code' => 'sovereign_checkout_disabled', - 'message' => __('Checkout runs on the main site.', 'ultimate-multisite'), - 'main_site_url' => $this->get_main_site_checkout_url(), - ], - 400 - ); - + if (apply_filters('wu_checkout_skip_user_exists_check', false, $this)) { return; } @@ -2015,16 +1969,7 @@ public function check_user_exists(): void { */ public function handle_inline_login(): void { - if (wu_is_sovereign_tenant()) { - wp_send_json_error( - [ - 'code' => 'sovereign_checkout_disabled', - 'message' => __('Checkout runs on the main site.', 'ultimate-multisite'), - 'main_site_url' => $this->get_main_site_checkout_url(), - ], - 400 - ); - + if (apply_filters('wu_checkout_skip_inline_login', false, $this)) { return; } diff --git a/inc/class-wp-ultimo.php b/inc/class-wp-ultimo.php index 6a6e2e3a..19fdc307 100644 --- a/inc/class-wp-ultimo.php +++ b/inc/class-wp-ultimo.php @@ -353,7 +353,6 @@ public function load_public_apis(): void { require_once wu_path('inc/functions/reflection.php'); require_once wu_path('inc/functions/scheduler.php'); require_once wu_path('inc/functions/session.php'); - require_once wu_path('inc/functions/sovereign.php'); require_once wu_path('inc/functions/documentation.php'); /** diff --git a/inc/compat/class-auto-delete-users-compat.php b/inc/compat/class-auto-delete-users-compat.php index ac92ee2a..1699a171 100644 --- a/inc/compat/class-auto-delete-users-compat.php +++ b/inc/compat/class-auto-delete-users-compat.php @@ -36,7 +36,7 @@ class Auto_Delete_Users_Compat { */ public function init(): void { - if ( wu_is_sovereign_tenant() ) { + if ( apply_filters('wu_auto_delete_users_skip_compat', false, $this) ) { return; } diff --git a/inc/compat/class-edit-users-compat.php b/inc/compat/class-edit-users-compat.php index 6fdafa6e..26ca0069 100644 --- a/inc/compat/class-edit-users-compat.php +++ b/inc/compat/class-edit-users-compat.php @@ -36,7 +36,7 @@ class Edit_Users_Compat { */ public function init(): void { - if ( wu_is_sovereign_tenant() ) { + if ( apply_filters('wu_edit_users_skip_compat', false, $this) ) { return; } diff --git a/inc/compat/class-multiple-accounts-compat.php b/inc/compat/class-multiple-accounts-compat.php index 38b106c5..bac807d2 100644 --- a/inc/compat/class-multiple-accounts-compat.php +++ b/inc/compat/class-multiple-accounts-compat.php @@ -51,7 +51,7 @@ class Multiple_Accounts_Compat { */ public function init(): void { - if ( wu_is_sovereign_tenant() ) { + if ( apply_filters('wu_multiple_accounts_skip_compat', false, $this) ) { return; } diff --git a/inc/functions/sovereign.php b/inc/functions/sovereign.php deleted file mode 100644 index 17df0914..00000000 --- a/inc/functions/sovereign.php +++ /dev/null @@ -1,52 +0,0 @@ - wu_mt_main_site_account_url(), - 'element_label' => __('Your account', 'ultimate-multisite'), - ] - ); + if (apply_filters('wu_account_skip_output', false, $atts, $content, $this)) { return; } diff --git a/inc/ui/class-billing-info-element.php b/inc/ui/class-billing-info-element.php index 027d0c9f..6c523f80 100644 --- a/inc/ui/class-billing-info-element.php +++ b/inc/ui/class-billing-info-element.php @@ -270,14 +270,7 @@ public function setup_preview() { */ public function output($atts, $content = null) { - if (wu_is_sovereign_tenant()) { - echo wu_get_template_contents( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped - 'elements/sovereign-redirect', - [ - 'main_site_account_url' => wu_mt_main_site_account_url(), - 'element_label' => __('Billing information', 'ultimate-multisite'), - ] - ); + if (apply_filters('wu_billing_info_skip_output', false, $atts, $content, $this)) { return; } diff --git a/inc/ui/class-checkout-element.php b/inc/ui/class-checkout-element.php index 9dacf1a1..e15c4275 100644 --- a/inc/ui/class-checkout-element.php +++ b/inc/ui/class-checkout-element.php @@ -698,15 +698,7 @@ public function inject_inline_auto_submittable_field($auto_submittable_field): v */ public function output($atts, $content = null) { - // In sovereign tenant context, render a link to the main site checkout instead - if (wu_is_sovereign_tenant()) { - $checkout_pages = \WP_Ultimo\Checkout\Checkout_Pages::get_instance(); - $main_site_url = $checkout_pages->get_main_site_checkout_url(); - ?> - - - - wu_mt_main_site_account_url(), - 'element_label' => __('Subscription', 'ultimate-multisite'), - ] - ); + if (apply_filters('wu_current_membership_skip_output', false, $atts, $content, $this)) { return; } diff --git a/inc/ui/class-current-site-element.php b/inc/ui/class-current-site-element.php index 841519e0..fbc6527d 100644 --- a/inc/ui/class-current-site-element.php +++ b/inc/ui/class-current-site-element.php @@ -352,14 +352,7 @@ public function register_scripts() { */ public function output($atts, $content = null) { - if (wu_is_sovereign_tenant()) { - echo wu_get_template_contents( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped - 'elements/sovereign-redirect', - [ - 'main_site_account_url' => wu_mt_main_site_account_url(), - 'element_label' => __('Site actions', 'ultimate-multisite'), - ] - ); + if (apply_filters('wu_current_site_skip_output', false, $atts, $content, $this)) { return; } diff --git a/inc/ui/class-domain-mapping-element.php b/inc/ui/class-domain-mapping-element.php index 44319e96..8ad8dfb5 100644 --- a/inc/ui/class-domain-mapping-element.php +++ b/inc/ui/class-domain-mapping-element.php @@ -1097,14 +1097,7 @@ public function setup_preview() { */ public function output($atts, $content = null) { - if (wu_is_sovereign_tenant()) { - echo wu_get_template_contents( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped - 'elements/sovereign-redirect', - [ - 'main_site_account_url' => wu_mt_main_site_account_url(), - 'element_label' => __('Domain mapping', 'ultimate-multisite'), - ] - ); + if (apply_filters('wu_domain_mapping_skip_output', false, $atts, $content, $this)) { return; } diff --git a/inc/ui/class-invoices-element.php b/inc/ui/class-invoices-element.php index 96ebf6db..9406f3e5 100644 --- a/inc/ui/class-invoices-element.php +++ b/inc/ui/class-invoices-element.php @@ -272,14 +272,7 @@ public function setup_preview() { */ public function output($atts, $content = null) { - if (wu_is_sovereign_tenant()) { - echo wu_get_template_contents( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped - 'elements/sovereign-redirect', - [ - 'main_site_account_url' => wu_mt_main_site_account_url(), - 'element_label' => __('Invoices', 'ultimate-multisite'), - ] - ); + if (apply_filters('wu_invoices_skip_output', false, $atts, $content, $this)) { return; } diff --git a/inc/ui/class-my-sites-element.php b/inc/ui/class-my-sites-element.php index b1c76a62..b42f125b 100644 --- a/inc/ui/class-my-sites-element.php +++ b/inc/ui/class-my-sites-element.php @@ -323,14 +323,7 @@ public function setup_preview() { */ public function output($atts, $content = null) { - if (wu_is_sovereign_tenant()) { - echo wu_get_template_contents( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped - 'elements/sovereign-redirect', - [ - 'main_site_account_url' => wu_mt_main_site_account_url(), - 'element_label' => __('My sites', 'ultimate-multisite'), - ] - ); + if (apply_filters('wu_my_sites_skip_output', false, $atts, $content, $this)) { return; } diff --git a/inc/ui/class-template-switching-element.php b/inc/ui/class-template-switching-element.php index d9054a71..d6cb9c4e 100644 --- a/inc/ui/class-template-switching-element.php +++ b/inc/ui/class-template-switching-element.php @@ -430,14 +430,7 @@ public function switch_template() { */ public function output($atts, $content = null) { - if (wu_is_sovereign_tenant()) { - echo wu_get_template_contents( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped - 'elements/sovereign-redirect', - [ - 'main_site_account_url' => wu_mt_main_site_account_url(), - 'element_label' => __('Template switching', 'ultimate-multisite'), - ] - ); + if (apply_filters('wu_template_switching_skip_output', false, $atts, $content, $this)) { return; } diff --git a/tests/WP_Ultimo/Checkout/Checkout_Test.php b/tests/WP_Ultimo/Checkout/Checkout_Test.php index e7e6712f..ee8b2fcd 100644 --- a/tests/WP_Ultimo/Checkout/Checkout_Test.php +++ b/tests/WP_Ultimo/Checkout/Checkout_Test.php @@ -82,33 +82,48 @@ private function ensure_session(Checkout $checkout): void { } /** - * Enable the sovereign tenant checkout guards for the current test. + * Tear down test fixtures. */ - private function enable_sovereign_tenant_context(): void { - add_filter('wu_is_sovereign_tenant', [$this, 'return_true']); - } + protected function tearDown(): void { + remove_filter('wu_checkout_skip_create_order', [$this, 'skip_checkout']); + remove_filter('wu_checkout_skip_order_submission', [$this, 'skip_checkout']); + remove_filter('wu_checkout_skip_user_exists_check', [$this, 'skip_checkout']); + remove_filter('wu_checkout_skip_inline_login', [$this, 'skip_checkout']); + remove_filter('wu_cart_skip_initialization', [$this, 'set_cart_error']); - /** - * Disable the sovereign tenant checkout guards for the current test. - */ - private function disable_sovereign_tenant_context(): void { - remove_filter('wu_is_sovereign_tenant', [$this, 'return_true']); + parent::tearDown(); } /** - * Return true for filter callbacks. + * Skip a checkout handler via filter. + * + * @param bool $skip Whether the handler should be skipped. + * @param Checkout $checkout Checkout instance. + * @return bool */ - public function return_true(): bool { + public function skip_checkout($skip, $checkout) { + unset($skip, $checkout); + return true; } /** - * Tear down test fixtures. + * Set a cart error for skip filters. + * + * @param bool $skip Whether initialization should be skipped. + * @param array $args Cart arguments. + * @param Cart $cart Cart instance. + * @return bool */ - protected function tearDown(): void { - $this->disable_sovereign_tenant_context(); + public function set_cart_error($skip, $args, $cart) { + unset($skip, $args); - parent::tearDown(); + $cart->errors = new \WP_Error( + 'checkout_disabled', + __('Checkout is disabled by a skip-initialization filter.', 'ultimate-multisite') + ); + + return true; } // ------------------------------------------------------------------------- @@ -5371,134 +5386,102 @@ public function test_cleanup_expired_drafts_cleans_up_pending_site(): void { } // ------------------------------------------------------------------------- - // Sovereign Tenant Checkout Guards + // Checkout Skip Filters // ------------------------------------------------------------------------- /** - * Test that create_order returns error in sovereign tenant context. + * Test that create_order honours the skip filter. */ - public function test_create_order_returns_error_in_sovereign_context(): void { + public function test_create_order_returns_early_when_skip_filter_is_enabled(): void { - $this->enable_sovereign_tenant_context(); + add_filter('wu_checkout_skip_create_order', [$this, 'skip_checkout'], 10, 2); $checkout = Checkout::get_instance(); // Mock the AJAX request $_POST['wu_nonce'] = wp_create_nonce('wu_checkout'); - // Capture the JSON response ob_start(); $checkout->create_order(); $response = ob_get_clean(); - $data = json_decode($response, true); - - $this->assertFalse($data['success']); - $this->assertEquals('sovereign_checkout_disabled', $data['data']['code']); - $this->assertStringContainsString('main site', $data['data']['message']); - $this->assertNotEmpty($data['data']['main_site_url']); + $this->assertSame('', $response); } /** - * Test that maybe_handle_order_submission returns error in sovereign tenant context. + * Test that maybe_handle_order_submission honours the skip filter. */ - public function test_maybe_handle_order_submission_returns_error_in_sovereign_context(): void { + public function test_maybe_handle_order_submission_returns_early_when_skip_filter_is_enabled(): void { - $this->enable_sovereign_tenant_context(); + add_filter('wu_checkout_skip_order_submission', [$this, 'skip_checkout'], 10, 2); $checkout = Checkout::get_instance(); // Mock the AJAX request $_POST['wu_nonce'] = wp_create_nonce('wu_checkout'); - // Capture the JSON response ob_start(); $checkout->maybe_handle_order_submission(); $response = ob_get_clean(); - $data = json_decode($response, true); - - $this->assertFalse($data['success']); - $this->assertEquals('sovereign_checkout_disabled', $data['data']['code']); + $this->assertSame('', $response); } /** - * Test that check_user_exists returns error in sovereign tenant context. + * Test that check_user_exists honours the skip filter. */ - public function test_check_user_exists_returns_error_in_sovereign_context(): void { + public function test_check_user_exists_returns_early_when_skip_filter_is_enabled(): void { - $this->enable_sovereign_tenant_context(); + add_filter('wu_checkout_skip_user_exists_check', [$this, 'skip_checkout'], 10, 2); $checkout = Checkout::get_instance(); // Mock the AJAX request - $_POST['wu_nonce'] = wp_create_nonce('wu_checkout'); + $_POST['wu_nonce'] = wp_create_nonce('wu_checkout'); $_POST['field_type'] = 'email'; - $_POST['value'] = 'test@example.com'; + $_POST['value'] = 'test@example.com'; - // Capture the JSON response ob_start(); $checkout->check_user_exists(); $response = ob_get_clean(); - $data = json_decode($response, true); - - $this->assertFalse($data['success']); - $this->assertEquals('sovereign_checkout_disabled', $data['data']['code']); + $this->assertSame('', $response); } /** - * Test that handle_inline_login returns error in sovereign tenant context. + * Test that handle_inline_login honours the skip filter. */ - public function test_handle_inline_login_returns_error_in_sovereign_context(): void { + public function test_handle_inline_login_returns_early_when_skip_filter_is_enabled(): void { - $this->enable_sovereign_tenant_context(); + add_filter('wu_checkout_skip_inline_login', [$this, 'skip_checkout'], 10, 2); $checkout = Checkout::get_instance(); // Mock the AJAX request - $_POST['wu_nonce'] = wp_create_nonce('wu_checkout'); + $_POST['wu_nonce'] = wp_create_nonce('wu_checkout'); $_POST['username_or_email'] = 'test@example.com'; - $_POST['password'] = 'password123'; + $_POST['password'] = 'password123'; - // Capture the JSON response ob_start(); $checkout->handle_inline_login(); $response = ob_get_clean(); - $data = json_decode($response, true); - - $this->assertFalse($data['success']); - $this->assertEquals('sovereign_checkout_disabled', $data['data']['code']); + $this->assertSame('', $response); } /** - * Test that Cart constructor sets error in sovereign tenant context. + * Test that Cart constructor honours the skip filter response. */ - public function test_cart_constructor_sets_error_in_sovereign_context(): void { - - $this->enable_sovereign_tenant_context(); + public function test_cart_constructor_sets_error_when_skip_filter_responds(): void { - $this->assertTrue(\wu_is_sovereign_tenant()); + add_filter('wu_cart_skip_initialization', [$this, 'set_cart_error'], 10, 3); $cart = new Cart([ 'products' => [], ]); $this->assertTrue(is_wp_error($cart->errors)); - $this->assertEquals('sovereign_checkout_disabled', $cart->errors->get_error_code()); - } - - /** - * Test that get_main_site_checkout_url returns valid URL. - */ - public function test_get_main_site_checkout_url_returns_valid_url(): void { - - $checkout = Checkout::get_instance(); - $url = $checkout->get_main_site_checkout_url(); - - $this->assertNotEmpty($url); - $this->assertStringContainsString('register', $url); + $this->assertEquals('checkout_disabled', $cart->errors->get_error_code()); } // ------------------------------------------------------------------------- diff --git a/tests/WP_Ultimo/UI/Sovereign_Mode_Elements_Test.php b/tests/WP_Ultimo/UI/Sovereign_Mode_Elements_Test.php index 1ac96ef4..7959b590 100644 --- a/tests/WP_Ultimo/UI/Sovereign_Mode_Elements_Test.php +++ b/tests/WP_Ultimo/UI/Sovereign_Mode_Elements_Test.php @@ -1,6 +1,6 @@ + */ + private array $elements = []; + /** * Set up test fixtures. */ protected function setUp(): void { parent::setUp(); - // Load the sovereign helper function. - require_once dirname(__DIR__, 3) . '/inc/functions/sovereign.php'; - - add_filter('wu_is_sovereign_tenant', [$this, 'return_true']); + $this->elements = [ + 'wu_account_skip_output' => Account_Summary_Element::get_instance(), + 'wu_billing_info_skip_output' => Billing_Info_Element::get_instance(), + 'wu_invoices_skip_output' => Invoices_Element::get_instance(), + 'wu_my_sites_skip_output' => My_Sites_Element::get_instance(), + 'wu_current_membership_skip_output' => Current_Membership_Element::get_instance(), + 'wu_current_site_skip_output' => Current_Site_Element::get_instance(), + 'wu_template_switching_skip_output' => Template_Switching_Element::get_instance(), + 'wu_domain_mapping_skip_output' => Domain_Mapping_Element::get_instance(), + ]; + + foreach (array_keys($this->elements) as $hook) { + add_filter($hook, [$this, 'skip_output'], 10, 4); + } } /** * Tear down test fixtures. */ protected function tearDown(): void { - remove_filter('wu_is_sovereign_tenant', [$this, 'return_true']); + foreach (array_keys($this->elements) as $hook) { + remove_filter($hook, [$this, 'skip_output']); + } parent::tearDown(); } /** - * Return true for filter callbacks. - */ - public function return_true(): bool { - return true; - } - - /** - * Test Account_Summary_Element outputs redirect in sovereign mode. - */ - public function test_account_summary_element_sovereign_mode(): void { - $element = Account_Summary_Element::get_instance(); - - ob_start(); - $element->output([]); - $output = ob_get_clean(); - - $this->assertStringContainsString('wu-sovereign-redirect', $output); - $this->assertStringContainsString('manage on main site', $output); - $this->assertStringContainsString('Your account', $output); - } - - /** - * Test Billing_Info_Element outputs redirect in sovereign mode. - */ - public function test_billing_info_element_sovereign_mode(): void { - $element = Billing_Info_Element::get_instance(); - - ob_start(); - $element->output([]); - $output = ob_get_clean(); - - $this->assertStringContainsString('wu-sovereign-redirect', $output); - $this->assertStringContainsString('manage on main site', $output); - $this->assertStringContainsString('Billing information', $output); - } - - /** - * Test Invoices_Element outputs redirect in sovereign mode. - */ - public function test_invoices_element_sovereign_mode(): void { - $element = Invoices_Element::get_instance(); - - ob_start(); - $element->output([]); - $output = ob_get_clean(); - - $this->assertStringContainsString('wu-sovereign-redirect', $output); - $this->assertStringContainsString('manage on main site', $output); - $this->assertStringContainsString('Invoices', $output); - } - - /** - * Test My_Sites_Element outputs redirect in sovereign mode. - */ - public function test_my_sites_element_sovereign_mode(): void { - $element = My_Sites_Element::get_instance(); - - ob_start(); - $element->output([]); - $output = ob_get_clean(); - - $this->assertStringContainsString('wu-sovereign-redirect', $output); - $this->assertStringContainsString('manage on main site', $output); - $this->assertStringContainsString('My sites', $output); - } - - /** - * Test Current_Membership_Element outputs redirect in sovereign mode. + * Output filter callback. + * + * @param bool $skip Whether to skip default output. + * @param array $atts Element attributes. + * @param string|null $content Element content. + * @param object $element Element instance. + * @return bool */ - public function test_current_membership_element_sovereign_mode(): void { - $element = Current_Membership_Element::get_instance(); + public function skip_output($skip, $atts, $content, $element): bool { + unset($skip, $atts, $content, $element); - ob_start(); - $element->output([]); - $output = ob_get_clean(); - - $this->assertStringContainsString('wu-sovereign-redirect', $output); - $this->assertStringContainsString('manage on main site', $output); - $this->assertStringContainsString('Subscription', $output); - } - - /** - * Test Current_Site_Element outputs redirect in sovereign mode. - */ - public function test_current_site_element_sovereign_mode(): void { - $element = Current_Site_Element::get_instance(); - - ob_start(); - $element->output([]); - $output = ob_get_clean(); - - $this->assertStringContainsString('wu-sovereign-redirect', $output); - $this->assertStringContainsString('manage on main site', $output); - $this->assertStringContainsString('Site actions', $output); - } - - /** - * Test Template_Switching_Element outputs redirect in sovereign mode. - */ - public function test_template_switching_element_sovereign_mode(): void { - $element = Template_Switching_Element::get_instance(); + echo '