diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1f588c14f..fe536990c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -222,16 +222,18 @@ jobs: for i in $(seq 1 60); do if curl -sf --max-time 5 http://127.0.0.1:9400/ > /dev/null 2>&1; then echo "Server is ready after ${i}s" + echo "baseline_server_ready=true" >> "$GITHUB_ENV" exit 0 fi echo " attempt $i/60..." sleep 5 done - echo "ERROR: Server did not become ready within 300 seconds" - exit 1 + echo "Baseline server did not become ready within 300 seconds; skipping advisory baseline metrics." + echo "baseline_server_ready=false" >> "$GITHUB_ENV" + echo "baseline_ok=false" >> "$GITHUB_ENV" - name: Run baseline performance tests - if: env.PERF_SKIP != 'true' + if: env.PERF_SKIP != 'true' && env.baseline_server_ready == 'true' run: | mkdir -p "$WP_PERF_ARTIFACTS" for attempt in 1 2 3; do @@ -293,16 +295,17 @@ jobs: for i in $(seq 1 60); do if curl -sf --max-time 5 http://127.0.0.1:9400/ > /dev/null 2>&1; then echo "Server is ready after ${i}s" + echo "pr_server_ready=true" >> "$GITHUB_ENV" exit 0 fi echo " attempt $i/60..." sleep 5 done - echo "ERROR: Server did not become ready within 300 seconds" - exit 1 + echo "PR server did not become ready within 300 seconds; skipping advisory PR metrics." + echo "pr_server_ready=false" >> "$GITHUB_ENV" - name: Run PR branch performance tests - if: env.PERF_SKIP != 'true' + if: env.PERF_SKIP != 'true' && env.pr_server_ready == 'true' run: | mkdir -p "$WP_PERF_ARTIFACTS" for attempt in 1 2 3; do diff --git a/assets/js/checkout-forms-editor.js b/assets/js/checkout-forms-editor.js index 228cf6620..7ad3e160f 100644 --- a/assets/js/checkout-forms-editor.js +++ b/assets/js/checkout-forms-editor.js @@ -196,25 +196,25 @@ }); - }, - scroll_to(element_id) { + }, + scroll_to(element_id) { - this.$nextTick(function() { + this.$nextTick(function() { - setTimeout(() => { + setTimeout(() => { - const element = document.getElementById(element_id); + const element = document.getElementById(element_id); - if (element) { - element.scrollIntoView({ behavior: 'smooth', block: 'center', inline: 'nearest' }); - } + if (element) { + element.scrollIntoView({ behavior: 'smooth', block: 'center', inline: 'nearest' }); + } - }, 500); + }, 500); - }); + }); - }, - find_step(step_name) { + }, + find_step(step_name) { return _.findWhere(this.steps, { id: step_name, diff --git a/assets/js/vue-apps.js b/assets/js/vue-apps.js index 325df7d26..f964367ef 100644 --- a/assets/js/vue-apps.js +++ b/assets/js/vue-apps.js @@ -78,7 +78,9 @@ } }, mounted() { - wu_on_load(); + if (typeof window.wu_on_load === "function") { + window.wu_on_load(); + } hooks.doAction("wu_" + app_id + "_mounted", this.$data); const cb = element.dataset.onLoad; if (typeof window[ cb ] === "function") { @@ -122,14 +124,15 @@ return typeof this[ value ] === "undefined" ? default_value : this[ value ]; }, duplicate_and_clean($event, query) { - let _a; const elements = document.querySelectorAll(query); const target = elements.item(elements.length - 1); const clone = target.cloneNode(true); clone.id = clone.id + "_copy"; const textAreas = clone.querySelectorAll("input, textarea"); textAreas.forEach((el) => el.value = ""); - (_a = target.parentNode) == null ? void 0 : _a.insertBefore(clone, target.nextSibling); + if (target.parentNode) { + target.parentNode.insertBefore(clone, target.nextSibling); + } }, wu_format_money(value) { return wu_format_money(value); @@ -141,7 +144,7 @@ if (Object.prototype.toString.call(value) === "[object Array]") { return value.indexOf(this[ data ]) > -1; } - return this[ data ] == value; + return this[ data ] === value; }, open($event) { $event.preventDefault(); @@ -155,7 +158,7 @@ url.searchParams.set(app_id, new_value); history.pushState({}, "", url); } catch (err) { - console.warn("Browser does not support pushState.", err); + window.console.warn("Browser does not support pushState.", err); } }); }; @@ -228,11 +231,11 @@ }); document.body.addEventListener("wubox:unload", function() { const modal = document.getElementById("WUB_window"); - if (!modal) { + if (! modal) { return; } const app = modal.querySelector("ul[data-wu-app]"); - if (!app) { + if (! app) { return; } const app_name = "wu_" + app.dataset.wuApp; @@ -242,4 +245,4 @@ document.body.addEventListener("wubox:load", loadApps); loadApps(); }); -})() \ No newline at end of file +})() diff --git a/inc/admin-pages/class-paypal-setup-wizard-admin-page.php b/inc/admin-pages/class-paypal-setup-wizard-admin-page.php index c71e7a74a..483c93118 100644 --- a/inc/admin-pages/class-paypal-setup-wizard-admin-page.php +++ b/inc/admin-pages/class-paypal-setup-wizard-admin-page.php @@ -127,7 +127,7 @@ public function get_menu_title() { public function get_sections() { return [ - 'welcome' => [ + 'welcome' => [ 'title' => __('Welcome', 'ultimate-multisite'), 'view' => [$this, 'section_welcome'], 'handler' => [$this, 'handle_welcome'], @@ -136,16 +136,16 @@ public function get_sections() { 'title' => __('Get Credentials', 'ultimate-multisite'), 'view' => [$this, 'section_instructions'], ], - 'configure' => [ + 'configure' => [ 'title' => __('Configure', 'ultimate-multisite'), 'view' => [$this, 'section_configure'], 'handler' => [$this, 'handle_configure'], ], - 'test' => [ + 'test' => [ 'title' => __('Test Connection', 'ultimate-multisite'), 'view' => [$this, 'section_test'], ], - 'done' => [ + 'done' => [ 'title' => __('Done', 'ultimate-multisite'), 'view' => [$this, 'section_done'], ], @@ -201,8 +201,8 @@ public function section_instructions(): void { wu_get_template( 'wizards/paypal-setup/instructions', [ - 'page' => $this, - 'sandbox_mode' => $this->sandbox_mode, + 'page' => $this, + 'sandbox_mode' => $this->sandbox_mode, 'developer_url' => $this->sandbox_mode ? 'https://developer.paypal.com/dashboard/applications/sandbox' : 'https://developer.paypal.com/dashboard/applications/live', @@ -228,13 +228,13 @@ public function section_configure(): void { wu_get_template( 'wizards/paypal-setup/configure', [ - 'page' => $this, - 'sandbox_mode' => $this->sandbox_mode, - 'mode_label' => $this->sandbox_mode + 'page' => $this, + 'sandbox_mode' => $this->sandbox_mode, + 'mode_label' => $this->sandbox_mode ? __('Sandbox', 'ultimate-multisite') : __('Live', 'ultimate-multisite'), - 'client_id' => $client_id, - 'client_secret' => $client_secret, + 'client_id' => $client_id, + 'client_secret' => $client_secret, ] ); } @@ -313,13 +313,13 @@ public function section_test(): void { 'wu-paypal-setup-wizard-test', 'wu_paypal_setup_wizard', [ - 'ajax_url' => admin_url('admin-ajax.php'), - 'nonce' => wp_create_nonce('wu_paypal_setup_wizard'), - 'sandbox_mode' => $this->sandbox_mode ? 1 : 0, - 'waiting_message' => __('Verifying your credentials with PayPal…', 'ultimate-multisite'), - 'success_message' => __('Your credentials were accepted by PayPal.', 'ultimate-multisite'), - 'webhook_message' => __('We installed the webhook automatically.', 'ultimate-multisite'), - 'error_message' => __('PayPal rejected the credentials. Double-check the Client ID and Secret on the previous step.', 'ultimate-multisite'), + 'ajax_url' => admin_url('admin-ajax.php'), + 'nonce' => wp_create_nonce('wu_paypal_setup_wizard'), + 'sandbox_mode' => $this->sandbox_mode ? 1 : 0, + 'waiting_message' => __('Verifying your credentials with PayPal…', 'ultimate-multisite'), + 'success_message' => __('Your credentials were accepted by PayPal.', 'ultimate-multisite'), + 'webhook_message' => __('We installed the webhook automatically.', 'ultimate-multisite'), + 'error_message' => __('PayPal rejected the credentials. Double-check the Client ID and Secret on the previous step.', 'ultimate-multisite'), ] ); @@ -465,9 +465,9 @@ public function ajax_test_credentials(): void { } // Credentials valid — try to install the webhook automatically. - $webhook_status = 'not_attempted'; - $webhook_message = ''; - $gateway = wu_get_gateway('paypal-rest'); + $webhook_status = 'not_attempted'; + $webhook_message = ''; + $gateway = wu_get_gateway('paypal-rest'); if ($gateway instanceof PayPal_REST_Gateway) { $gateway->set_test_mode($sandbox); diff --git a/inc/apis/trait-mcp-abilities.php b/inc/apis/trait-mcp-abilities.php index 1f632f6e7..80c0d9171 100644 --- a/inc/apis/trait-mcp-abilities.php +++ b/inc/apis/trait-mcp-abilities.php @@ -753,13 +753,13 @@ public function mcp_get_items(array $args): array { $filter_columns = array_keys($this->get_model_filter_columns()); foreach ($filter_columns as $column) { - if (isset($args[$column]) && empty($args[$column]) && $args[$column] !== false) { - unset($args[$column]); + if (isset($args[ $column ]) && empty($args[ $column ]) && false !== $args[ $column ]) { + unset($args[ $column ]); } } // Also strip empty search strings. - if (isset($args['search']) && $args['search'] === '') { + if (isset($args['search']) && '' === $args['search']) { unset($args['search']); } diff --git a/inc/class-ajax.php b/inc/class-ajax.php index 940c21f81..e575b3f90 100644 --- a/inc/class-ajax.php +++ b/inc/class-ajax.php @@ -85,7 +85,6 @@ public function refresh_list_table(): void { * @return void */ public function search_models(): void { - /* * The selectize search endpoint returns network-wide objects * (customers, memberships, payments and — for the 'user' model — @@ -343,12 +342,12 @@ public function search_wp_ultimo_setting($query): array { $section['fields'] = array_map( function ($item) use ($section, $section_slug) { - $item['section'] = $section_slug; + $item['section'] = $section_slug; - // Normalise to string so array_filter never strips it and - // the JS template always receives a defined scalar value. - $raw_title = wu_get_isset($section, 'title', ''); - $item['section_title'] = is_scalar($raw_title) ? (string) $raw_title : ''; + // Normalise to string so array_filter never strips it and + // the JS template always receives a defined scalar value. + $raw_title = wu_get_isset($section, 'title', ''); + $item['section_title'] = is_scalar($raw_title) ? (string) $raw_title : ''; $item['url'] = wu_network_admin_url( 'wp-ultimo-settings', diff --git a/inc/class-signup-metrics.php b/inc/class-signup-metrics.php index 642f58edf..51dab67e6 100644 --- a/inc/class-signup-metrics.php +++ b/inc/class-signup-metrics.php @@ -106,13 +106,14 @@ public function track_checkout_started($element): void { * * @since 2.5.0 * - * @param \WP_Ultimo\Checkout\Cart $order The cart/order object. - * @param \WP_Ultimo\Models\Customer $customer The customer. + * @param \WP_Ultimo\Checkout\Cart $order The cart/order object. + * @param \WP_Ultimo\Models\Customer $customer The customer. * @param \WP_Ultimo\Models\Membership $membership The primary membership. - * @param \WP_Ultimo\Models\Payment $payment The payment. + * @param \WP_Ultimo\Models\Payment $payment The payment. * @return void */ public function track_checkout_step_completed($order, $customer, $membership, $payment): void { + unset($payment); $plan = $order->get_plan(); @@ -149,6 +150,7 @@ public function track_checkout_step_completed($order, $customer, $membership, $p * @return void */ public function track_checkout_completed($payment, $membership, $customer, $order, $type, $checkout): void { + unset($checkout); $plan = $order ? $order->get_plan() : null; diff --git a/inc/database/engine/class-query.php b/inc/database/engine/class-query.php index 5a381dfa5..3aa6d6197 100644 --- a/inc/database/engine/class-query.php +++ b/inc/database/engine/class-query.php @@ -143,7 +143,7 @@ public function get_columns($args = array(), $operator = 'and', $field = false) * Default true. * @return int|false Number of rows affected, or false on failure. */ - public function increment_item( $item_id = 0, $increments = [], $sets = [], $invalidate_cache = true ) { + public function increment_item($item_id = 0, $increments = [], $sets = [], $invalidate_cache = true) { // Bail if nothing to do. if ( empty( $increments ) && empty( $sets ) ) { @@ -173,7 +173,7 @@ public function increment_item( $item_id = 0, $increments = [], $sets = [], $inv $valid_columns = array_flip( $this->get_columns( [], 'and', 'name' ) ); // Get the primary column name. - $primary_columns = $this->get_columns( [ 'primary' => true ], 'and', 'name' ); + $primary_columns = $this->get_columns( ['primary' => true], 'and', 'name' ); $primary = ! empty( $primary_columns ) ? reset( $primary_columns ) : 'id'; // Build SET clause fragments and prepare values. @@ -227,7 +227,7 @@ public function increment_item( $item_id = 0, $increments = [], $sets = [], $inv // Build and execute the query. $sql = sprintf( - "UPDATE `%s` SET %s WHERE `%s` = %%d", + 'UPDATE `%s` SET %s WHERE `%s` = %%d', $table, implode( ', ', $set_clauses ), $primary diff --git a/inc/gateways/class-base-stripe-gateway.php b/inc/gateways/class-base-stripe-gateway.php index 0ea9b782c..4beddc1d4 100644 --- a/inc/gateways/class-base-stripe-gateway.php +++ b/inc/gateways/class-base-stripe-gateway.php @@ -2940,7 +2940,7 @@ public function process_webhooks() { * Subscription payment received. */ } else { - $invoice_currency = strtoupper($invoice->currency ?? 'USD'); + $invoice_currency = strtoupper($invoice->currency ?? 'USD'); $payment_data['total'] = $invoice->total / wu_stripe_get_currency_multiplier($invoice_currency); $payment_data['subtotal'] = ($invoice->total_excluding_tax / wu_stripe_get_currency_multiplier($invoice_currency)) - $payment_data['discount_total']; $payment_data['tax_total'] = $invoice->tax / wu_stripe_get_currency_multiplier($invoice_currency); @@ -3317,7 +3317,7 @@ public function process_webhooks() { $expiration = ''; } - $new_status = 'trialing' === $stripe_status ? Membership_Status::TRIALING : Membership_Status::ACTIVE; + $new_status = 'trialing' === $stripe_status ? Membership_Status::TRIALING : Membership_Status::ACTIVE; /* * Use reactivate() for expired/cancelled memberships so that diff --git a/inc/gateways/class-paypal-rest-gateway.php b/inc/gateways/class-paypal-rest-gateway.php index 036a7bec3..7bfb59565 100644 --- a/inc/gateways/class-paypal-rest-gateway.php +++ b/inc/gateways/class-paypal-rest-gateway.php @@ -747,9 +747,9 @@ protected function api_request(string $endpoint, array $data = [], string $metho 'wu_paypal_api_error', $error_msg, [ - 'status' => $code, - 'response' => $body, - 'debug_id' => $debug_id, + 'status' => $code, + 'response' => $body, + 'debug_id' => $debug_id, ] ); } @@ -1114,7 +1114,7 @@ protected function create_order($payment, $membership, $customer, $cart, $type): 'email_address' => $customer->get_email_address(), ], ], - 'purchase_units' => [ $purchase_unit ], + 'purchase_units' => [$purchase_unit], ]; /** @@ -1944,27 +1944,6 @@ public function render_oauth_connection(): void { // Enqueue the connect/disconnect scripts $this->enqueue_connect_scripts(); - - // Fee notice (mirrors Stripe Connect fee notice) -// if (! \WP_Ultimo::get_instance()->get_addon_repository()->has_addon_purchase()) { -// printf( -// '
%s
%s
', -// esc_html( -// sprintf( -// /* translators: %s: the fee percentage */ -// __('There is a %s%% fee per-transaction to use the PayPal integration included in the free Ultimate Multisite plugin.', 'ultimate-multisite'), -// number_format_i18n($this->get_platform_fee_percent(), 0) -// ) -// ), -// esc_url(network_admin_url('admin.php?page=wp-ultimo-addons')), -// esc_html__('Remove this fee by purchasing any addon and connecting your store.', 'ultimate-multisite') -// ); -// } else { -// printf( -// '

%s

', -// esc_html__('No application fee — thank you for your support!', 'ultimate-multisite') -// ); -// } } /** @@ -2229,9 +2208,9 @@ public function verify_and_complete_payment($payment_id) { // Subscription is ACTIVE — try to find the transaction ID for the first payment. $gateway_payment_id = ''; - $start_time = gmdate('Y-m-d\TH:i:s\Z', strtotime('-1 day')); - $end_time = gmdate('Y-m-d\TH:i:s\Z'); - $transactions = $this->api_request( + $start_time = gmdate('Y-m-d\TH:i:s\Z', strtotime('-1 day')); + $end_time = gmdate('Y-m-d\TH:i:s\Z'); + $transactions = $this->api_request( sprintf('/v1/billing/subscriptions/%s/transactions?start_time=%s&end_time=%s', $subscription_id, $start_time, $end_time), [], 'GET' diff --git a/inc/gateways/class-paypal-webhook-handler.php b/inc/gateways/class-paypal-webhook-handler.php index 93ed40218..0571eace9 100644 --- a/inc/gateways/class-paypal-webhook-handler.php +++ b/inc/gateways/class-paypal-webhook-handler.php @@ -486,11 +486,13 @@ protected function handle_payment_completed(array $event_data): void { // Check for the original pending payment created during checkout (first payment only). // When a subscription returns APPROVED, we leave the initial payment as PENDING and // expect this webhook to confirm it rather than creating a duplicate. - $pending_payments = wu_get_payments([ - 'membership_id' => $membership->get_id(), - 'status' => Payment_Status::PENDING, - 'number' => 1, - ]); + $pending_payments = wu_get_payments( + [ + 'membership_id' => $membership->get_id(), + 'status' => Payment_Status::PENDING, + 'number' => 1, + ] + ); $payment = ! empty($pending_payments) ? $pending_payments[0] : null; diff --git a/inc/helpers/class-aws-signer.php b/inc/helpers/class-aws-signer.php index eb971f7a2..81a827087 100644 --- a/inc/helpers/class-aws-signer.php +++ b/inc/helpers/class-aws-signer.php @@ -92,12 +92,12 @@ public function __construct(string $access_key, string $secret_key, string $regi */ public function sign(string $method, string $url, string $payload = ''): array { - $parsed = wp_parse_url($url); - $uri = $parsed['path'] ?? '/'; - $query = $parsed['query'] ?? ''; - $host = $parsed['host'] ?? ''; - $amz_date = gmdate('Ymd\THis\Z'); - $date_stamp = gmdate('Ymd'); + $parsed = wp_parse_url($url); + $uri = $parsed['path'] ?? '/'; + $query = $parsed['query'] ?? ''; + $host = $parsed['host'] ?? ''; + $amz_date = gmdate('Ymd\THis\Z'); + $date_stamp = gmdate('Ymd'); $payload_hash = hash('sha256', $payload); $canonical_headers = "host:{$host}\n" . diff --git a/inc/helpers/class-screenshot.php b/inc/helpers/class-screenshot.php index bf70a2024..87998d27b 100644 --- a/inc/helpers/class-screenshot.php +++ b/inc/helpers/class-screenshot.php @@ -73,11 +73,11 @@ public static function api_url($domain, int $width = self::DEFAULT_WIDTH, int $h $url = add_query_arg( [ - 'url' => 'https://' . $clean_domain, - 'screenshot' => 'true', - 'viewport.width' => $width, - 'viewport.height' => $height, - 'embed' => 'screenshot.url', + 'url' => 'https://' . $clean_domain, + 'screenshot' => 'true', + 'viewport.width' => $width, + 'viewport.height' => $height, + 'embed' => 'screenshot.url', ], 'https://api.microlink.io/' ); diff --git a/inc/integrations/host-providers/class-hestia-host-provider.php b/inc/integrations/host-providers/class-hestia-host-provider.php index 3c4454306..20c3c812c 100644 --- a/inc/integrations/host-providers/class-hestia-host-provider.php +++ b/inc/integrations/host-providers/class-hestia-host-provider.php @@ -629,5 +629,4 @@ public function delete_dns_record(string $domain, string $record_id) { return true; } - } diff --git a/inc/integrations/providers/cyberpanel/class-cyberpanel-domain-mapping.php b/inc/integrations/providers/cyberpanel/class-cyberpanel-domain-mapping.php index ceda4b417..32a148daf 100644 --- a/inc/integrations/providers/cyberpanel/class-cyberpanel-domain-mapping.php +++ b/inc/integrations/providers/cyberpanel/class-cyberpanel-domain-mapping.php @@ -124,12 +124,15 @@ public function on_add_domain(string $domain, int $site_id): void { $master_domain = $this->get_cyberpanel()->get_master_domain(); - wu_log_add('integration-cyberpanel', sprintf( + wu_log_add( + 'integration-cyberpanel', + sprintf( 'Adding child domain: %s for site ID: %d (master: %s)', $domain, $site_id, $master_domain - )); + ) + ); // Step 1: Add as child domain so it shares the master's document root $result = $this->create_child_domain($domain, $master_domain); @@ -217,12 +220,15 @@ private function create_child_domain(string $domain, string $master_domain) { $username = $this->get_cyberpanel()->get_credential('WU_CYBERPANEL_USERNAME'); - return $this->get_cyberpanel()->api_call('addChildDomain', [ - 'masterDomain' => $master_domain, - 'childDomain' => $domain, - 'owner' => $username, - 'path' => '/home/' . $master_domain . '/public_html', - ]); + return $this->get_cyberpanel()->api_call( + 'addChildDomain', + [ + 'masterDomain' => $master_domain, + 'childDomain' => $domain, + 'owner' => $username, + 'path' => '/home/' . $master_domain . '/public_html', + ] + ); } /** @@ -236,10 +242,13 @@ private function create_child_domain(string $domain, string $master_domain) { */ private function delete_child_domain(string $domain, string $master_domain) { - return $this->get_cyberpanel()->api_call('deleteChildDomain', [ - 'masterDomain' => $master_domain, - 'childDomain' => $domain, - ]); + return $this->get_cyberpanel()->api_call( + 'deleteChildDomain', + [ + 'masterDomain' => $master_domain, + 'childDomain' => $domain, + ] + ); } /** @@ -257,10 +266,13 @@ private function delete_child_domain(string $domain, string $master_domain) { */ private function issue_ssl(string $master_domain, string $child_domain): void { - $result = $this->get_cyberpanel()->api_call('submitWebsiteStatus', [ - 'websiteName' => $master_domain, - 'state' => 'issueSSL', - ]); + $result = $this->get_cyberpanel()->api_call( + 'submitWebsiteStatus', + [ + 'websiteName' => $master_domain, + 'state' => 'issueSSL', + ] + ); if (is_wp_error($result)) { wu_log_add('integration-cyberpanel', 'SSL issuance failed for ' . $child_domain . ': ' . $result->get_error_message(), LogLevel::ERROR); diff --git a/inc/invoices/class-invoice.php b/inc/invoices/class-invoice.php index 66da7f3e5..3436e2ca9 100644 --- a/inc/invoices/class-invoice.php +++ b/inc/invoices/class-invoice.php @@ -170,7 +170,7 @@ private function get_rtl_fontdata(): array { */ private function pdf_setup(): void { - $this->printer = new Mpdf( + $this->printer = new Mpdf( [ 'mode' => '+aCJK', 'autoScriptToLang' => true, diff --git a/inc/limits/class-customer-user-role-limits.php b/inc/limits/class-customer-user-role-limits.php index 08a3eaec8..3a62af6c4 100644 --- a/inc/limits/class-customer-user-role-limits.php +++ b/inc/limits/class-customer-user-role-limits.php @@ -29,11 +29,11 @@ class Customer_User_Role_Limits { */ public function init(): void { - add_action( 'in_admin_header', array( $this, 'block_new_user_page' ) ); + add_action( 'in_admin_header', array($this, 'block_new_user_page') ); - add_action( 'wu_async_after_membership_update_products', array( $this, 'update_site_user_roles' ) ); + add_action( 'wu_async_after_membership_update_products', array($this, 'update_site_user_roles') ); - add_filter( 'editable_roles', array( $this, 'filter_editable_roles' ) ); + add_filter( 'editable_roles', array($this, 'filter_editable_roles') ); if ( ! wu_get_current_site()->has_module_limitation( 'customer_user_role' ) ) { return; @@ -70,7 +70,7 @@ public function block_new_user_page(): void { */ $message = apply_filters( 'wu_users_membership_limit_message', $message ); - wp_die( esc_html( $message ), esc_html__( 'Limit Reached', 'ultimate-multisite' ), array( 'back_link' => true ) ); + wp_die( esc_html( $message ), esc_html__( 'Limit Reached', 'ultimate-multisite' ), array('back_link' => true) ); } /** @@ -81,7 +81,7 @@ public function block_new_user_page(): void { * @param array $roles The list of available roles. * @return array */ - public function filter_editable_roles( $roles ) { + public function filter_editable_roles($roles) { if ( ! is_admin() || ! is_user_logged_in() ) { return $roles; } @@ -124,7 +124,7 @@ public function filter_editable_roles( $roles ) { * @param int $membership_id The membership upgraded or downgraded. * @return void */ - public function update_site_user_roles( $membership_id ): void { + public function update_site_user_roles($membership_id): void { $membership = wu_get_membership( $membership_id ); @@ -167,7 +167,7 @@ public function update_site_user_roles( $membership_id ): void { * @param int $membership_id The membership that was updated. * @return void */ - public function handle_downgrade( $membership_id ): void { + public function handle_downgrade($membership_id): void { $membership = wu_get_membership( $membership_id ); @@ -182,7 +182,6 @@ public function handle_downgrade( $membership_id ): void { $sites = $membership->get_sites( false ); foreach ( $sites as $site ) { - $blog_id = $site->get_id(); switch_to_blog( $blog_id ); @@ -192,7 +191,6 @@ public function handle_downgrade( $membership_id ): void { $all_roles = wp_roles()->get_names(); foreach ( array_keys( $all_roles ) as $role ) { - $limit = $users_limitation->{$role}; if ( ! property_exists( $limit, 'enabled' ) || ! $limit->enabled ) { @@ -225,7 +223,6 @@ public function handle_downgrade( $membership_id ): void { $users_to_demote = array_slice( $users_in_role, 0, $excess ); foreach ( $users_to_demote as $user_id ) { - if ( is_super_admin( $user_id ) ) { continue; } diff --git a/inc/limits/class-disk-space-limits.php b/inc/limits/class-disk-space-limits.php index 664f3ee3a..445410f7b 100644 --- a/inc/limits/class-disk-space-limits.php +++ b/inc/limits/class-disk-space-limits.php @@ -46,11 +46,11 @@ class Disk_Space_Limits { */ public function init(): void { - add_filter( 'site_option_upload_space_check_disabled', array( $this, 'upload_space_check_disabled' ) ); + add_filter( 'site_option_upload_space_check_disabled', array($this, 'upload_space_check_disabled') ); - add_filter( 'get_space_allowed', array( $this, 'apply_disk_space_limitations' ) ); + add_filter( 'get_space_allowed', array($this, 'apply_disk_space_limitations') ); - add_action( 'wu_async_after_membership_update_products', array( $this, 'handle_downgrade' ) ); + add_action( 'wu_async_after_membership_update_products', array($this, 'handle_downgrade') ); } /** @@ -62,7 +62,7 @@ public function init(): void { * @param int $value The current value. * @return int */ - public function upload_space_check_disabled( $value ) { + public function upload_space_check_disabled($value) { if ( ! $this->should_load() ) { return $value; @@ -120,7 +120,7 @@ protected function should_load() { * @param int $membership_id The membership that was updated. * @return void */ - public function handle_downgrade( $membership_id ): void { + public function handle_downgrade($membership_id): void { $membership = wu_get_membership( $membership_id ); @@ -131,7 +131,6 @@ public function handle_downgrade( $membership_id ): void { $sites = $membership->get_sites( false ); foreach ( $sites as $site ) { - $blog_id = $site->get_id(); switch_to_blog( $blog_id ); @@ -181,7 +180,7 @@ public function handle_downgrade( $membership_id ): void { * @param string $disk_space The new disk space. * @return int */ - public function apply_disk_space_limitations( $disk_space ) { + public function apply_disk_space_limitations($disk_space) { if ( ! $this->should_load() ) { return $disk_space; diff --git a/inc/limits/class-post-type-limits.php b/inc/limits/class-post-type-limits.php index 56eb18bb7..ef32ea54c 100644 --- a/inc/limits/class-post-type-limits.php +++ b/inc/limits/class-post-type-limits.php @@ -35,7 +35,7 @@ public function init(): void { * @since 2.0.6 */ if ( is_main_site() && is_network_admin() ) { - add_action( 'init', array( $this, 'register_emulated_post_types' ), 999 ); + add_action( 'init', array($this, 'register_emulated_post_types'), 999 ); } /** @@ -56,17 +56,17 @@ public function init(): void { return; } - add_action( 'load-post-new.php', array( $this, 'limit_posts' ) ); + add_action( 'load-post-new.php', array($this, 'limit_posts') ); - add_filter( 'wp_handle_upload', array( $this, 'limit_media' ) ); + add_filter( 'wp_handle_upload', array($this, 'limit_media') ); - add_filter( 'media_upload_tabs', array( $this, 'limit_tabs' ) ); + add_filter( 'media_upload_tabs', array($this, 'limit_tabs') ); - add_action( 'current_screen', array( $this, 'limit_restoring' ), 10 ); + add_action( 'current_screen', array($this, 'limit_restoring'), 10 ); - add_filter( 'wp_insert_post_data', array( $this, 'limit_draft_publishing' ), 10, 2 ); + add_filter( 'wp_insert_post_data', array($this, 'limit_draft_publishing'), 10, 2 ); - add_action( 'wu_async_after_membership_update_products', array( $this, 'handle_downgrade' ) ); + add_action( 'wu_async_after_membership_update_products', array($this, 'handle_downgrade') ); } /** @@ -182,14 +182,14 @@ public function limit_posts(): void { if ( ! wu_get_current_site()->get_limitations()->post_types->{$screen->post_type}->enabled ) { $upgrade_message = __( 'Your plan does not support this post type.', 'ultimate-multisite' ); - wp_die( esc_html( $upgrade_message ), esc_html( __( 'Limit Reached', 'ultimate-multisite' ) ), array( 'back_link' => true ) ); + wp_die( esc_html( $upgrade_message ), esc_html( __( 'Limit Reached', 'ultimate-multisite' ) ), array('back_link' => true) ); } // Check if that is more than our limit if ( wu_get_current_site()->get_limitations()->post_types->is_post_above_limit( $screen->post_type ) ) { $upgrade_message = __( 'You reached your plan\'s post limit.', 'ultimate-multisite' ); - wp_die( esc_html( $upgrade_message ), esc_html__( 'Limit Reached', 'ultimate-multisite' ), array( 'back_link' => true ) ); + wp_die( esc_html( $upgrade_message ), esc_html__( 'Limit Reached', 'ultimate-multisite' ), array('back_link' => true) ); } } @@ -203,7 +203,7 @@ public function limit_posts(): void { * @param array $modified_data Data that is changing. We are interested in publish. * @return array */ - public function limit_draft_publishing( $data, $modified_data ) { + public function limit_draft_publishing($data, $modified_data) { global $current_screen; @@ -239,7 +239,7 @@ public function limit_draft_publishing( $data, $modified_data ) { * @param array $file $_FILE array being passed. * @return mixed */ - public function limit_media( $file ) { + public function limit_media($file) { if ( ! wu_get_current_site()->get_limitations()->post_types->attachment->enabled ) { $file['error'] = __( 'Your plan does not support media upload.', 'ultimate-multisite' ); @@ -290,7 +290,7 @@ public function limit_media( $file ) { * @param int $membership_id The membership that was updated. * @return void */ - public function handle_downgrade( $membership_id ): void { + public function handle_downgrade($membership_id): void { $membership = wu_get_membership( $membership_id ); @@ -301,7 +301,6 @@ public function handle_downgrade( $membership_id ): void { $sites = $membership->get_sites( false ); foreach ( $sites as $site ) { - $blog_id = $site->get_id(); switch_to_blog( $blog_id ); @@ -316,7 +315,6 @@ public function handle_downgrade( $membership_id ): void { $over_limit = $post_type_limits->check_all_post_types(); foreach ( $over_limit as $post_type => $counts ) { - $excess = $counts['current'] - $counts['limit']; if ( $excess <= 0 ) { @@ -327,7 +325,7 @@ public function handle_downgrade( $membership_id ): void { $posts_to_demote = get_posts( array( 'post_type' => $post_type, - 'post_status' => array( 'publish', 'private' ), + 'post_status' => array('publish', 'private'), 'posts_per_page' => $excess, 'orderby' => 'ID', 'order' => 'ASC', @@ -336,7 +334,6 @@ public function handle_downgrade( $membership_id ): void { ); foreach ( $posts_to_demote as $post_id ) { - wp_update_post( array( 'ID' => $post_id, @@ -370,7 +367,7 @@ public function handle_downgrade( $membership_id ): void { * @param array $tabs Tabs of the media gallery upload modal. * @return array */ - public function limit_tabs( $tabs ) { + public function limit_tabs($tabs) { $post_count = wp_count_posts( 'attachment' ); diff --git a/inc/models/class-checkout-form.php b/inc/models/class-checkout-form.php index b0cf64bf3..53db72681 100644 --- a/inc/models/class-checkout-form.php +++ b/inc/models/class-checkout-form.php @@ -729,12 +729,12 @@ private function get_simple_template() { 'auto_generate_site_url' => true, ], [ - 'step' => 'checkout', - 'name' => __('Template Selection', 'ultimate-multisite'), - 'type' => 'template_selection', - 'id' => 'template_selection', - 'template_selection_type' => 'all', - 'template_selection_template' => 'clean', + 'step' => 'checkout', + 'name' => __('Template Selection', 'ultimate-multisite'), + 'type' => 'template_selection', + 'id' => 'template_selection', + 'template_selection_type' => 'all', + 'template_selection_template' => 'clean', 'hide_template_selection_when_pre_selected' => true, ], [ diff --git a/inc/site-exporter/class-export-download-handler.php b/inc/site-exporter/class-export-download-handler.php index ef604b404..98bdbbeec 100644 --- a/inc/site-exporter/class-export-download-handler.php +++ b/inc/site-exporter/class-export-download-handler.php @@ -107,10 +107,10 @@ public static function raw_download_url(string $filename): string { return add_query_arg( [ - 'page' => 'wu-site-export', - 'action' => 'download', - 'file' => rawurlencode($filename), - '_wpnonce' => wp_create_nonce(self::nonce_action($filename)), + 'page' => 'wu-site-export', + 'action' => 'download', + 'file' => rawurlencode($filename), + '_wpnonce' => wp_create_nonce(self::nonce_action($filename)), ], network_admin_url('sites.php') ); diff --git a/inc/site-exporter/database/class-import.php b/inc/site-exporter/database/class-import.php index 474063af1..5f7101f32 100644 --- a/inc/site-exporter/database/class-import.php +++ b/inc/site-exporter/database/class-import.php @@ -173,7 +173,7 @@ private function dropTables($site_id = false): void { // Get list of tables — use PDO::quote() to safely escape the LIKE pattern. $like_pattern = $this->db->quote($table . '%'); - $tables = $this->query('SHOW TABLES LIKE ' . $like_pattern); + $tables = $this->query('SHOW TABLES LIKE ' . $like_pattern); if ($tables !== null && $tables !== false) { // Loop through tables $results = $tables->fetchAll(PDO::FETCH_COLUMN); diff --git a/inc/ui/class-command-palette-manager.php b/inc/ui/class-command-palette-manager.php index a16581325..3cf534e50 100644 --- a/inc/ui/class-command-palette-manager.php +++ b/inc/ui/class-command-palette-manager.php @@ -138,8 +138,8 @@ public function enqueue_scripts(): void { // Core dependencies: wp-commands, wp-data, wp-element, wp-i18n, wp-api-fetch. // Progressive enhancement deps (JS feature-detects these at runtime): - // wp-primitives: SVG/Path for icons (no global wp.icons exists in any WP version). - // wp-compose: useDebounce for search debouncing. + // wp-primitives: SVG/Path for icons (no global wp.icons exists in any WP version). + // wp-compose: useDebounce for search debouncing. // Both are available since WP 6.1 and safe to list — WP resolves them // from its registered scripts. On pages where they aren't loaded, the JS // gracefully degrades (no icons, setTimeout fallback for debounce). diff --git a/inc/ui/class-site-actions-element.php b/inc/ui/class-site-actions-element.php index cb550d2c0..62d361f44 100644 --- a/inc/ui/class-site-actions-element.php +++ b/inc/ui/class-site-actions-element.php @@ -1397,7 +1397,7 @@ public function render_resubscribe_membership(): void { $customer = wu_get_current_customer(); - if ( ! is_super_admin() && ( ! $customer || $customer->get_id() !== $membership->get_customer_id())) { + if ( ! is_super_admin() && (! $customer || $customer->get_id() !== $membership->get_customer_id())) { $error = __('You are not allowed to do this.', 'ultimate-multisite'); } @@ -1488,7 +1488,7 @@ public function handle_resubscribe_membership(): void { $customer = wu_get_current_customer(); - if ( ! is_super_admin() && ( ! $customer || $customer->get_id() !== $membership->get_customer_id())) { + if ( ! is_super_admin() && (! $customer || $customer->get_id() !== $membership->get_customer_id())) { $error = new \WP_Error('error', __('You are not allowed to do this.', 'ultimate-multisite')); wp_send_json_error($error); @@ -1514,7 +1514,7 @@ public function handle_resubscribe_membership(): void { $checkout_url = add_query_arg( [ - 'products[]' => $plan->get_slug(), + 'products[]' => $plan->get_slug(), 'wu_resubscribe' => $membership->get_hash(), ], $checkout_url diff --git a/tests/Admin_Pages/Base_Admin_Page_Test.php b/tests/Admin_Pages/Base_Admin_Page_Test.php index d995b93be..3f09a2703 100644 --- a/tests/Admin_Pages/Base_Admin_Page_Test.php +++ b/tests/Admin_Pages/Base_Admin_Page_Test.php @@ -76,8 +76,8 @@ public function output(): void { */ class Concrete_Test_Admin_Page_With_Highlight extends Base_Admin_Page { - public $id = 'test-page-highlight'; - public $type = 'submenu'; + public $id = 'test-page-highlight'; + public $type = 'submenu'; protected $highlight_menu_slug = 'wp-ultimo'; protected $supported_panels = [ @@ -523,7 +523,7 @@ public function test_fix_subdomain_name_does_nothing_when_no_submenu_entry(): vo * @param Concrete_Test_Admin_Page $page The page instance. * @return string The classes string produced by the page's filter callback. */ - private function get_body_classes_from_page( $page ): string { + private function get_body_classes_from_page($page): string { global $wp_filter; // Record how many callbacks exist before we add ours. @@ -539,13 +539,13 @@ private function get_body_classes_from_page( $page ): string { // Find the newly added callback (the last one at priority 10). $our_callback = null; if (isset($wp_filter['admin_body_class']->callbacks[10])) { - $all = array_values($wp_filter['admin_body_class']->callbacks[10]); + $all = array_values($wp_filter['admin_body_class']->callbacks[10]); $our_callback = end($all); } remove_all_filters('admin_body_class'); - if ($our_callback === null || !isset($our_callback['function'])) { + if ($our_callback === null || ! isset($our_callback['function'])) { return ''; } diff --git a/tests/Admin_Pages/Checkout_Form_Edit_Admin_Page_Test.php b/tests/Admin_Pages/Checkout_Form_Edit_Admin_Page_Test.php index 38c0841a6..a3b315178 100644 --- a/tests/Admin_Pages/Checkout_Form_Edit_Admin_Page_Test.php +++ b/tests/Admin_Pages/Checkout_Form_Edit_Admin_Page_Test.php @@ -235,7 +235,7 @@ public function test_get_object_caches_result(): void { * action_links returns an empty array when the object does not exist (new form). */ public function test_action_links_returns_empty_when_object_not_saved(): void { - $new_form = new Checkout_Form(); + $new_form = new Checkout_Form(); $this->page->object = $new_form; $links = $this->page->action_links(); @@ -292,7 +292,10 @@ public function test_query_filter_preserves_existing_args(): void { $_REQUEST['id'] = $this->checkout_form->get_id(); $this->page->object = $this->checkout_form; - $args = ['per_page' => 20, 'orderby' => 'date']; + $args = [ + 'per_page' => 20, + 'orderby' => 'date', + ]; $result = $this->page->query_filter($args); $this->assertEquals(20, $result['per_page']); @@ -459,7 +462,10 @@ public function test_get_create_field_fields_submit_button_title_for_new_field() * get_create_field_fields submit button title is "Save Field" when attributes provided. */ public function test_get_create_field_fields_submit_button_title_for_existing_field(): void { - $fields = $this->page->get_create_field_fields(['type' => 'text', 'name' => 'My Field']); + $fields = $this->page->get_create_field_fields([ + 'type' => 'text', + 'name' => 'My Field', + ]); $this->assertEquals(__('Save Field', 'ultimate-multisite'), $fields['submit_button']['title']); } diff --git a/tests/Admin_Pages/Invoice_Template_Customize_Admin_Page_Test.php b/tests/Admin_Pages/Invoice_Template_Customize_Admin_Page_Test.php index 941d82e59..d1535d7ef 100644 --- a/tests/Admin_Pages/Invoice_Template_Customize_Admin_Page_Test.php +++ b/tests/Admin_Pages/Invoice_Template_Customize_Admin_Page_Test.php @@ -440,7 +440,7 @@ public function test_handle_save_falls_back_to_default_font_for_invalid_value(): * * @dataProvider valid_font_provider */ - public function test_handle_save_accepts_all_valid_fonts( string $font ): void { + public function test_handle_save_accepts_all_valid_fonts(string $font): void { $_POST['font'] = $font; ob_start(); diff --git a/tests/Admin_Pages/Wizard_Admin_Page_Test.php b/tests/Admin_Pages/Wizard_Admin_Page_Test.php index c25630d27..3fbf16450 100644 --- a/tests/Admin_Pages/Wizard_Admin_Page_Test.php +++ b/tests/Admin_Pages/Wizard_Admin_Page_Test.php @@ -81,7 +81,10 @@ public function get_menu_title(): string { public function get_sections(): array { return [ 'main' => ['title' => 'Main'], - 'extra' => ['title' => 'Extra', 'addon' => true], + 'extra' => [ + 'title' => 'Extra', + 'addon' => true, + ], ]; } } @@ -610,7 +613,10 @@ function ($location) use (&$redirect_url) { * register_widgets() returns early when current_section has a separator key. */ public function test_register_widgets_returns_early_for_separator_section(): void { - $this->page->current_section = ['separator' => true, 'title' => 'Sep']; + $this->page->current_section = [ + 'separator' => true, + 'title' => 'Sep', + ]; $GLOBALS['current_screen'] = \WP_Screen::get('dashboard-network'); diff --git a/tests/WP_Ultimo/Admin_Pages/Addons_Admin_Page_Test.php b/tests/WP_Ultimo/Admin_Pages/Addons_Admin_Page_Test.php index 793e761bb..5e79eee06 100644 --- a/tests/WP_Ultimo/Admin_Pages/Addons_Admin_Page_Test.php +++ b/tests/WP_Ultimo/Admin_Pages/Addons_Admin_Page_Test.php @@ -418,7 +418,7 @@ public function test_get_addons_list_returns_array_on_api_failure(): void { delete_site_transient('wu-addons-list-beta'); // Mock HTTP request to return WP_Error - add_filter('pre_http_request', function($preempt, $args, $url) { + add_filter('pre_http_request', function ($preempt, $args, $url) { return new \WP_Error('http_error', 'Connection failed'); }, 10, 3); @@ -440,9 +440,12 @@ public function test_get_addons_list_returns_empty_array_on_empty_api_response() delete_site_transient('wu-addons-list-beta'); // Mock HTTP request to return empty body - add_filter('pre_http_request', function($preempt, $args, $url) { + add_filter('pre_http_request', function ($preempt, $args, $url) { return array( - 'response' => array('code' => 200, 'message' => 'OK'), + 'response' => array( + 'code' => 200, + 'message' => 'OK', + ), 'body' => wp_json_encode(array()), 'headers' => array(), ); @@ -466,7 +469,12 @@ public function test_get_addons_list_uses_cached_property(): void { $reflection = new \ReflectionClass($this->page); $property = $reflection->getProperty('addons'); $property->setAccessible(true); - $property->setValue($this->page, array(array('slug' => 'test-addon', 'name' => 'Test Addon'))); + $property->setValue($this->page, array( + array( + 'slug' => 'test-addon', + 'name' => 'Test Addon', + ), + )); $method = new \ReflectionMethod($this->page, 'get_addons_list'); $method->setAccessible(true); @@ -483,7 +491,10 @@ public function test_get_addons_list_uses_cached_property(): void { */ public function test_get_addons_list_uses_transient_cache(): void { $cached_addons = array( - array('slug' => 'cached-addon', 'name' => 'Cached Addon'), + array( + 'slug' => 'cached-addon', + 'name' => 'Cached Addon', + ), ); set_site_transient('wu-addons-list', $cached_addons); @@ -507,7 +518,10 @@ public function test_get_addons_list_uses_transient_cache(): void { */ public function test_get_addons_list_uses_beta_transient_when_beta_enabled(): void { $beta_addons = array( - array('slug' => 'beta-addon', 'name' => 'Beta Addon'), + array( + 'slug' => 'beta-addon', + 'name' => 'Beta Addon', + ), ); set_site_transient('wu-addons-list-beta', $beta_addons); @@ -536,13 +550,20 @@ public function test_get_addons_list_fetches_and_caches(): void { delete_site_transient('wu-addons-list'); $api_addons = array( - array('slug' => 'api-addon', 'name' => 'API Addon', 'sku' => 'api-addon'), + array( + 'slug' => 'api-addon', + 'name' => 'API Addon', + 'sku' => 'api-addon', + ), ); // Mock HTTP request to return addon data - add_filter('pre_http_request', function($preempt, $args, $url) use ($api_addons) { + add_filter('pre_http_request', function ($preempt, $args, $url) use ($api_addons) { return array( - 'response' => array('code' => 200, 'message' => 'OK'), + 'response' => array( + 'code' => 200, + 'message' => 'OK', + ), 'body' => wp_json_encode($api_addons), 'headers' => array(), ); @@ -572,12 +593,19 @@ public function test_get_addons_list_marks_installed_plugins(): void { delete_site_transient('wu-addons-list'); $api_addons = array( - array('slug' => 'my-addon', 'name' => 'My Addon', 'sku' => 'my-addon'), + array( + 'slug' => 'my-addon', + 'name' => 'My Addon', + 'sku' => 'my-addon', + ), ); - add_filter('pre_http_request', function($preempt, $args, $url) use ($api_addons) { + add_filter('pre_http_request', function ($preempt, $args, $url) use ($api_addons) { return array( - 'response' => array('code' => 200, 'message' => 'OK'), + 'response' => array( + 'code' => 200, + 'message' => 'OK', + ), 'body' => wp_json_encode($api_addons), 'headers' => array(), ); @@ -614,7 +642,12 @@ public function test_serve_addons_list_is_callable(): void { * that the cached addons property is used when available. */ public function test_serve_addons_list_uses_cached_addons(): void { - $test_addons = array(array('slug' => 'cached-addon', 'name' => 'Cached Addon')); + $test_addons = array( + array( + 'slug' => 'cached-addon', + 'name' => 'Cached Addon', + ), + ); // Pre-populate addons cache $reflection = new \ReflectionClass($this->page); @@ -773,7 +806,7 @@ private function install_ajax_die_handler(): callable { add_filter('wp_doing_ajax', '__return_true'); $handler = function () { - return function ( $message ) { + return function ($message) { throw new \WPAjaxDieContinueException( (string) $message ); }; }; @@ -789,7 +822,7 @@ private function install_ajax_die_handler(): callable { * @param callable $handler The handler returned by install_ajax_die_handler(). * @return void */ - private function remove_ajax_die_handler( callable $handler ): void { + private function remove_ajax_die_handler(callable $handler): void { remove_filter('wp_doing_ajax', '__return_true'); remove_filter('wp_die_ajax_handler', $handler, 1); } @@ -874,7 +907,7 @@ public function test_default_handler_redirects(): void { $redirected = false; $exited = false; - add_filter('wp_redirect', function($location) use (&$redirected) { + add_filter('wp_redirect', function ($location) use (&$redirected) { $redirected = true; return $location; }); diff --git a/tests/WP_Ultimo/Admin_Pages/Broadcast_Edit_Admin_Page_Test.php b/tests/WP_Ultimo/Admin_Pages/Broadcast_Edit_Admin_Page_Test.php index 6867eb25c..aea050b3b 100644 --- a/tests/WP_Ultimo/Admin_Pages/Broadcast_Edit_Admin_Page_Test.php +++ b/tests/WP_Ultimo/Admin_Pages/Broadcast_Edit_Admin_Page_Test.php @@ -419,7 +419,10 @@ public function test_query_filter_merges_object_id(): void { * Test query_filter preserves existing args. */ public function test_query_filter_preserves_existing_args(): void { - $args = ['existing_key' => 'existing_value', 'number' => 10]; + $args = [ + 'existing_key' => 'existing_value', + 'number' => 10, + ]; $result = $this->page->query_filter($args); $this->assertEquals('existing_value', $result['existing_key']); @@ -496,7 +499,10 @@ public function test_events_query_filter_merges_object_id(): void { * Test events_query_filter preserves existing args. */ public function test_events_query_filter_preserves_existing_args(): void { - $args = ['existing_key' => 'existing_value', 'number' => 5]; + $args = [ + 'existing_key' => 'existing_value', + 'number' => 5, + ]; $result = $this->page->events_query_filter($args); $this->assertEquals('existing_value', $result['existing_key']); @@ -560,9 +566,9 @@ public function test_events_query_filter_matches_query_filter(): void { $this->page->object = $broadcast; - $args = ['number' => 10]; - $query_result = $this->page->query_filter($args); - $events_result = $this->page->events_query_filter($args); + $args = ['number' => 10]; + $query_result = $this->page->query_filter($args); + $events_result = $this->page->events_query_filter($args); $this->assertEquals($query_result['object_type'], $events_result['object_type']); $this->assertEquals($query_result['object_id'], $events_result['object_id']); @@ -833,7 +839,10 @@ public function test_output_default_widget_product_targets_no_targets(): void { $broadcast->set_type('broadcast_notice'); $broadcast->set_content('Content for no product targets test'); // Set empty targets so get_message_targets() returns an array, not false. - $broadcast->set_message_targets(['customers' => '', 'products' => '']); + $broadcast->set_message_targets([ + 'customers' => '', + 'products' => '', + ]); $saved = $broadcast->save(); if (is_wp_error($saved)) { diff --git a/tests/WP_Ultimo/Admin_Pages/Customer_Edit_Admin_Page_Test.php b/tests/WP_Ultimo/Admin_Pages/Customer_Edit_Admin_Page_Test.php index 7b849815a..e1e95b95e 100644 --- a/tests/WP_Ultimo/Admin_Pages/Customer_Edit_Admin_Page_Test.php +++ b/tests/WP_Ultimo/Admin_Pages/Customer_Edit_Admin_Page_Test.php @@ -797,7 +797,10 @@ public function test_customer_extra_form_attributes_preserves_existing_state(): $form_attributes = [ 'html_attr' => [ - 'data-state' => wp_json_encode(['confirmed' => true, 'other_key' => 'value']), + 'data-state' => wp_json_encode([ + 'confirmed' => true, + 'other_key' => 'value', + ]), ], ]; @@ -1151,12 +1154,12 @@ public function test_all_restricted_meta_keys_are_blocked(string $key): void { public function restricted_meta_keys_provider(): array { return [ - 'wu_verification_key' => ['wu_verification_key'], - 'wu_billing_address' => ['wu_billing_address'], - 'ip_state' => ['ip_state'], - 'ip_country' => ['ip_country'], - 'wu_has_trialed' => ['wu_has_trialed'], - 'wu_custom_meta_keys' => ['wu_custom_meta_keys'], + 'wu_verification_key' => ['wu_verification_key'], + 'wu_billing_address' => ['wu_billing_address'], + 'ip_state' => ['ip_state'], + 'ip_country' => ['ip_country'], + 'wu_has_trialed' => ['wu_has_trialed'], + 'wu_custom_meta_keys' => ['wu_custom_meta_keys'], ]; } diff --git a/tests/WP_Ultimo/Admin_Pages/Customizer_Admin_Page_Test.php b/tests/WP_Ultimo/Admin_Pages/Customizer_Admin_Page_Test.php index ac6d41fc0..f8e193d48 100644 --- a/tests/WP_Ultimo/Admin_Pages/Customizer_Admin_Page_Test.php +++ b/tests/WP_Ultimo/Admin_Pages/Customizer_Admin_Page_Test.php @@ -55,15 +55,15 @@ public function get_menu_title() { public function get_labels() { return [ - 'edit_label' => 'Edit Test', - 'add_new_label' => 'Add Test', - 'updated_message' => 'Test updated', - 'title_placeholder' => 'Enter title', - 'title_description' => 'Title desc', - 'save_button_label' => 'Save Test', - 'save_description' => 'Save desc', + 'edit_label' => 'Edit Test', + 'add_new_label' => 'Add Test', + 'updated_message' => 'Test updated', + 'title_placeholder' => 'Enter title', + 'title_description' => 'Title desc', + 'save_button_label' => 'Save Test', + 'save_description' => 'Save desc', 'delete_button_label' => 'Delete Test', - 'delete_description' => 'Delete desc', + 'delete_description' => 'Delete desc', ]; } diff --git a/tests/WP_Ultimo/Admin_Pages/Discount_Code_Edit_Admin_Page_Test.php b/tests/WP_Ultimo/Admin_Pages/Discount_Code_Edit_Admin_Page_Test.php index cd4d5877c..8d9509fa4 100644 --- a/tests/WP_Ultimo/Admin_Pages/Discount_Code_Edit_Admin_Page_Test.php +++ b/tests/WP_Ultimo/Admin_Pages/Discount_Code_Edit_Admin_Page_Test.php @@ -439,7 +439,10 @@ public function test_query_filter_merges_object_id(): void { * Test query_filter preserves existing args. */ public function test_query_filter_preserves_existing_args(): void { - $args = ['existing_key' => 'existing_value', 'number' => 10]; + $args = [ + 'existing_key' => 'existing_value', + 'number' => 10, + ]; $result = $this->page->query_filter($args); $this->assertEquals('existing_value', $result['existing_key']); diff --git a/tests/WP_Ultimo/Admin_Pages/Domain_Edit_Admin_Page_Test.php b/tests/WP_Ultimo/Admin_Pages/Domain_Edit_Admin_Page_Test.php index 47b8efbe0..320c19acc 100644 --- a/tests/WP_Ultimo/Admin_Pages/Domain_Edit_Admin_Page_Test.php +++ b/tests/WP_Ultimo/Admin_Pages/Domain_Edit_Admin_Page_Test.php @@ -55,7 +55,7 @@ protected function setUp(): void { parent::setUp(); - $this->page = new Testable_Domain_Edit_Admin_Page(); + $this->page = new Testable_Domain_Edit_Admin_Page(); // Use the main site blog ID (1) to avoid switch_to_blog() DB connection issues. $this->blog_id = 1; } @@ -156,7 +156,7 @@ private function capture_json_response(callable $callback): array { * @param array $overrides Optional attribute overrides. * @return Domain */ - private function create_domain( array $overrides = [] ): Domain { + private function create_domain(array $overrides = []): Domain { $domain = new Domain( array_merge( @@ -520,7 +520,7 @@ public function test_query_filter_merges_object_type(): void { */ public function test_query_filter_merges_object_id(): void { - $domain = $this->create_domain(); + $domain = $this->create_domain(); $this->page->object = $domain; $result = $this->page->query_filter([]); @@ -540,7 +540,10 @@ public function test_query_filter_preserves_existing_args(): void { $this->page->object = $domain; - $args = ['existing_key' => 'existing_value', 'number' => 10]; + $args = [ + 'existing_key' => 'existing_value', + 'number' => 10, + ]; $result = $this->page->query_filter($args); $this->assertEquals('existing_value', $result['existing_key']); @@ -595,7 +598,10 @@ public function test_sites_query_filter_preserves_existing_args(): void { $this->page->object = $domain; - $args = ['number' => 5, 'orderby' => 'title']; + $args = [ + 'number' => 5, + 'orderby' => 'title', + ]; $result = $this->page->sites_query_filter($args); $this->assertEquals(5, $result['number']); diff --git a/tests/WP_Ultimo/Admin_Pages/Edit_Admin_Page_Test.php b/tests/WP_Ultimo/Admin_Pages/Edit_Admin_Page_Test.php index defc3ed8c..14a89d343 100644 --- a/tests/WP_Ultimo/Admin_Pages/Edit_Admin_Page_Test.php +++ b/tests/WP_Ultimo/Admin_Pages/Edit_Admin_Page_Test.php @@ -923,7 +923,10 @@ public function test_add_info_widget_uses_date_registered_when_available(): void $this->page->object = $mock_object; - $this->page->public_add_info_widget('info', ['title' => 'Timestamps', 'position' => 'side-bottom']); + $this->page->public_add_info_widget('info', [ + 'title' => 'Timestamps', + 'position' => 'side-bottom', + ]); $this->assertTrue(true); } diff --git a/tests/WP_Ultimo/Admin_Pages/Email_Edit_Admin_Page_Test.php b/tests/WP_Ultimo/Admin_Pages/Email_Edit_Admin_Page_Test.php index 0b3fc00c4..367137ae6 100644 --- a/tests/WP_Ultimo/Admin_Pages/Email_Edit_Admin_Page_Test.php +++ b/tests/WP_Ultimo/Admin_Pages/Email_Edit_Admin_Page_Test.php @@ -491,7 +491,10 @@ public function test_query_filter_merges_object_id(): void { * Test query_filter preserves existing args. */ public function test_query_filter_preserves_existing_args(): void { - $args = ['existing_key' => 'existing_value', 'number' => 10]; + $args = [ + 'existing_key' => 'existing_value', + 'number' => 10, + ]; $result = $this->page->query_filter($args); $this->assertEquals('existing_value', $result['existing_key']); @@ -570,7 +573,10 @@ public function test_events_query_filter_merges_object_id(): void { * Test events_query_filter preserves existing args. */ public function test_events_query_filter_preserves_existing_args(): void { - $args = ['foo' => 'bar', 'limit' => 5]; + $args = [ + 'foo' => 'bar', + 'limit' => 5, + ]; $result = $this->page->events_query_filter($args); $this->assertEquals('bar', $result['foo']); diff --git a/tests/WP_Ultimo/Admin_Pages/Email_List_Admin_Page_Test.php b/tests/WP_Ultimo/Admin_Pages/Email_List_Admin_Page_Test.php index 0bf6fb567..35f1f3690 100644 --- a/tests/WP_Ultimo/Admin_Pages/Email_List_Admin_Page_Test.php +++ b/tests/WP_Ultimo/Admin_Pages/Email_List_Admin_Page_Test.php @@ -65,7 +65,7 @@ private function install_ajax_die_handler(): callable { add_filter('wp_doing_ajax', '__return_true'); $handler = function () { - return function ( $message ) { + return function ($message) { throw new \WPAjaxDieContinueException( (string) $message ); }; }; @@ -81,7 +81,7 @@ private function install_ajax_die_handler(): callable { * @param callable $handler The handler returned by install_ajax_die_handler(). * @return void */ - private function remove_ajax_die_handler( callable $handler ): void { + private function remove_ajax_die_handler(callable $handler): void { remove_filter('wp_doing_ajax', '__return_true'); remove_filter('wp_die_ajax_handler', $handler, 1); } @@ -92,7 +92,7 @@ private function remove_ajax_die_handler( callable $handler ): void { * @param callable $callable The callable to invoke. * @return array{output: string, exception: bool} */ - private function call_in_ajax_context( callable $callable ): array { + private function call_in_ajax_context(callable $callable): array { $handler = $this->install_ajax_die_handler(); $exception_caught = false; @@ -966,9 +966,9 @@ public function test_handle_reset_import_modal_reset_specific_email(): void { $original_id = $email->get_id(); - $_REQUEST['reset_emails'] = '1'; - $_REQUEST['import_emails'] = ''; - $_REQUEST['reset_' . $first_slug] = '1'; + $_REQUEST['reset_emails'] = '1'; + $_REQUEST['import_emails'] = ''; + $_REQUEST['reset_' . $first_slug] = '1'; $result = $this->call_in_ajax_context(function () { $this->page->handle_reset_import_modal(); @@ -1006,9 +1006,9 @@ public function test_handle_reset_import_modal_import_specific_email(): void { $this->markTestSkipped('All default emails already exist; cannot test import path.'); } - $_REQUEST['reset_emails'] = ''; - $_REQUEST['import_emails'] = '1'; - $_REQUEST['import_' . $import_slug] = '1'; + $_REQUEST['reset_emails'] = ''; + $_REQUEST['import_emails'] = '1'; + $_REQUEST['import_' . $import_slug] = '1'; $result = $this->call_in_ajax_context(function () { $this->page->handle_reset_import_modal(); diff --git a/tests/WP_Ultimo/Admin_Pages/External_Cron_Admin_Page_Test.php b/tests/WP_Ultimo/Admin_Pages/External_Cron_Admin_Page_Test.php index 657b0124e..df1f7526a 100644 --- a/tests/WP_Ultimo/Admin_Pages/External_Cron_Admin_Page_Test.php +++ b/tests/WP_Ultimo/Admin_Pages/External_Cron_Admin_Page_Test.php @@ -474,9 +474,18 @@ public function test_get_service_status_active_has_label(): void { public function test_get_service_status_always_has_required_keys(): void { $scenarios = array( - array('site_id' => '', 'enabled' => false), - array('site_id' => 'abc', 'enabled' => false), - array('site_id' => 'abc', 'enabled' => true), + array( + 'site_id' => '', + 'enabled' => false, + ), + array( + 'site_id' => 'abc', + 'enabled' => false, + ), + array( + 'site_id' => 'abc', + 'enabled' => true, + ), ); foreach ($scenarios as $scenario) { @@ -861,7 +870,10 @@ public function test_ajax_sync_updates_last_sync(): void { // Mock HTTP to avoid real API calls. add_filter('pre_http_request', function () { return array( - 'response' => array('code' => 200, 'message' => 'OK'), + 'response' => array( + 'code' => 200, + 'message' => 'OK', + ), 'body' => wp_json_encode(array()), 'headers' => array(), ); @@ -897,7 +909,10 @@ public function test_ajax_sync_returns_success(): void { // Mock HTTP to avoid real API calls. add_filter('pre_http_request', function () { return array( - 'response' => array('code' => 200, 'message' => 'OK'), + 'response' => array( + 'code' => 200, + 'message' => 'OK', + ), 'body' => wp_json_encode(array()), 'headers' => array(), ); @@ -1089,7 +1104,7 @@ private function install_ajax_die_handler(): callable { add_filter('wp_doing_ajax', '__return_true'); $handler = function () { - return function ( $message ) { + return function ($message) { throw new \WPAjaxDieContinueException( (string) $message ); }; }; @@ -1105,7 +1120,7 @@ private function install_ajax_die_handler(): callable { * @param callable $handler The handler returned by install_ajax_die_handler(). * @return void */ - private function remove_ajax_die_handler( callable $handler ): void { + private function remove_ajax_die_handler(callable $handler): void { remove_filter('wp_doing_ajax', '__return_true'); remove_filter('wp_die_ajax_handler', $handler, 1); diff --git a/tests/WP_Ultimo/Admin_Pages/Hosting_Integration_Wizard_Admin_Page_Test.php b/tests/WP_Ultimo/Admin_Pages/Hosting_Integration_Wizard_Admin_Page_Test.php index cbc222544..0c9018ff2 100644 --- a/tests/WP_Ultimo/Admin_Pages/Hosting_Integration_Wizard_Admin_Page_Test.php +++ b/tests/WP_Ultimo/Admin_Pages/Hosting_Integration_Wizard_Admin_Page_Test.php @@ -81,7 +81,7 @@ protected function tearDown(): void { */ public function test_page_id(): void { - $ref = new \ReflectionClass($this->page); + $ref = new \ReflectionClass($this->page); $prop = $ref->getProperty('id'); $prop->setAccessible(true); @@ -93,7 +93,7 @@ public function test_page_id(): void { */ public function test_page_type(): void { - $ref = new \ReflectionClass($this->page); + $ref = new \ReflectionClass($this->page); $prop = $ref->getProperty('type'); $prop->setAccessible(true); @@ -105,7 +105,7 @@ public function test_page_type(): void { */ public function test_page_parent(): void { - $ref = new \ReflectionClass($this->page); + $ref = new \ReflectionClass($this->page); $prop = $ref->getProperty('parent'); $prop->setAccessible(true); @@ -117,7 +117,7 @@ public function test_page_parent(): void { */ public function test_highlight_menu_slug(): void { - $ref = new \ReflectionClass($this->page); + $ref = new \ReflectionClass($this->page); $prop = $ref->getProperty('highlight_menu_slug'); $prop->setAccessible(true); @@ -129,7 +129,7 @@ public function test_highlight_menu_slug(): void { */ public function test_badge_count(): void { - $ref = new \ReflectionClass($this->page); + $ref = new \ReflectionClass($this->page); $prop = $ref->getProperty('badge_count'); $prop->setAccessible(true); @@ -141,7 +141,7 @@ public function test_badge_count(): void { */ public function test_supported_panels(): void { - $ref = new \ReflectionClass($this->page); + $ref = new \ReflectionClass($this->page); $prop = $ref->getProperty('supported_panels'); $prop->setAccessible(true); $panels = $prop->getValue($this->page); @@ -457,7 +457,11 @@ public function test_section_configuration_runs_without_error(): void { // Set a current section so get_current_section() doesn't fail. $ref = new \ReflectionProperty(\WP_Ultimo\Admin_Pages\Wizard_Admin_Page::class, 'current_section'); $ref->setAccessible(true); - $ref->setValue($this->page, ['title' => 'Config', 'view' => function () {}, 'handler' => function () {}]); + $ref->setValue($this->page, [ + 'title' => 'Config', + 'view' => function () {}, + 'handler' => function () {}, + ]); ob_start(); $this->page->section_configuration(); @@ -606,8 +610,8 @@ public function test_handle_configuration_is_callable(): void { */ public function test_handle_configuration_with_valid_nonce_saves_and_redirects(): void { - $nonce = wp_create_nonce('saving_config'); - $_POST['saving_config'] = $nonce; + $nonce = wp_create_nonce('saving_config'); + $_POST['saving_config'] = $nonce; $_REQUEST['saving_config'] = $nonce; // Intercept wp_safe_redirect() before it calls header() (which fails after output). @@ -671,7 +675,7 @@ function ($location) use (&$redirect_url) { */ public function test_page_loaded_redirects_when_integration_not_found(): void { - $page = new Hosting_Integration_Wizard_Admin_Page(); + $page = new Hosting_Integration_Wizard_Admin_Page(); $_GET['integration'] = 'nonexistent-integration-xyz'; // Intercept wp_safe_redirect() before it calls header() (which fails after output). diff --git a/tests/WP_Ultimo/Admin_Pages/Multisite_Setup_Admin_Page_Test.php b/tests/WP_Ultimo/Admin_Pages/Multisite_Setup_Admin_Page_Test.php index d43eaba23..3098a62b8 100644 --- a/tests/WP_Ultimo/Admin_Pages/Multisite_Setup_Admin_Page_Test.php +++ b/tests/WP_Ultimo/Admin_Pages/Multisite_Setup_Admin_Page_Test.php @@ -516,7 +516,7 @@ public function test_constructor_registers_ajax_setup_install(): void { */ public function test_register_scripts_does_not_enqueue_on_wrong_screen(): void { - $block_ui_enqueued = wp_script_is('wu-block-ui', 'enqueued'); + $block_ui_enqueued = wp_script_is('wu-block-ui', 'enqueued'); $wizard_extra_enqueued = wp_script_is('wu-setup-wizard-extra', 'enqueued'); $GLOBALS['current_screen'] = \WP_Screen::get('dashboard'); diff --git a/tests/WP_Ultimo/Admin_Pages/PayPal_Setup_Wizard_Admin_Page_Test.php b/tests/WP_Ultimo/Admin_Pages/PayPal_Setup_Wizard_Admin_Page_Test.php index 48f59b5be..d3dd27058 100644 --- a/tests/WP_Ultimo/Admin_Pages/PayPal_Setup_Wizard_Admin_Page_Test.php +++ b/tests/WP_Ultimo/Admin_Pages/PayPal_Setup_Wizard_Admin_Page_Test.php @@ -107,7 +107,7 @@ protected function tearDown(): void { */ public function test_page_id(): void { - $ref = new \ReflectionClass($this->page); + $ref = new \ReflectionClass($this->page); $prop = $ref->getProperty('id'); $prop->setAccessible(true); @@ -119,7 +119,7 @@ public function test_page_id(): void { */ public function test_page_type(): void { - $ref = new \ReflectionClass($this->page); + $ref = new \ReflectionClass($this->page); $prop = $ref->getProperty('type'); $prop->setAccessible(true); @@ -131,7 +131,7 @@ public function test_page_type(): void { */ public function test_page_parent(): void { - $ref = new \ReflectionClass($this->page); + $ref = new \ReflectionClass($this->page); $prop = $ref->getProperty('parent'); $prop->setAccessible(true); @@ -143,7 +143,7 @@ public function test_page_parent(): void { */ public function test_highlight_menu_slug(): void { - $ref = new \ReflectionClass($this->page); + $ref = new \ReflectionClass($this->page); $prop = $ref->getProperty('highlight_menu_slug'); $prop->setAccessible(true); @@ -155,7 +155,7 @@ public function test_highlight_menu_slug(): void { */ public function test_supported_panels(): void { - $ref = new \ReflectionClass($this->page); + $ref = new \ReflectionClass($this->page); $prop = $ref->getProperty('supported_panels'); $prop->setAccessible(true); $panels = $prop->getValue($this->page); @@ -359,9 +359,9 @@ public function test_handle_configure_persists_sandbox_credentials(): void { grant_super_admin($user_id); wp_set_current_user($user_id); - $nonce = wp_create_nonce('saving_configure'); - $_POST['_wpultimo_nonce'] = $nonce; - $_REQUEST['_wpultimo_nonce'] = $nonce; + $nonce = wp_create_nonce('saving_configure'); + $_POST['_wpultimo_nonce'] = $nonce; + $_REQUEST['_wpultimo_nonce'] = $nonce; $_POST['paypal_client_id'] = 'AX_test_sandbox_client_id_12345'; $_POST['paypal_client_secret'] = 'EK_test_sandbox_client_secret_67890'; @@ -399,9 +399,9 @@ public function test_handle_configure_persists_live_credentials_when_live_mode() grant_super_admin($user_id); wp_set_current_user($user_id); - $nonce = wp_create_nonce('saving_configure'); - $_POST['_wpultimo_nonce'] = $nonce; - $_REQUEST['_wpultimo_nonce'] = $nonce; + $nonce = wp_create_nonce('saving_configure'); + $_POST['_wpultimo_nonce'] = $nonce; + $_REQUEST['_wpultimo_nonce'] = $nonce; $_POST['paypal_client_id'] = 'AX_test_live_id'; $_POST['paypal_client_secret'] = 'EK_test_live_secret'; @@ -431,9 +431,9 @@ public function test_handle_configure_rejects_empty_credentials_with_notice(): v grant_super_admin($user_id); wp_set_current_user($user_id); - $nonce = wp_create_nonce('saving_configure'); - $_POST['_wpultimo_nonce'] = $nonce; - $_REQUEST['_wpultimo_nonce'] = $nonce; + $nonce = wp_create_nonce('saving_configure'); + $_POST['_wpultimo_nonce'] = $nonce; + $_REQUEST['_wpultimo_nonce'] = $nonce; $_POST['paypal_client_id'] = ''; $_POST['paypal_client_secret'] = ''; @@ -535,7 +535,10 @@ public function test_ajax_test_credentials_handles_paypal_rejection(): void { function ($preempt, $args, $url) { if (false !== strpos($url, '/v1/oauth2/token')) { return [ - 'response' => ['code' => 401, 'message' => 'Unauthorized'], + 'response' => [ + 'code' => 401, + 'message' => 'Unauthorized', + ], 'body' => wp_json_encode( [ 'error' => 'invalid_client', @@ -629,7 +632,10 @@ public function test_ajax_test_credentials_succeeds_with_valid_token(): void { function ($preempt, $args, $url) { if (false !== strpos($url, '/v1/oauth2/token')) { return [ - 'response' => ['code' => 200, 'message' => 'OK'], + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], 'body' => wp_json_encode( [ 'access_token' => 'A21AAtest_access_token', @@ -645,7 +651,10 @@ function ($preempt, $args, $url) { if (false !== strpos($url, '/v1/notifications/webhooks')) { // Pretend webhook installed cleanly. return [ - 'response' => ['code' => 201, 'message' => 'Created'], + 'response' => [ + 'code' => 201, + 'message' => 'Created', + ], 'body' => wp_json_encode( [ 'id' => 'WH-test-id', diff --git a/tests/WP_Ultimo/Admin_Pages/Payment_Edit_Admin_Page_Test.php b/tests/WP_Ultimo/Admin_Pages/Payment_Edit_Admin_Page_Test.php index 301ff2e1a..9ee7cf92d 100644 --- a/tests/WP_Ultimo/Admin_Pages/Payment_Edit_Admin_Page_Test.php +++ b/tests/WP_Ultimo/Admin_Pages/Payment_Edit_Admin_Page_Test.php @@ -468,7 +468,10 @@ public function test_events_query_filter_merges_object_id(): void { * Test events_query_filter preserves existing args. */ public function test_events_query_filter_preserves_existing_args(): void { - $args = ['existing_key' => 'existing_value', 'number' => 10]; + $args = [ + 'existing_key' => 'existing_value', + 'number' => 10, + ]; $result = $this->page->events_query_filter($args); $this->assertEquals('existing_value', $result['existing_key']); @@ -536,7 +539,10 @@ public function test_payments_query_filter_sets_parent_in_false(): void { * Test payments_query_filter preserves existing args. */ public function test_payments_query_filter_preserves_existing_args(): void { - $args = ['number' => 20, 'status' => 'completed']; + $args = [ + 'number' => 20, + 'status' => 'completed', + ]; $result = $this->page->payments_query_filter($args); $this->assertEquals(20, $result['number']); diff --git a/tests/WP_Ultimo/Admin_Pages/Product_Edit_Admin_Page_Test.php b/tests/WP_Ultimo/Admin_Pages/Product_Edit_Admin_Page_Test.php index a6566b94c..171577eb0 100644 --- a/tests/WP_Ultimo/Admin_Pages/Product_Edit_Admin_Page_Test.php +++ b/tests/WP_Ultimo/Admin_Pages/Product_Edit_Admin_Page_Test.php @@ -415,7 +415,10 @@ public function test_query_filter_merges_object_id(): void { * Test query_filter preserves existing args. */ public function test_query_filter_preserves_existing_args(): void { - $args = ['existing_key' => 'existing_value', 'number' => 10]; + $args = [ + 'existing_key' => 'existing_value', + 'number' => 10, + ]; $result = $this->page->query_filter($args); $this->assertEquals('existing_value', $result['existing_key']); @@ -545,7 +548,7 @@ public function test_register_forms_adds_delete_product_filter(): void { remove_all_filters('wu_form_fields_delete_product_modal'); remove_all_actions('wu_after_delete_product_modal'); - remove_all_actions("wu_page_wp-ultimo-edit-product_load"); + remove_all_actions('wu_page_wp-ultimo-edit-product_load'); } /** @@ -561,7 +564,7 @@ public function test_register_forms_adds_after_delete_action(): void { remove_all_filters('wu_form_fields_delete_product_modal'); remove_all_actions('wu_after_delete_product_modal'); - remove_all_actions("wu_page_wp-ultimo-edit-product_load"); + remove_all_actions('wu_page_wp-ultimo-edit-product_load'); } /** @@ -577,7 +580,7 @@ public function test_register_forms_adds_page_load_action(): void { remove_all_filters('wu_form_fields_delete_product_modal'); remove_all_actions('wu_after_delete_product_modal'); - remove_all_actions("wu_page_wp-ultimo-edit-product_load"); + remove_all_actions('wu_page_wp-ultimo-edit-product_load'); } // ------------------------------------------------------------------------- diff --git a/tests/WP_Ultimo/Admin_Pages/System_Info_Admin_Page_Test.php b/tests/WP_Ultimo/Admin_Pages/System_Info_Admin_Page_Test.php index 86191854e..b5b0eb35b 100644 --- a/tests/WP_Ultimo/Admin_Pages/System_Info_Admin_Page_Test.php +++ b/tests/WP_Ultimo/Admin_Pages/System_Info_Admin_Page_Test.php @@ -355,7 +355,7 @@ public function test_get_browser_returns_unknown_name_when_no_match(): void { */ public function test_get_browser_user_agent_matches_server(): void { - $ua = 'Mozilla/5.0 (X11; Linux x86_64; rv:89.0) Gecko/20100101 Firefox/89.0'; + $ua = 'Mozilla/5.0 (X11; Linux x86_64; rv:89.0) Gecko/20100101 Firefox/89.0'; $_SERVER['HTTP_USER_AGENT'] = $ua; $browser = $this->page->get_browser(); @@ -545,7 +545,10 @@ public function test_get_all_options_is_non_empty(): void { */ public function test_get_transients_in_options_returns_empty_when_none(): void { - $options = ['siteurl' => 'http://example.com', 'blogname' => 'Test']; + $options = [ + 'siteurl' => 'http://example.com', + 'blogname' => 'Test', + ]; $transients = $this->page->get_transients_in_options($options); $this->assertIsArray($transients); @@ -558,10 +561,10 @@ public function test_get_transients_in_options_returns_empty_when_none(): void { public function test_get_transients_in_options_returns_transients(): void { $options = [ - 'siteurl' => 'http://example.com', - '_transient_my_cache' => 'cached_value', + 'siteurl' => 'http://example.com', + '_transient_my_cache' => 'cached_value', '_transient_timeout_my_cache' => '9999999999', - 'blogname' => 'Test', + 'blogname' => 'Test', ]; $transients = $this->page->get_transients_in_options($options); @@ -977,7 +980,13 @@ public function test_get_data_applies_filter(): void { public function test_get_data_filter_can_modify_data(): void { $callback = function ($data) { - $data['Custom Section'] = ['custom-key' => ['tooltip' => '', 'title' => 'Custom', 'value' => 'test']]; + $data['Custom Section'] = [ + 'custom-key' => [ + 'tooltip' => '', + 'title' => 'Custom', + 'value' => 'test', + ], + ]; return $data; }; diff --git a/tests/WP_Ultimo/Admin_Pages/Template_Previewer_Customize_Admin_Page_Test.php b/tests/WP_Ultimo/Admin_Pages/Template_Previewer_Customize_Admin_Page_Test.php index 6986a5686..c93868ffe 100644 --- a/tests/WP_Ultimo/Admin_Pages/Template_Previewer_Customize_Admin_Page_Test.php +++ b/tests/WP_Ultimo/Admin_Pages/Template_Previewer_Customize_Admin_Page_Test.php @@ -294,8 +294,8 @@ public function test_get_preview_url_contains_customizer_param(): void { */ public function test_get_preview_url_contains_preview_parameter(): void { - $url = $this->page->get_preview_url(); - $preview_param = Template_Previewer::get_instance()->get_preview_parameter(); + $url = $this->page->get_preview_url(); + $preview_param = Template_Previewer::get_instance()->get_preview_parameter(); $this->assertStringContainsString($preview_param . '=1', $url); } diff --git a/tests/WP_Ultimo/Admin_Themes_Compatibility_Test.php b/tests/WP_Ultimo/Admin_Themes_Compatibility_Test.php index b960b4ce8..c7d49f082 100644 --- a/tests/WP_Ultimo/Admin_Themes_Compatibility_Test.php +++ b/tests/WP_Ultimo/Admin_Themes_Compatibility_Test.php @@ -121,7 +121,7 @@ public function test_add_body_classes_adds_prefix_for_activated_themes() { }); $instance = Admin_Themes_Compatibility::get_instance(); - $result = $instance->add_body_classes(''); + $result = $instance->add_body_classes(''); $this->assertStringContainsString('wu-compat-admin-theme-test-theme', $result); } diff --git a/tests/WP_Ultimo/Ajax_Test.php b/tests/WP_Ultimo/Ajax_Test.php index e579de272..50c11b774 100644 --- a/tests/WP_Ultimo/Ajax_Test.php +++ b/tests/WP_Ultimo/Ajax_Test.php @@ -48,7 +48,7 @@ public function set_up(): void { */ public function tear_down(): void { - foreach ( [ 'model', 'query', 'number', 'exclude', 'include', 'table_id' ] as $key ) { + foreach ( ['model', 'query', 'number', 'exclude', 'include', 'table_id'] as $key ) { unset( $_REQUEST[ $key ], $_GET[ $key ], $_POST[ $key ] ); } @@ -93,7 +93,7 @@ private function reset_settings_with_empty_sections(): void { * * @param array $sections The sections to set. */ - private function set_settings_sections( array $sections ): void { + private function set_settings_sections(array $sections): void { $this->settings_sections_ref->setValue( Settings::get_instance(), $sections ); } @@ -112,7 +112,7 @@ private function install_ajax_die_handler(): callable { add_filter( 'wp_doing_ajax', '__return_true' ); $handler = function () { - return function ( $message ) { + return function ($message) { throw new \WPAjaxDieContinueException( (string) $message ); }; }; @@ -127,7 +127,7 @@ private function install_ajax_die_handler(): callable { * * @param callable $handler The handler returned by install_ajax_die_handler(). */ - private function remove_ajax_die_handler( callable $handler ): void { + private function remove_ajax_die_handler(callable $handler): void { remove_filter( 'wp_doing_ajax', '__return_true' ); remove_filter( 'wp_die_ajax_handler', $handler, 1 ); @@ -139,7 +139,7 @@ private function remove_ajax_die_handler( callable $handler ): void { * @param callable $callable The callable to invoke. * @return array{output: string, exception: bool} */ - private function call_in_ajax_context( callable $callable ): array { + private function call_in_ajax_context(callable $callable): array { $handler = $this->install_ajax_die_handler(); $exception_caught = false; @@ -168,7 +168,7 @@ private function call_in_ajax_context( callable $callable ): array { * @param string $table_id The table ID to convert. * @return string */ - private function invoke_get_table_class_name( string $table_id ): string { + private function invoke_get_table_class_name(string $table_id): string { $reflection = new \ReflectionClass( $this->ajax ); $method = $reflection->getMethod( 'get_table_class_name' ); @@ -211,9 +211,9 @@ public function test_init_registers_hooks(): void { $this->ajax->init(); - $this->assertGreaterThan( 0, has_action( 'wu_ajax_wu_search', [ $this->ajax, 'search_models' ] ) ); - $this->assertGreaterThan( 0, has_action( 'in_admin_footer', [ $this->ajax, 'render_selectize_templates' ] ) ); - $this->assertGreaterThan( 0, has_action( 'wp_ajax_wu_list_table_fetch_ajax_results', [ $this->ajax, 'refresh_list_table' ] ) ); + $this->assertGreaterThan( 0, has_action( 'wu_ajax_wu_search', [$this->ajax, 'search_models'] ) ); + $this->assertGreaterThan( 0, has_action( 'in_admin_footer', [$this->ajax, 'render_selectize_templates'] ) ); + $this->assertGreaterThan( 0, has_action( 'wp_ajax_wu_list_table_fetch_ajax_results', [$this->ajax, 'refresh_list_table'] ) ); } // ========================================================================= @@ -274,7 +274,7 @@ public function test_refresh_list_table_unknown_class_fires_action(): void { $action_fired = false; add_action( 'wu_list_table_fetch_ajax_results', - function ( $table_id ) use ( &$action_fired ) { + function ($table_id) use (&$action_fired) { $action_fired = $table_id; } ); @@ -296,7 +296,7 @@ public function test_refresh_list_table_always_fires_action(): void { $fired_with = null; add_action( 'wu_list_table_fetch_ajax_results', - function ( $table_id ) use ( &$fired_with ) { + function ($table_id) use (&$fired_with) { $fired_with = $table_id; } ); @@ -318,7 +318,7 @@ public function test_refresh_list_table_empty_table_id(): void { $fired = false; add_action( 'wu_list_table_fetch_ajax_results', - function () use ( &$fired ) { + function () use (&$fired) { $fired = true; } ); @@ -341,7 +341,7 @@ public function test_refresh_list_table_with_existing_class(): void { $action_fired = false; add_action( 'wu_list_table_fetch_ajax_results', - function () use ( &$action_fired ) { + function () use (&$action_fired) { $action_fired = true; } ); @@ -366,7 +366,7 @@ public function test_search_models_all_returns_json(): void { $this->reset_settings_with_empty_sections(); $_REQUEST['model'] = 'all'; - $_REQUEST['query'] = [ 'search' => 'zzz_no_match_xyz' ]; + $_REQUEST['query'] = ['search' => 'zzz_no_match_xyz']; // Suppress all data-source functions to return empty arrays. add_filter( @@ -396,7 +396,7 @@ public function test_search_models_fires_before_action(): void { $this->reset_settings_with_empty_sections(); - $grant_manage_network = static function ( array $allcaps ): array { + $grant_manage_network = static function (array $allcaps): array { $allcaps['manage_network'] = true; return $allcaps; @@ -404,7 +404,7 @@ public function test_search_models_fires_before_action(): void { add_filter( 'user_has_cap', $grant_manage_network ); $_REQUEST['model'] = 'all'; - $_REQUEST['query'] = [ 'search' => 'zzz_no_match_xyz' ]; + $_REQUEST['query'] = ['search' => 'zzz_no_match_xyz']; add_filter( 'wu_search_models_functions', @@ -416,7 +416,7 @@ function () { $fired = false; add_action( 'wu_before_search_models', - function () use ( &$fired ) { + function () use (&$fired) { $fired = true; } ); @@ -441,7 +441,7 @@ function () { public function test_search_models_user_model(): void { $_REQUEST['model'] = 'user'; - $_REQUEST['query'] = [ 'search' => 'admin' ]; + $_REQUEST['query'] = ['search' => 'admin']; $_REQUEST['number'] = 10; $_REQUEST['exclude'] = []; @@ -467,7 +467,7 @@ public function test_search_models_setting_model(): void { $this->reset_settings_with_empty_sections(); $_REQUEST['model'] = 'setting'; - $_REQUEST['query'] = [ 'search' => 'zzz_no_match_xyz' ]; + $_REQUEST['query'] = ['search' => 'zzz_no_match_xyz']; $_REQUEST['number'] = 10; $_REQUEST['exclude'] = []; @@ -490,7 +490,7 @@ function () { public function test_search_models_page_model(): void { $_REQUEST['model'] = 'page'; - $_REQUEST['query'] = [ 'search' => '' ]; + $_REQUEST['query'] = ['search' => '']; $_REQUEST['number'] = 10; $_REQUEST['exclude'] = []; @@ -513,7 +513,7 @@ function () { public function test_search_models_unknown_model_returns_empty_array(): void { $_REQUEST['model'] = 'nonexistent_model_xyz'; - $_REQUEST['query'] = [ 'search' => 'test' ]; + $_REQUEST['query'] = ['search' => 'test']; $_REQUEST['number'] = 10; $_REQUEST['exclude'] = []; @@ -537,7 +537,7 @@ function () { public function test_search_models_exclude_as_string(): void { $_REQUEST['model'] = 'user'; - $_REQUEST['query'] = [ 'search' => '' ]; + $_REQUEST['query'] = ['search' => '']; $_REQUEST['number'] = 10; $_REQUEST['exclude'] = '1,2,3'; @@ -559,9 +559,9 @@ function () { public function test_search_models_exclude_as_array(): void { $_REQUEST['model'] = 'user'; - $_REQUEST['query'] = [ 'search' => '' ]; + $_REQUEST['query'] = ['search' => '']; $_REQUEST['number'] = 10; - $_REQUEST['exclude'] = [ '1', '2' ]; + $_REQUEST['exclude'] = ['1', '2']; $result = $this->call_in_ajax_context( function () { @@ -581,7 +581,7 @@ function () { public function test_search_models_include_as_string(): void { $_REQUEST['model'] = 'user'; - $_REQUEST['query'] = [ 'search' => '' ]; + $_REQUEST['query'] = ['search' => '']; $_REQUEST['number'] = 10; $_REQUEST['exclude'] = []; $_REQUEST['include'] = '1,2,3'; @@ -604,10 +604,10 @@ function () { public function test_search_models_include_as_array(): void { $_REQUEST['model'] = 'user'; - $_REQUEST['query'] = [ 'search' => '' ]; + $_REQUEST['query'] = ['search' => '']; $_REQUEST['number'] = 10; $_REQUEST['exclude'] = []; - $_REQUEST['include'] = [ '1', '2' ]; + $_REQUEST['include'] = ['1', '2']; $result = $this->call_in_ajax_context( function () { @@ -627,7 +627,7 @@ function () { public function test_search_models_site_model_remaps_id_in(): void { $_REQUEST['model'] = 'site'; - $_REQUEST['query'] = [ 'search' => '' ]; + $_REQUEST['query'] = ['search' => '']; $_REQUEST['number'] = 10; $_REQUEST['exclude'] = []; $_REQUEST['include'] = '1'; @@ -650,7 +650,7 @@ function () { public function test_search_models_site_model_remaps_id_not_in(): void { $_REQUEST['model'] = 'site'; - $_REQUEST['query'] = [ 'search' => '' ]; + $_REQUEST['query'] = ['search' => '']; $_REQUEST['number'] = 10; $_REQUEST['exclude'] = '1,2'; @@ -672,7 +672,7 @@ function () { public function test_search_models_number_defaults_to_100(): void { $_REQUEST['model'] = 'user'; - $_REQUEST['query'] = [ 'search' => '' ]; + $_REQUEST['query'] = ['search' => '']; $_REQUEST['exclude'] = []; // No 'number' key set. @@ -694,7 +694,10 @@ function () { public function test_search_models_number_in_query_preserved(): void { $_REQUEST['model'] = 'user'; - $_REQUEST['query'] = [ 'number' => 5, 'search' => '' ]; + $_REQUEST['query'] = [ + 'number' => 5, + 'search' => '', + ]; $_REQUEST['number'] = 100; $_REQUEST['exclude'] = []; @@ -722,7 +725,7 @@ public function test_search_all_models_returns_json_array(): void { $this->reset_settings_with_empty_sections(); - $_REQUEST['query'] = [ 'search' => 'zzz_no_match_xyz' ]; + $_REQUEST['query'] = ['search' => 'zzz_no_match_xyz']; add_filter( 'wu_search_models_functions', @@ -759,7 +762,7 @@ public function test_search_all_models_user_results_have_model_property(): void ] ); - $_REQUEST['query'] = [ 'search' => 'testajaxuser' ]; + $_REQUEST['query'] = ['search' => 'testajaxuser']; add_filter( 'wu_search_models_functions', @@ -780,7 +783,7 @@ function () { // Find the user entry. $user_entries = array_filter( $decoded, - function ( $item ) { + function ($item) { return isset( $item['model'] ) && $item['model'] === 'user'; } ); @@ -798,12 +801,12 @@ public function test_search_all_models_applies_data_sources_filter(): void { $this->reset_settings_with_empty_sections(); - $_REQUEST['query'] = [ 'search' => 'zzz_no_match_xyz' ]; + $_REQUEST['query'] = ['search' => 'zzz_no_match_xyz']; $filter_applied = false; add_filter( 'wu_search_models_functions', - function ( $functions ) use ( &$filter_applied ) { + function ($functions) use (&$filter_applied) { $filter_applied = true; return []; } @@ -830,7 +833,7 @@ public function test_search_all_models_with_empty_query(): void { $this->reset_settings_with_empty_sections(); // Must include 'search' key to avoid undefined array key in search_wp_ultimo_setting. - $_REQUEST['query'] = [ 'search' => 'zzz_no_match_xyz' ]; + $_REQUEST['query'] = ['search' => 'zzz_no_match_xyz']; add_filter( 'wu_search_models_functions', @@ -863,7 +866,7 @@ public function test_search_wp_ultimo_setting_returns_array(): void { $this->reset_settings_with_empty_sections(); - $result = $this->ajax->search_wp_ultimo_setting( [ 'search' => 'zzz_no_match_xyz_abc_123' ] ); + $result = $this->ajax->search_wp_ultimo_setting( ['search' => 'zzz_no_match_xyz_abc_123'] ); $this->assertIsArray( $result ); } @@ -890,13 +893,13 @@ public function test_search_wp_ultimo_setting_filters_by_setting_id(): void { ] ); - $result = $this->ajax->search_wp_ultimo_setting( [ 'search' => 'my_unique_setting_xyz' ] ); + $result = $this->ajax->search_wp_ultimo_setting( ['search' => 'my_unique_setting_xyz'] ); $this->assertIsArray( $result ); $found = array_filter( $result, - function ( $item ) { + function ($item) { return isset( $item['setting_id'] ) && $item['setting_id'] === 'my_unique_setting_xyz'; } ); @@ -926,13 +929,13 @@ public function test_search_wp_ultimo_setting_filters_by_title(): void { ] ); - $result = $this->ajax->search_wp_ultimo_setting( [ 'search' => 'unique title xyz' ] ); + $result = $this->ajax->search_wp_ultimo_setting( ['search' => 'unique title xyz'] ); $this->assertIsArray( $result ); $found = array_filter( $result, - function ( $item ) { + function ($item) { return isset( $item['title'] ) && $item['title'] === 'Unique Title XYZ'; } ); @@ -962,13 +965,13 @@ public function test_search_wp_ultimo_setting_filters_by_desc(): void { ] ); - $result = $this->ajax->search_wp_ultimo_setting( [ 'search' => 'unique description abcdef' ] ); + $result = $this->ajax->search_wp_ultimo_setting( ['search' => 'unique description abcdef'] ); $this->assertIsArray( $result ); $found = array_filter( $result, - function ( $item ) { + function ($item) { return isset( $item['setting_id'] ) && $item['setting_id'] === 'desc_setting'; } ); @@ -998,13 +1001,13 @@ public function test_search_wp_ultimo_setting_excludes_header_fields(): void { ] ); - $result = $this->ajax->search_wp_ultimo_setting( [ 'search' => 'header_field_xyz' ] ); + $result = $this->ajax->search_wp_ultimo_setting( ['search' => 'header_field_xyz'] ); $this->assertIsArray( $result ); $found = array_filter( $result, - function ( $item ) { + function ($item) { return isset( $item['setting_id'] ) && $item['setting_id'] === 'header_field_xyz'; } ); @@ -1040,7 +1043,7 @@ public function test_search_wp_ultimo_setting_returns_sorted_by_title(): void { ] ); - $result = $this->ajax->search_wp_ultimo_setting( [ 'search' => 'sort test' ] ); + $result = $this->ajax->search_wp_ultimo_setting( ['search' => 'sort test'] ); $this->assertIsArray( $result ); @@ -1048,7 +1051,7 @@ public function test_search_wp_ultimo_setting_returns_sorted_by_title(): void { $test_entries = array_values( array_filter( $result, - function ( $item ) { + function ($item) { return isset( $item['desc'] ) && $item['desc'] === 'sort test'; } ) @@ -1057,7 +1060,7 @@ function ( $item ) { $this->assertCount( 2, $test_entries ); $this->assertLessThanOrEqual( 0, - strcmp( (string) ( $test_entries[0]['title'] ?? '' ), (string) ( $test_entries[1]['title'] ?? '' ) ), + strcmp( (string) ($test_entries[0]['title'] ?? ''), (string) ($test_entries[1]['title'] ?? '') ), 'Results should be sorted alphabetically by title' ); } @@ -1084,14 +1087,14 @@ public function test_search_wp_ultimo_setting_adds_section_and_url(): void { ] ); - $result = $this->ajax->search_wp_ultimo_setting( [ 'search' => 'url_test_setting' ] ); + $result = $this->ajax->search_wp_ultimo_setting( ['search' => 'url_test_setting'] ); $this->assertIsArray( $result ); $found = array_values( array_filter( $result, - function ( $item ) { + function ($item) { return isset( $item['setting_id'] ) && $item['setting_id'] === 'url_test_setting'; } ) @@ -1117,7 +1120,7 @@ public function test_search_wp_ultimo_setting_no_match_returns_empty(): void { $this->reset_settings_with_empty_sections(); - $result = $this->ajax->search_wp_ultimo_setting( [ 'search' => 'zzz_no_match_xyz_abc_123' ] ); + $result = $this->ajax->search_wp_ultimo_setting( ['search' => 'zzz_no_match_xyz_abc_123'] ); $this->assertIsArray( $result ); $this->assertEmpty( $result ); @@ -1146,13 +1149,13 @@ public function test_search_wp_ultimo_setting_strips_wildcards(): void { ); // Pass search with leading/trailing asterisks — should be stripped. - $result = $this->ajax->search_wp_ultimo_setting( [ 'search' => '*wildcard_setting*' ] ); + $result = $this->ajax->search_wp_ultimo_setting( ['search' => '*wildcard_setting*'] ); $this->assertIsArray( $result ); $found = array_filter( $result, - function ( $item ) { + function ($item) { return isset( $item['setting_id'] ) && $item['setting_id'] === 'wildcard_setting'; } ); @@ -1169,7 +1172,7 @@ function ( $item ) { */ public function test_search_wordpress_users_returns_array(): void { - $result = $this->ajax->search_wordpress_users( [ 'search' => '' ] ); + $result = $this->ajax->search_wordpress_users( ['search' => ''] ); $this->assertIsArray( $result ); } @@ -1186,7 +1189,7 @@ public function test_search_wordpress_users_returns_user_data(): void { ] ); - $result = $this->ajax->search_wordpress_users( [ 'search' => 'searchable_user_abc' ] ); + $result = $this->ajax->search_wordpress_users( ['search' => 'searchable_user_abc'] ); $this->assertIsArray( $result ); $this->assertNotEmpty( $result ); @@ -1210,7 +1213,7 @@ public function test_search_wordpress_users_clears_user_pass(): void { ] ); - $result = $this->ajax->search_wordpress_users( [ 'search' => 'passtest_user_xyz' ] ); + $result = $this->ajax->search_wordpress_users( ['search' => 'passtest_user_xyz'] ); $this->assertIsArray( $result ); $this->assertNotEmpty( $result ); @@ -1232,7 +1235,7 @@ public function test_search_wordpress_users_adds_avatar(): void { ] ); - $result = $this->ajax->search_wordpress_users( [ 'search' => 'avatar_test_user_xyz' ] ); + $result = $this->ajax->search_wordpress_users( ['search' => 'avatar_test_user_xyz'] ); $this->assertIsArray( $result ); $this->assertNotEmpty( $result ); @@ -1247,7 +1250,7 @@ public function test_search_wordpress_users_adds_avatar(): void { */ public function test_search_wordpress_users_no_match_returns_empty(): void { - $result = $this->ajax->search_wordpress_users( [ 'search' => 'zzz_no_such_user_xyz_abc_999' ] ); + $result = $this->ajax->search_wordpress_users( ['search' => 'zzz_no_such_user_xyz_abc_999'] ); $this->assertIsArray( $result ); $this->assertEmpty( $result ); @@ -1263,7 +1266,7 @@ public function test_search_wordpress_users_no_match_returns_empty(): void { public function test_render_selectize_templates_no_output_without_capability(): void { // Create a subscriber (no manage_network capability). - $user_id = $this->factory->user->create( [ 'role' => 'subscriber' ] ); + $user_id = $this->factory->user->create( ['role' => 'subscriber'] ); wp_set_current_user( $user_id ); ob_start(); @@ -1280,7 +1283,7 @@ public function test_render_selectize_templates_no_output_without_capability(): public function test_render_selectize_templates_calls_template_for_admin(): void { // Grant manage_network to current user. - $user_id = $this->factory->user->create( [ 'role' => 'administrator' ] ); + $user_id = $this->factory->user->create( ['role' => 'administrator'] ); wp_set_current_user( $user_id ); grant_super_admin( $user_id ); diff --git a/tests/WP_Ultimo/Apis/MCP_Abilities_Test.php b/tests/WP_Ultimo/Apis/MCP_Abilities_Test.php index fb0779887..e10637d00 100644 --- a/tests/WP_Ultimo/Apis/MCP_Abilities_Test.php +++ b/tests/WP_Ultimo/Apis/MCP_Abilities_Test.php @@ -78,7 +78,7 @@ public function test_enable_mcp_abilities_bails_when_function_missing(): void { $this->manager->enable_mcp_abilities(); // Hooks should be registered since wp_register_ability exists in vendor. - $has_category_hook = has_action('wp_abilities_api_categories_init', [$this->manager, 'register_ability_category']); + $has_category_hook = has_action('wp_abilities_api_categories_init', [$this->manager, 'register_ability_category']); $has_abilities_hook = has_action('wp_abilities_api_init', [$this->manager, 'register_abilities']); $this->assertNotFalse($has_category_hook); @@ -179,7 +179,10 @@ public function test_mcp_permission_callback_ignores_input_data(): void { wp_set_current_user(1); // Pass arbitrary data — should not affect result. - $result = $this->manager->mcp_permission_callback(['foo' => 'bar', 'id' => 999]); + $result = $this->manager->mcp_permission_callback([ + 'foo' => 'bar', + 'id' => 999, + ]); $this->assertTrue($result); diff --git a/tests/WP_Ultimo/Apis/Rest_Api_Trait_Test.php b/tests/WP_Ultimo/Apis/Rest_Api_Trait_Test.php index be00fe636..9d6a44ab9 100644 --- a/tests/WP_Ultimo/Apis/Rest_Api_Trait_Test.php +++ b/tests/WP_Ultimo/Apis/Rest_Api_Trait_Test.php @@ -71,7 +71,7 @@ class Stub_Rest_Model { * * @param array $data Initial data. */ - public function __construct( array $data = [] ) { + public function __construct(array $data = []) { $this->data = $data; } @@ -82,7 +82,7 @@ public function __construct( array $data = [] ) { * @param int $id Item ID. * @return static|null */ - public static function get_by_id( $id ) { + public static function get_by_id($id) { return static::$items[ $id ] ?? null; } @@ -93,7 +93,7 @@ public static function get_by_id( $id ) { * @param array $args Query args. * @return array|int */ - public static function query( array $args = [] ) { + public static function query(array $args = []) { if ( ! empty( $args['count'] ) ) { return count( static::$items ); @@ -143,7 +143,7 @@ public function delete() { * @param array $values Meta values. * @return void */ - public function update_meta_batch( array $values ): void { + public function update_meta_batch(array $values): void { $this->data['meta'] = $values; } @@ -154,7 +154,7 @@ public function update_meta_batch( array $values ): void { * @param mixed $value Value. * @return void */ - public function set_name( $value ): void { + public function set_name($value): void { $this->data['name'] = $value; } @@ -249,7 +249,7 @@ public function set_up(): void { * @param mixed $result The result from a trait method. * @return WP_Error */ - private function extract_wp_error( $result ): WP_Error { + private function extract_wp_error($result): WP_Error { if ( $result instanceof WP_Error ) { return $result; @@ -303,8 +303,8 @@ public function test_enable_rest_api_registers_hooks_when_enabled(): void { $this->manager->enable_rest_api(); - $this->assertGreaterThan( 0, has_action( 'rest_api_init', [ $this->manager, 'register_routes_general' ] ) ); - $this->assertGreaterThan( 0, has_action( 'rest_api_init', [ $this->manager, 'register_routes_with_id' ] ) ); + $this->assertGreaterThan( 0, has_action( 'rest_api_init', [$this->manager, 'register_routes_general'] ) ); + $this->assertGreaterThan( 0, has_action( 'rest_api_init', [$this->manager, 'register_routes_with_id'] ) ); remove_filter( 'wu_is_api_enabled', '__return_true' ); } @@ -319,8 +319,8 @@ public function test_enable_rest_api_skips_hooks_when_disabled(): void { $manager = new Stub_Rest_Manager(); $manager->enable_rest_api(); - $this->assertFalse( has_action( 'rest_api_init', [ $manager, 'register_routes_general' ] ) ); - $this->assertFalse( has_action( 'rest_api_init', [ $manager, 'register_routes_with_id' ] ) ); + $this->assertFalse( has_action( 'rest_api_init', [$manager, 'register_routes_general'] ) ); + $this->assertFalse( has_action( 'rest_api_init', [$manager, 'register_routes_with_id'] ) ); remove_filter( 'wu_is_api_enabled', '__return_false' ); } @@ -337,7 +337,7 @@ public function test_register_routes_general_fires_action(): void { $fired = false; add_action( 'wu_rest_register_routes_general', - function () use ( &$fired ) { + function () use (&$fired) { $fired = true; } ); @@ -374,12 +374,12 @@ public function test_register_routes_general_only_get_items(): void { $manager = new Stub_Rest_Manager(); $reflection = new \ReflectionClass( $manager ); $prop = $reflection->getProperty( 'enabled_rest_endpoints' ); - $prop->setValue( $manager, [ 'get_items' ] ); + $prop->setValue( $manager, ['get_items'] ); $fired_routes = null; add_action( 'wu_rest_register_routes_general', - function ( $routes ) use ( &$fired_routes ) { + function ($routes) use (&$fired_routes) { $fired_routes = $routes; } ); @@ -399,12 +399,12 @@ public function test_register_routes_general_only_create_item(): void { $manager = new Stub_Rest_Manager(); $reflection = new \ReflectionClass( $manager ); $prop = $reflection->getProperty( 'enabled_rest_endpoints' ); - $prop->setValue( $manager, [ 'create_item' ] ); + $prop->setValue( $manager, ['create_item'] ); $fired_routes = null; add_action( 'wu_rest_register_routes_general', - function ( $routes ) use ( &$fired_routes ) { + function ($routes) use (&$fired_routes) { $fired_routes = $routes; } ); @@ -428,7 +428,7 @@ public function test_register_routes_with_id_fires_action(): void { $fired = false; add_action( 'wu_rest_register_routes_with_id', - function () use ( &$fired ) { + function () use (&$fired) { $fired = true; } ); @@ -462,7 +462,7 @@ public function test_register_routes_with_id_all_endpoints(): void { $fired_routes = null; add_action( 'wu_rest_register_routes_with_id', - function ( $routes ) use ( &$fired_routes ) { + function ($routes) use (&$fired_routes) { $fired_routes = $routes; } ); @@ -497,7 +497,7 @@ public function test_get_item_rest_returns_error_when_not_found(): void { */ public function test_get_item_rest_returns_item_when_found(): void { - $item = new Stub_Rest_Model( [ 'name' => 'Test' ] ); + $item = new Stub_Rest_Model( ['name' => 'Test'] ); Stub_Rest_Model::$items[42] = $item; $request = new WP_REST_Request( 'GET', '/wu/v2/stub_rest_model/42' ); @@ -520,7 +520,7 @@ public function test_get_items_rest_returns_response_with_headers(): void { // Populate 5 items. for ( $i = 1; $i <= 5; $i++ ) { - Stub_Rest_Model::$items[ $i ] = new Stub_Rest_Model( [ 'name' => "Item $i" ] ); + Stub_Rest_Model::$items[ $i ] = new Stub_Rest_Model( ['name' => "Item $i"] ); } $request = new WP_REST_Request( 'GET', '/wu/v2/stub_rest_model' ); @@ -569,7 +569,7 @@ public function test_get_items_rest_clamps_per_page_below_one(): void { public function test_get_items_rest_second_page(): void { for ( $i = 1; $i <= 10; $i++ ) { - Stub_Rest_Model::$items[ $i ] = new Stub_Rest_Model( [ 'name' => "Item $i" ] ); + Stub_Rest_Model::$items[ $i ] = new Stub_Rest_Model( ['name' => "Item $i"] ); } $request = new WP_REST_Request( 'GET', '/wu/v2/stub_rest_model' ); @@ -632,7 +632,7 @@ public function test_get_collection_params_per_page_defaults(): void { public function test_create_item_rest_success_via_new_instance(): void { $request = new WP_REST_Request( 'POST', '/wu/v2/stub_rest_model' ); - $request->set_body( json_encode( [ 'name' => 'New Item' ] ) ); + $request->set_body( json_encode( ['name' => 'New Item'] ) ); $result = $this->manager->create_item_rest( $request ); @@ -649,7 +649,7 @@ public function test_create_item_rest_returns_error_when_save_fails(): void { Stub_Rest_Model::$save_fails = true; $request = new WP_REST_Request( 'POST', '/wu/v2/stub_rest_model' ); - $request->set_body( json_encode( [ 'name' => 'Fail Item' ] ) ); + $request->set_body( json_encode( ['name' => 'Fail Item'] ) ); $result = $this->manager->create_item_rest( $request ); @@ -665,7 +665,7 @@ public function test_create_item_rest_returns_wp_error_response_when_save_errors Stub_Rest_Model::$save_returns_error = true; $request = new WP_REST_Request( 'POST', '/wu/v2/stub_rest_model' ); - $request->set_body( json_encode( [ 'name' => 'Error Item' ] ) ); + $request->set_body( json_encode( ['name' => 'Error Item'] ) ); $result = $this->manager->create_item_rest( $request ); @@ -686,7 +686,7 @@ public function test_create_item_rest_uses_saver_function_when_exists(): void { } $request = new WP_REST_Request( 'POST', '/wu/v2/stub_rest_model' ); - $request->set_body( json_encode( [ 'name' => 'Saver Item' ] ) ); + $request->set_body( json_encode( ['name' => 'Saver Item'] ) ); $result = $this->manager->create_item_rest( $request ); @@ -704,8 +704,8 @@ public function test_create_item_rest_uses_saver_function_when_exists(): void { public function test_update_item_rest_returns_error_when_not_found(): void { $request = new WP_REST_Request( 'PUT', '/wu/v2/stub_rest_model/999' ); - $request->set_url_params( [ 'id' => 999 ] ); - $request->set_body( json_encode( [ 'name' => 'Updated' ] ) ); + $request->set_url_params( ['id' => 999] ); + $request->set_body( json_encode( ['name' => 'Updated'] ) ); $result = $this->manager->update_item_rest( $request ); @@ -718,12 +718,12 @@ public function test_update_item_rest_returns_error_when_not_found(): void { */ public function test_update_item_rest_success_via_setter(): void { - $item = new Stub_Rest_Model( [ 'name' => 'Original' ] ); + $item = new Stub_Rest_Model( ['name' => 'Original'] ); Stub_Rest_Model::$items[10] = $item; $request = new WP_REST_Request( 'PUT', '/wu/v2/stub_rest_model/10' ); - $request->set_url_params( [ 'id' => 10 ] ); - $request->set_body( json_encode( [ 'name' => 'Updated Name' ] ) ); + $request->set_url_params( ['id' => 10] ); + $request->set_body( json_encode( ['name' => 'Updated Name'] ) ); $result = $this->manager->update_item_rest( $request ); @@ -741,13 +741,13 @@ public function test_update_item_rest_updates_meta(): void { Stub_Rest_Model::$items[11] = $item; $request = new WP_REST_Request( 'PUT', '/wu/v2/stub_rest_model/11' ); - $request->set_url_params( [ 'id' => 11 ] ); - $request->set_body( json_encode( [ 'meta' => [ 'key' => 'value' ] ] ) ); + $request->set_url_params( ['id' => 11] ); + $request->set_body( json_encode( ['meta' => ['key' => 'value']] ) ); $result = $this->manager->update_item_rest( $request ); $this->assertInstanceOf( \WP_REST_Response::class, $result ); - $this->assertEquals( [ 'key' => 'value' ], $item->data['meta'] ); + $this->assertEquals( ['key' => 'value'], $item->data['meta'] ); } /** @@ -759,8 +759,8 @@ public function test_update_item_rest_returns_error_for_missing_setter(): void { Stub_Rest_Model::$items[12] = $item; $request = new WP_REST_Request( 'PUT', '/wu/v2/stub_rest_model/12' ); - $request->set_url_params( [ 'id' => 12 ] ); - $request->set_body( json_encode( [ 'nonexistent_field' => 'value' ] ) ); + $request->set_url_params( ['id' => 12] ); + $request->set_body( json_encode( ['nonexistent_field' => 'value'] ) ); $result = $this->manager->update_item_rest( $request ); @@ -778,8 +778,8 @@ public function test_update_item_rest_returns_error_when_save_fails(): void { Stub_Rest_Model::$save_fails = true; $request = new WP_REST_Request( 'PUT', '/wu/v2/stub_rest_model/13' ); - $request->set_url_params( [ 'id' => 13 ] ); - $request->set_body( json_encode( [ 'name' => 'Updated' ] ) ); + $request->set_url_params( ['id' => 13] ); + $request->set_body( json_encode( ['name' => 'Updated'] ) ); $result = $this->manager->update_item_rest( $request ); @@ -797,8 +797,8 @@ public function test_update_item_rest_returns_wp_error_response_when_save_errors Stub_Rest_Model::$save_returns_error = true; $request = new WP_REST_Request( 'PUT', '/wu/v2/stub_rest_model/14' ); - $request->set_url_params( [ 'id' => 14 ] ); - $request->set_body( json_encode( [ 'name' => 'Updated' ] ) ); + $request->set_url_params( ['id' => 14] ); + $request->set_body( json_encode( ['name' => 'Updated'] ) ); $result = $this->manager->update_item_rest( $request ); @@ -815,7 +815,7 @@ public function test_update_item_rest_filters_credential_keys(): void { Stub_Rest_Model::$items[15] = $item; $request = new WP_REST_Request( 'PUT', '/wu/v2/stub_rest_model/15' ); - $request->set_url_params( [ 'id' => 15 ] ); + $request->set_url_params( ['id' => 15] ); $request->set_body( json_encode( [ 'name' => 'Safe', 'api_key' => 'should-be-filtered', @@ -982,8 +982,8 @@ public function test_permission_checks_filter_is_registered(): void { public function test_filter_schema_arguments_removes_author_id_for_non_broadcast(): void { $args = [ - 'author_id' => [ 'type' => 'integer' ], - 'name' => [ 'type' => 'string' ], + 'author_id' => ['type' => 'integer'], + 'name' => ['type' => 'string'], ]; $result = $this->manager->filter_schema_arguments( $args ); @@ -1003,8 +1003,8 @@ public function test_filter_schema_arguments_keeps_author_id_for_broadcast(): vo $prop->setValue( $manager, 'broadcast' ); $args = [ - 'author_id' => [ 'type' => 'integer' ], - 'name' => [ 'type' => 'string' ], + 'author_id' => ['type' => 'integer'], + 'name' => ['type' => 'string'], ]; $result = $manager->filter_schema_arguments( $args ); @@ -1018,8 +1018,8 @@ public function test_filter_schema_arguments_keeps_author_id_for_broadcast(): vo public function test_filter_schema_arguments_removes_list_order(): void { $args = [ - 'list_order' => [ 'type' => 'integer' ], - 'name' => [ 'type' => 'string' ], + 'list_order' => ['type' => 'integer'], + 'name' => ['type' => 'string'], ]; $result = $this->manager->filter_schema_arguments( $args ); @@ -1033,8 +1033,8 @@ public function test_filter_schema_arguments_removes_list_order(): void { public function test_filter_schema_arguments_removes_status_for_non_status_slugs(): void { $args = [ - 'status' => [ 'type' => 'string' ], - 'name' => [ 'type' => 'string' ], + 'status' => ['type' => 'string'], + 'name' => ['type' => 'string'], ]; $result = $this->manager->filter_schema_arguments( $args ); @@ -1053,8 +1053,8 @@ public function test_filter_schema_arguments_keeps_status_for_broadcast(): void $prop->setValue( $manager, 'broadcast' ); $args = [ - 'status' => [ 'type' => 'string' ], - 'name' => [ 'type' => 'string' ], + 'status' => ['type' => 'string'], + 'name' => ['type' => 'string'], ]; $result = $manager->filter_schema_arguments( $args ); @@ -1068,8 +1068,8 @@ public function test_filter_schema_arguments_keeps_status_for_broadcast(): void public function test_filter_schema_arguments_removes_slug_field_for_non_slug_slugs(): void { $args = [ - 'slug' => [ 'type' => 'string' ], - 'name' => [ 'type' => 'string' ], + 'slug' => ['type' => 'string'], + 'name' => ['type' => 'string'], ]; $result = $this->manager->filter_schema_arguments( $args ); @@ -1088,8 +1088,8 @@ public function test_filter_schema_arguments_keeps_slug_for_broadcast(): void { $prop->setValue( $manager, 'broadcast' ); $args = [ - 'slug' => [ 'type' => 'string' ], - 'name' => [ 'type' => 'string' ], + 'slug' => ['type' => 'string'], + 'name' => ['type' => 'string'], ]; $result = $manager->filter_schema_arguments( $args ); @@ -1108,8 +1108,8 @@ public function test_filter_schema_arguments_removes_price_variations_for_produc $prop->setValue( $manager, 'product' ); $args = [ - 'price_variations' => [ 'type' => 'array' ], - 'name' => [ 'type' => 'string' ], + 'price_variations' => ['type' => 'array'], + 'name' => ['type' => 'string'], ]; $result = $manager->filter_schema_arguments( $args ); @@ -1128,8 +1128,8 @@ public function test_filter_schema_arguments_removes_line_items_for_payment(): v $prop->setValue( $manager, 'payment' ); $args = [ - 'line_items' => [ 'type' => 'array' ], - 'name' => [ 'type' => 'string' ], + 'line_items' => ['type' => 'array'], + 'name' => ['type' => 'string'], ]; $result = $manager->filter_schema_arguments( $args ); @@ -1148,9 +1148,9 @@ public function test_filter_schema_arguments_removes_site_fields(): void { $prop->setValue( $manager, 'site' ); $args = [ - 'duplication_arguments' => [ 'type' => 'array' ], - 'transient' => [ 'type' => 'string' ], - 'name' => [ 'type' => 'string' ], + 'duplication_arguments' => ['type' => 'array'], + 'transient' => ['type' => 'string'], + 'name' => ['type' => 'string'], ]; $result = $manager->filter_schema_arguments( $args ); @@ -1171,9 +1171,9 @@ public function test_filter_schema_arguments_removes_email_fields(): void { $prop->setValue( $manager, 'email' ); $args = [ - 'status' => [ 'type' => 'string' ], - 'email_schedule' => [ 'type' => 'string' ], - 'name' => [ 'type' => 'string' ], + 'status' => ['type' => 'string'], + 'email_schedule' => ['type' => 'string'], + 'name' => ['type' => 'string'], ]; $result = $manager->filter_schema_arguments( $args ); @@ -1194,8 +1194,8 @@ public function test_filter_schema_arguments_removes_message_targets_for_broadca $prop->setValue( $manager, 'broadcast' ); $args = [ - 'message_targets' => [ 'type' => 'array' ], - 'name' => [ 'type' => 'string' ], + 'message_targets' => ['type' => 'array'], + 'name' => ['type' => 'string'], ]; $result = $manager->filter_schema_arguments( $args ); @@ -1209,8 +1209,8 @@ public function test_filter_schema_arguments_removes_message_targets_for_broadca public function test_filter_schema_arguments_removes_billing_address(): void { $args = [ - 'billing_address' => [ 'type' => 'object' ], - 'name' => [ 'type' => 'string' ], + 'billing_address' => ['type' => 'object'], + 'name' => ['type' => 'string'], ]; $result = $this->manager->filter_schema_arguments( $args ); @@ -1228,7 +1228,7 @@ public function test_filter_schema_arguments_fires_filters(): void { add_filter( 'wu_before_stub_rest_model_api_arguments', - function ( $args ) use ( &$before_fired ) { + function ($args) use (&$before_fired) { $before_fired = true; return $args; } @@ -1236,13 +1236,13 @@ function ( $args ) use ( &$before_fired ) { add_filter( 'wu_after_stub_rest_model_api_arguments', - function ( $args ) use ( &$after_fired ) { + function ($args) use (&$after_fired) { $after_fired = true; return $args; } ); - $this->manager->filter_schema_arguments( [ 'name' => [ 'type' => 'string' ] ] ); + $this->manager->filter_schema_arguments( ['name' => ['type' => 'string']] ); $this->assertTrue( $before_fired ); $this->assertTrue( $after_fired ); @@ -1264,7 +1264,7 @@ public function test_credential_keys_filtered_during_update(): void { Stub_Rest_Model::$items[30] = $item; $request = new WP_REST_Request( 'PUT', '/wu/v2/stub_rest_model/30' ); - $request->set_url_params( [ 'id' => 30 ] ); + $request->set_url_params( ['id' => 30] ); // Only credential keys — no valid setter, but they should be filtered before reaching setter check. $request->set_body( json_encode( [ 'api_key' => 'key', diff --git a/tests/WP_Ultimo/Async_Calls_Test.php b/tests/WP_Ultimo/Async_Calls_Test.php index d2cef58eb..348f541a0 100644 --- a/tests/WP_Ultimo/Async_Calls_Test.php +++ b/tests/WP_Ultimo/Async_Calls_Test.php @@ -175,19 +175,34 @@ public function test_build_url_list_includes_extra_args() { public function test_condense_results_returns_true_when_all_success() { $results = [ - (object) ['success' => true, 'data' => 'ok'], - (object) ['success' => true, 'data' => 'ok'], + (object) [ + 'success' => true, + 'data' => 'ok', + ], + (object) [ + 'success' => true, + 'data' => 'ok', + ], ]; $this->assertTrue(Async_Calls::condense_results($results)); } public function test_condense_results_returns_failure_on_first_error() { - $error = (object) ['success' => false, 'data' => 'error msg']; + $error = (object) [ + 'success' => false, + 'data' => 'error msg', + ]; $results = [ - (object) ['success' => true, 'data' => 'ok'], + (object) [ + 'success' => true, + 'data' => 'ok', + ], $error, - (object) ['success' => true, 'data' => 'ok'], + (object) [ + 'success' => true, + 'data' => 'ok', + ], ]; $result = Async_Calls::condense_results($results); diff --git a/tests/WP_Ultimo/Autoloader_Test.php b/tests/WP_Ultimo/Autoloader_Test.php index 19d25e3e6..b91a1f796 100644 --- a/tests/WP_Ultimo/Autoloader_Test.php +++ b/tests/WP_Ultimo/Autoloader_Test.php @@ -47,7 +47,7 @@ public function test_instance_property_exists() { // ------------------------------------------------------------------ public function test_constructor_is_private() { - $ref = new \ReflectionClass(Autoloader::class); + $ref = new \ReflectionClass(Autoloader::class); $constructor = $ref->getConstructor(); $this->assertTrue($constructor->isPrivate()); diff --git a/tests/WP_Ultimo/Checkout/Cart_Coverage_Test.php b/tests/WP_Ultimo/Checkout/Cart_Coverage_Test.php index 25707aa6a..1a0904464 100644 --- a/tests/WP_Ultimo/Checkout/Cart_Coverage_Test.php +++ b/tests/WP_Ultimo/Checkout/Cart_Coverage_Test.php @@ -72,8 +72,6 @@ public static function set_up_before_class() { global $wpdb; $wpdb->query( "TRUNCATE TABLE {$wpdb->prefix}wu_customers" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery - - $unique = 'cov' . uniqid(); $result = wu_create_customer( @@ -154,13 +152,13 @@ public function tear_down() { * @param string $recurring_mode PWYW recurring mode. * @return void */ - private function prime_pwyw_meta( $product, float $suggested_amount = 0.0, float $minimum_amount = 0.0, string $recurring_mode = 'customer_choice' ) { + private function prime_pwyw_meta($product, float $suggested_amount = 0.0, float $minimum_amount = 0.0, string $recurring_mode = 'customer_choice') { $product_id = $product->get_id(); // Use the wu_filter_product_item BerlinDB filter to intercept product fetches // and inject the PWYW values directly onto the product object. // This bypasses the meta table entirely, which may not be available in tests. - $callback = function ( $item ) use ( $product_id, $suggested_amount, $minimum_amount, $recurring_mode ) { + $callback = function ($item) use ($product_id, $suggested_amount, $minimum_amount, $recurring_mode) { if ( ! is_object( $item ) ) { return $item; } @@ -172,7 +170,7 @@ private function prime_pwyw_meta( $product, float $suggested_amount = 0.0, float // Use the get_wu_product_metadata filter to intercept meta reads. // NOTE: This only works if is_meta_available() returns true (i.e., $wpdb->wu_productmeta is set). // As a fallback, we also directly set the values on the product object. - $meta_callback = function ( $value, $object_id, $meta_key, $single ) use ( $product_id, $suggested_amount, $minimum_amount, $recurring_mode ) { + $meta_callback = function ($value, $object_id, $meta_key, $single) use ($product_id, $suggested_amount, $minimum_amount, $recurring_mode) { if ( (int) $object_id !== (int) $product_id ) { return $value; } @@ -182,7 +180,7 @@ private function prime_pwyw_meta( $product, float $suggested_amount = 0.0, float 'wu_pwyw_recurring_mode' => $recurring_mode, ]; if ( isset( $pwyw_values[ $meta_key ] ) ) { - return $single ? $pwyw_values[ $meta_key ] : [ $pwyw_values[ $meta_key ] ]; + return $single ? $pwyw_values[ $meta_key ] : [$pwyw_values[ $meta_key ]]; } return $value; }; @@ -215,7 +213,7 @@ private function prime_pwyw_meta( $product, float $suggested_amount = 0.0, float * @param array $overrides Optional overrides. * @return \WP_Ultimo\Models\Product */ - private function create_plan( array $overrides = [] ) { + private function create_plan(array $overrides = []) { $uid = uniqid( 'cp-' ); $defaults = [ @@ -245,7 +243,7 @@ private function create_plan( array $overrides = [] ) { * @param array $overrides Optional overrides. * @return \WP_Ultimo\Models\Product */ - private function create_service( array $overrides = [] ) { + private function create_service(array $overrides = []) { $uid = uniqid( 'cs-' ); $defaults = [ @@ -276,18 +274,18 @@ private function create_service( array $overrides = [] ) { * @param array $overrides Optional overrides. * @return Membership */ - private function create_active_membership( $plan, array $overrides = [] ) { + private function create_active_membership($plan, array $overrides = []) { $defaults = [ - 'customer_id' => self::$customer->get_id(), - 'plan_id' => $plan->get_id(), - 'status' => 'active', - 'recurring' => true, - 'amount' => $plan->get_amount(), - 'duration' => $plan->get_duration(), - 'duration_unit' => $plan->get_duration_unit(), + 'customer_id' => self::$customer->get_id(), + 'plan_id' => $plan->get_id(), + 'status' => 'active', + 'recurring' => true, + 'amount' => $plan->get_amount(), + 'duration' => $plan->get_duration(), + 'duration_unit' => $plan->get_duration_unit(), 'date_expiration' => gmdate( 'Y-m-d 23:59:59', strtotime( '+30 days' ) ), - 'date_created' => wu_get_current_time( 'mysql', true ), - 'date_activated' => wu_get_current_time( 'mysql', true ), + 'date_created' => wu_get_current_time( 'mysql', true ), + 'date_activated' => wu_get_current_time( 'mysql', true ), ]; $membership = wu_create_membership( array_merge( $defaults, $overrides ) ); @@ -341,11 +339,11 @@ public function test_build_from_payment_wrong_customer() { $membership = wu_create_membership( [ - 'customer_id' => $other_customer->get_id(), - 'plan_id' => $plan->get_id(), - 'status' => 'active', - 'amount' => $plan->get_amount(), - 'duration' => $plan->get_duration(), + 'customer_id' => $other_customer->get_id(), + 'plan_id' => $plan->get_id(), + 'status' => 'active', + 'amount' => $plan->get_amount(), + 'duration' => $plan->get_duration(), 'duration_unit' => $plan->get_duration_unit(), ] ); @@ -358,11 +356,11 @@ public function test_build_from_payment_wrong_customer() { $payment = wu_create_payment( [ - 'customer_id' => $other_customer->get_id(), + 'customer_id' => $other_customer->get_id(), 'membership_id' => $membership->get_id(), - 'total' => 50.00, - 'subtotal' => 50.00, - 'status' => Payment_Status::PENDING, + 'total' => 50.00, + 'subtotal' => 50.00, + 'status' => Payment_Status::PENDING, ] ); @@ -398,16 +396,16 @@ public function test_build_from_payment_wrong_customer() { public function test_build_from_payment_pending_payment_pending_membership() { wp_set_current_user( self::$customer->get_user_id() ); - $plan = $this->create_plan( [ 'amount' => 30.00 ] ); + $plan = $this->create_plan( ['amount' => 30.00] ); // Create a membership with 'pending' status (not active, not trialing) $membership = wu_create_membership( [ - 'customer_id' => self::$customer->get_id(), - 'plan_id' => $plan->get_id(), - 'status' => 'pending', - 'amount' => 30.00, - 'duration' => 1, + 'customer_id' => self::$customer->get_id(), + 'plan_id' => $plan->get_id(), + 'status' => 'pending', + 'amount' => 30.00, + 'duration' => 1, 'duration_unit' => 'month', ] ); @@ -419,11 +417,11 @@ public function test_build_from_payment_pending_payment_pending_membership() { $payment = wu_create_payment( [ - 'customer_id' => self::$customer->get_id(), + 'customer_id' => self::$customer->get_id(), 'membership_id' => $membership->get_id(), - 'total' => 30.00, - 'subtotal' => 30.00, - 'status' => Payment_Status::PENDING, + 'total' => 30.00, + 'subtotal' => 30.00, + 'status' => Payment_Status::PENDING, ] ); @@ -454,17 +452,17 @@ public function test_build_from_payment_pending_payment_pending_membership() { public function test_build_from_payment_completed_payment() { wp_set_current_user( self::$customer->get_user_id() ); - $plan = $this->create_plan( [ 'amount' => 40.00 ] ); + $plan = $this->create_plan( ['amount' => 40.00] ); $membership = $this->create_active_membership( $plan ); $payment = wu_create_payment( [ - 'customer_id' => self::$customer->get_id(), + 'customer_id' => self::$customer->get_id(), 'membership_id' => $membership->get_id(), - 'total' => 40.00, - 'subtotal' => 40.00, - 'status' => Payment_Status::COMPLETED, + 'total' => 40.00, + 'subtotal' => 40.00, + 'status' => Payment_Status::COMPLETED, ] ); @@ -495,17 +493,17 @@ public function test_build_from_payment_completed_payment() { public function test_build_from_payment_cancelled_payment() { wp_set_current_user( self::$customer->get_user_id() ); - $plan = $this->create_plan( [ 'amount' => 40.00 ] ); + $plan = $this->create_plan( ['amount' => 40.00] ); $membership = $this->create_active_membership( $plan ); $payment = wu_create_payment( [ - 'customer_id' => self::$customer->get_id(), + 'customer_id' => self::$customer->get_id(), 'membership_id' => $membership->get_id(), - 'total' => 40.00, - 'subtotal' => 40.00, - 'status' => Payment_Status::CANCELLED, + 'total' => 40.00, + 'subtotal' => 40.00, + 'status' => Payment_Status::CANCELLED, ] ); @@ -536,15 +534,15 @@ public function test_build_from_payment_cancelled_payment() { public function test_build_from_payment_invalid_status() { wp_set_current_user( self::$customer->get_user_id() ); - $plan = $this->create_plan( [ 'amount' => 40.00 ] ); + $plan = $this->create_plan( ['amount' => 40.00] ); $membership = wu_create_membership( [ - 'customer_id' => self::$customer->get_id(), - 'plan_id' => $plan->get_id(), - 'status' => 'pending', - 'amount' => 40.00, - 'duration' => 1, + 'customer_id' => self::$customer->get_id(), + 'plan_id' => $plan->get_id(), + 'status' => 'pending', + 'amount' => 40.00, + 'duration' => 1, 'duration_unit' => 'month', ] ); @@ -557,11 +555,11 @@ public function test_build_from_payment_invalid_status() { // Create a payment with 'refunded' status (not in allowed list for retry) $payment = wu_create_payment( [ - 'customer_id' => self::$customer->get_id(), + 'customer_id' => self::$customer->get_id(), 'membership_id' => $membership->get_id(), - 'total' => 40.00, - 'subtotal' => 40.00, - 'status' => 'refunded', + 'total' => 40.00, + 'subtotal' => 40.00, + 'status' => 'refunded', ] ); @@ -596,15 +594,15 @@ public function test_build_from_payment_invalid_status() { public function test_pending_membership_id_is_ignored() { wp_set_current_user( self::$customer->get_user_id() ); - $plan = $this->create_plan( [ 'amount' => 50.00 ] ); + $plan = $this->create_plan( ['amount' => 50.00] ); $pending_membership = wu_create_membership( [ - 'customer_id' => self::$customer->get_id(), - 'plan_id' => $plan->get_id(), - 'status' => 'pending', - 'amount' => 50.00, - 'duration' => 1, + 'customer_id' => self::$customer->get_id(), + 'plan_id' => $plan->get_id(), + 'status' => 'pending', + 'amount' => 50.00, + 'duration' => 1, 'duration_unit' => 'month', ] ); @@ -614,13 +612,13 @@ public function test_pending_membership_id_is_ignored() { $this->markTestSkipped( 'Could not create pending membership' ); } - $new_plan = $this->create_plan( [ 'amount' => 75.00 ] ); + $new_plan = $this->create_plan( ['amount' => 75.00] ); $cart = new Cart( [ 'cart_type' => 'upgrade', 'membership_id' => $pending_membership->get_id(), - 'products' => [ $new_plan->get_id() ], + 'products' => [$new_plan->get_id()], ] ); @@ -643,7 +641,7 @@ public function test_pending_membership_id_is_ignored() { public function test_membership_change_with_no_products_adds_error() { wp_set_current_user( self::$customer->get_user_id() ); - $plan = $this->create_plan( [ 'amount' => 50.00 ] ); + $plan = $this->create_plan( ['amount' => 50.00] ); $membership = $this->create_active_membership( $plan ); @@ -674,17 +672,17 @@ public function test_membership_change_with_no_products_adds_error() { public function test_membership_change_no_products_with_payment_no_error() { wp_set_current_user( self::$customer->get_user_id() ); - $plan = $this->create_plan( [ 'amount' => 50.00 ] ); + $plan = $this->create_plan( ['amount' => 50.00] ); $membership = $this->create_active_membership( $plan ); $payment = wu_create_payment( [ - 'customer_id' => self::$customer->get_id(), + 'customer_id' => self::$customer->get_id(), 'membership_id' => $membership->get_id(), - 'total' => 50.00, - 'subtotal' => 50.00, - 'status' => Payment_Status::COMPLETED, + 'total' => 50.00, + 'subtotal' => 50.00, + 'status' => Payment_Status::COMPLETED, ] ); @@ -724,8 +722,8 @@ public function test_membership_change_no_products_with_payment_no_error() { public function test_addon_cart_service_only() { wp_set_current_user( self::$customer->get_user_id() ); - $plan = $this->create_plan( [ 'amount' => 50.00 ] ); - $service = $this->create_service( [ 'amount' => 15.00 ] ); + $plan = $this->create_plan( ['amount' => 50.00] ); + $service = $this->create_service( ['amount' => 15.00] ); $membership = $this->create_active_membership( $plan ); @@ -733,7 +731,7 @@ public function test_addon_cart_service_only() { [ 'cart_type' => 'addon', 'membership_id' => $membership->get_id(), - 'products' => [ $service->get_id() ], + 'products' => [$service->get_id()], ] ); @@ -752,8 +750,8 @@ public function test_addon_cart_service_only() { public function test_addon_cart_applies_membership_discount_code() { wp_set_current_user( self::$customer->get_user_id() ); - $plan = $this->create_plan( [ 'amount' => 50.00 ] ); - $service = $this->create_service( [ 'amount' => 20.00 ] ); + $plan = $this->create_plan( ['amount' => 50.00] ); + $service = $this->create_service( ['amount' => 20.00] ); $code = 'RNWDSC' . uniqid(); @@ -783,7 +781,7 @@ public function test_addon_cart_applies_membership_discount_code() { [ 'cart_type' => 'addon', 'membership_id' => $membership->get_id(), - 'products' => [ $service->get_id() ], + 'products' => [$service->get_id()], ] ); @@ -802,7 +800,7 @@ public function test_addon_cart_applies_membership_discount_code() { public function test_addon_cart_no_products_adds_error() { wp_set_current_user( self::$customer->get_user_id() ); - $plan = $this->create_plan( [ 'amount' => 50.00 ] ); + $plan = $this->create_plan( ['amount' => 50.00] ); $membership = $this->create_active_membership( $plan ); @@ -811,7 +809,7 @@ public function test_addon_cart_no_products_adds_error() { [ 'cart_type' => 'addon', 'membership_id' => $membership->get_id(), - 'products' => [ 999999 ], // non-existent + 'products' => [999999], // non-existent ] ); @@ -828,7 +826,7 @@ public function test_addon_cart_no_products_adds_error() { public function test_addon_cart_no_changes_error_suppressed_by_filter() { wp_set_current_user( self::$customer->get_user_id() ); - $plan = $this->create_plan( [ 'amount' => 50.00 ] ); + $plan = $this->create_plan( ['amount' => 50.00] ); $membership = $this->create_active_membership( $plan ); @@ -839,7 +837,7 @@ public function test_addon_cart_no_changes_error_suppressed_by_filter() { [ 'cart_type' => 'addon', 'membership_id' => $membership->get_id(), - 'products' => [ 999999 ], // non-existent + 'products' => [999999], // non-existent ] ); @@ -864,8 +862,8 @@ public function test_addon_cart_no_changes_error_suppressed_by_filter() { public function test_addon_cart_plan_plus_service_removes_plan() { wp_set_current_user( self::$customer->get_user_id() ); - $plan = $this->create_plan( [ 'amount' => 50.00 ] ); - $service = $this->create_service( [ 'amount' => 20.00 ] ); + $plan = $this->create_plan( ['amount' => 50.00] ); + $service = $this->create_service( ['amount' => 20.00] ); $membership = $this->create_active_membership( $plan ); @@ -874,7 +872,7 @@ public function test_addon_cart_plan_plus_service_removes_plan() { [ 'cart_type' => 'addon', 'membership_id' => $membership->get_id(), - 'products' => [ $plan->get_id(), $service->get_id() ], + 'products' => [$plan->get_id(), $service->get_id()], ] ); @@ -899,8 +897,8 @@ public function test_addon_cart_plan_plus_service_removes_plan() { public function test_upgrade_cart_more_expensive_plan() { wp_set_current_user( self::$customer->get_user_id() ); - $cheap_plan = $this->create_plan( [ 'amount' => 20.00 ] ); - $expensive_plan = $this->create_plan( [ 'amount' => 80.00 ] ); + $cheap_plan = $this->create_plan( ['amount' => 20.00] ); + $expensive_plan = $this->create_plan( ['amount' => 80.00] ); $membership = $this->create_active_membership( $cheap_plan ); @@ -908,7 +906,7 @@ public function test_upgrade_cart_more_expensive_plan() { [ 'cart_type' => 'upgrade', 'membership_id' => $membership->get_id(), - 'products' => [ $expensive_plan->get_id() ], + 'products' => [$expensive_plan->get_id()], ] ); @@ -927,8 +925,8 @@ public function test_upgrade_cart_more_expensive_plan() { public function test_downgrade_cart_cheaper_plan() { wp_set_current_user( self::$customer->get_user_id() ); - $expensive_plan = $this->create_plan( [ 'amount' => 100.00 ] ); - $cheap_plan = $this->create_plan( [ 'amount' => 20.00 ] ); + $expensive_plan = $this->create_plan( ['amount' => 100.00] ); + $cheap_plan = $this->create_plan( ['amount' => 20.00] ); $membership = $this->create_active_membership( $expensive_plan ); @@ -936,7 +934,7 @@ public function test_downgrade_cart_cheaper_plan() { [ 'cart_type' => 'downgrade', 'membership_id' => $membership->get_id(), - 'products' => [ $cheap_plan->get_id() ], + 'products' => [$cheap_plan->get_id()], ] ); @@ -954,7 +952,7 @@ public function test_downgrade_cart_cheaper_plan() { public function test_upgrade_to_lifetime_plan() { wp_set_current_user( self::$customer->get_user_id() ); - $monthly_plan = $this->create_plan( [ 'amount' => 50.00 ] ); + $monthly_plan = $this->create_plan( ['amount' => 50.00] ); $lifetime_plan = $this->create_plan( [ 'amount' => 500.00, @@ -969,7 +967,7 @@ public function test_upgrade_to_lifetime_plan() { [ 'cart_type' => 'upgrade', 'membership_id' => $membership->get_id(), - 'products' => [ $lifetime_plan->get_id() ], + 'products' => [$lifetime_plan->get_id()], ] ); @@ -1003,7 +1001,7 @@ public function test_no_changes_error_same_plan_same_duration() { [ 'cart_type' => 'upgrade', 'membership_id' => $membership->get_id(), - 'products' => [ $plan->get_id() ], + 'products' => [$plan->get_id()], 'duration' => 1, 'duration_unit' => 'month', ] @@ -1029,7 +1027,7 @@ public function test_membership_change_nonexistent_membership() { [ 'cart_type' => 'upgrade', 'membership_id' => 999999, - 'products' => [ $plan->get_id() ], + 'products' => [$plan->get_id()], ] ); @@ -1061,11 +1059,11 @@ public function test_membership_change_wrong_customer() { $membership = wu_create_membership( [ - 'customer_id' => $other_customer->get_id(), - 'plan_id' => $plan->get_id(), - 'status' => 'active', - 'amount' => $plan->get_amount(), - 'duration' => $plan->get_duration(), + 'customer_id' => $other_customer->get_id(), + 'plan_id' => $plan->get_id(), + 'status' => 'active', + 'amount' => $plan->get_amount(), + 'duration' => $plan->get_duration(), 'duration_unit' => $plan->get_duration_unit(), ] ); @@ -1079,13 +1077,13 @@ public function test_membership_change_wrong_customer() { // Log in as our shared customer (not the membership owner) wp_set_current_user( self::$customer->get_user_id() ); - $new_plan = $this->create_plan( [ 'amount' => 100.00 ] ); + $new_plan = $this->create_plan( ['amount' => 100.00] ); $cart = new Cart( [ 'cart_type' => 'upgrade', 'membership_id' => $membership->get_id(), - 'products' => [ $new_plan->get_id() ], + 'products' => [$new_plan->get_id()], ] ); @@ -1109,8 +1107,8 @@ public function test_membership_change_wrong_customer() { public function test_prorate_credits_added_for_upgrade() { wp_set_current_user( self::$customer->get_user_id() ); - $cheap_plan = $this->create_plan( [ 'amount' => 20.00 ] ); - $expensive_plan = $this->create_plan( [ 'amount' => 80.00 ] ); + $cheap_plan = $this->create_plan( ['amount' => 20.00] ); + $expensive_plan = $this->create_plan( ['amount' => 80.00] ); $membership = $this->create_active_membership( $cheap_plan ); @@ -1118,7 +1116,7 @@ public function test_prorate_credits_added_for_upgrade() { [ 'cart_type' => 'upgrade', 'membership_id' => $membership->get_id(), - 'products' => [ $expensive_plan->get_id() ], + 'products' => [$expensive_plan->get_id()], ] ); @@ -1138,14 +1136,14 @@ public function test_prorate_credits_added_for_upgrade() { public function test_prorate_credits_filter() { wp_set_current_user( self::$customer->get_user_id() ); - $cheap_plan = $this->create_plan( [ 'amount' => 20.00 ] ); - $expensive_plan = $this->create_plan( [ 'amount' => 80.00 ] ); + $cheap_plan = $this->create_plan( ['amount' => 20.00] ); + $expensive_plan = $this->create_plan( ['amount' => 80.00] ); $membership = $this->create_active_membership( $cheap_plan ); add_filter( 'wu_checkout_calculate_prorate_credits', - function ( $credit ) { + function ($credit) { return 5.00; // Force a fixed credit } ); @@ -1154,7 +1152,7 @@ function ( $credit ) { [ 'cart_type' => 'upgrade', 'membership_id' => $membership->get_id(), - 'products' => [ $expensive_plan->get_id() ], + 'products' => [$expensive_plan->get_id()], ] ); @@ -1178,19 +1176,19 @@ function ( $credit ) { public function test_prorate_credits_skipped_for_trialing_membership() { wp_set_current_user( self::$customer->get_user_id() ); - $cheap_plan = $this->create_plan( [ 'amount' => 20.00 ] ); - $expensive_plan = $this->create_plan( [ 'amount' => 80.00 ] ); + $cheap_plan = $this->create_plan( ['amount' => 20.00] ); + $expensive_plan = $this->create_plan( ['amount' => 80.00] ); $membership = $this->create_active_membership( $cheap_plan, - [ 'status' => Membership_Status::TRIALING ] + ['status' => Membership_Status::TRIALING] ); $cart = new Cart( [ 'cart_type' => 'upgrade', 'membership_id' => $membership->get_id(), - 'products' => [ $expensive_plan->get_id() ], + 'products' => [$expensive_plan->get_id()], ] ); @@ -1226,8 +1224,8 @@ public function test_pwyw_product_with_custom_amount() { $cart = new Cart( [ - 'products' => [ $pwyw_plan->get_id() ], - 'custom_amounts' => [ $pwyw_plan->get_id() => 30.00 ], + 'products' => [$pwyw_plan->get_id()], + 'custom_amounts' => [$pwyw_plan->get_id() => 30.00], ] ); @@ -1253,8 +1251,8 @@ public function test_pwyw_product_below_minimum_adds_error() { $cart = new Cart( [ - 'products' => [ $pwyw_plan->get_id() ], - 'custom_amounts' => [ $pwyw_plan->get_id() => 2.00 ], + 'products' => [$pwyw_plan->get_id()], + 'custom_amounts' => [$pwyw_plan->get_id() => 2.00], ] ); @@ -1282,8 +1280,8 @@ public function test_pwyw_product_above_maximum_adds_error() { $cart = new Cart( [ - 'products' => [ $pwyw_plan->get_id() ], - 'custom_amounts' => [ $pwyw_plan->get_id() => 200.00 ], + 'products' => [$pwyw_plan->get_id()], + 'custom_amounts' => [$pwyw_plan->get_id() => 200.00], ] ); @@ -1312,7 +1310,7 @@ public function test_pwyw_product_uses_suggested_amount() { $cart = new Cart( [ - 'products' => [ $pwyw_plan->get_id() ], + 'products' => [$pwyw_plan->get_id()], // No custom_amounts — should use suggested ] ); @@ -1340,7 +1338,7 @@ public function test_pwyw_product_force_recurring_mode() { $cart = new Cart( [ - 'products' => [ $pwyw_plan->get_id() ], + 'products' => [$pwyw_plan->get_id()], ] ); @@ -1367,7 +1365,7 @@ public function test_pwyw_product_force_one_time_mode() { $cart = new Cart( [ - 'products' => [ $pwyw_plan->get_id() ], + 'products' => [$pwyw_plan->get_id()], ] ); @@ -1394,8 +1392,8 @@ public function test_pwyw_product_customer_choice_recurring() { $cart = new Cart( [ - 'products' => [ $pwyw_plan->get_id() ], - 'pwyw_recurring' => [ $pwyw_plan->get_id() => true ], + 'products' => [$pwyw_plan->get_id()], + 'pwyw_recurring' => [$pwyw_plan->get_id() => true], ] ); @@ -1427,8 +1425,8 @@ public function test_get_custom_amount_for_product_set() { $cart = new Cart( [ - 'products' => [ $plan->get_id() ], - 'custom_amounts' => [ $plan->get_id() => 42.50 ], + 'products' => [$plan->get_id()], + 'custom_amounts' => [$plan->get_id() => 42.50], ] ); @@ -1464,8 +1462,8 @@ public function test_get_pwyw_recurring_for_product_set() { $cart = new Cart( [ - 'products' => [ $plan->get_id() ], - 'pwyw_recurring' => [ $plan->get_id() => true ], + 'products' => [$plan->get_id()], + 'pwyw_recurring' => [$plan->get_id() => true], ] ); @@ -1493,10 +1491,10 @@ public function test_sanitize_pwyw_amounts_filters_invalid() { // Pass invalid keys (0, negative) and non-scalar values $cart = new Cart( [ - 'products' => [ $plan->get_id() ], + 'products' => [$plan->get_id()], 'custom_amounts' => [ - 0 => 10.00, // invalid key (0) - -1 => 5.00, // invalid key (negative) + 0 => 10.00, // invalid key (0) + -1 => 5.00, // invalid key (negative) $plan->get_id() => 25.00, // valid ], ] @@ -1523,8 +1521,8 @@ public function test_sanitize_pwyw_amounts_clamps_negative() { $cart = new Cart( [ - 'products' => [ $plan->get_id() ], - 'custom_amounts' => [ $plan->get_id() => -50.00 ], + 'products' => [$plan->get_id()], + 'custom_amounts' => [$plan->get_id() => -50.00], ] ); @@ -1552,9 +1550,9 @@ public function test_sanitize_pwyw_recurring_filters_invalid() { $cart = new Cart( [ - 'products' => [ $plan->get_id() ], + 'products' => [$plan->get_id()], 'pwyw_recurring' => [ - 0 => true, // invalid key + 0 => true, // invalid key $plan->get_id() => true, // valid ], ] @@ -1575,11 +1573,11 @@ public function test_sanitize_pwyw_recurring_filters_invalid() { * Test get_independent_line_items returns empty for standard products. */ public function test_get_independent_line_items_empty_for_standard_products() { - $plan = $this->create_plan( [ 'amount' => 50.00 ] ); + $plan = $this->create_plan( ['amount' => 50.00] ); $cart = new Cart( [ - 'products' => [ $plan->get_id() ], + 'products' => [$plan->get_id()], ] ); @@ -1611,12 +1609,12 @@ public function test_get_independent_line_items_empty_cart() { public function test_cancel_conflicting_pending_payments_runs_for_new_cart() { wp_set_current_user( self::$customer->get_user_id() ); - $plan = $this->create_plan( [ 'amount' => 50.00 ] ); + $plan = $this->create_plan( ['amount' => 50.00] ); $cart = new Cart( [ 'cart_type' => 'new', - 'products' => [ $plan->get_id() ], + 'products' => [$plan->get_id()], ] ); @@ -1637,19 +1635,19 @@ public function test_cancel_conflicting_pending_payments_runs_for_new_cart() { public function test_cancel_conflicting_pending_payments_skips_non_new_cart() { wp_set_current_user( self::$customer->get_user_id() ); - $plan = $this->create_plan( [ 'amount' => 50.00 ] ); - $new_plan = $this->create_plan( [ 'amount' => 80.00 ] ); + $plan = $this->create_plan( ['amount' => 50.00] ); + $new_plan = $this->create_plan( ['amount' => 80.00] ); // Create an active membership so build_from_membership() succeeds. $membership = $this->create_active_membership( $plan ); $pending_payment = wu_create_payment( [ - 'customer_id' => self::$customer->get_id(), + 'customer_id' => self::$customer->get_id(), 'membership_id' => $membership->get_id(), - 'total' => 50.00, - 'subtotal' => 50.00, - 'status' => Payment_Status::PENDING, + 'total' => 50.00, + 'subtotal' => 50.00, + 'status' => Payment_Status::PENDING, ] ); @@ -1666,7 +1664,7 @@ public function test_cancel_conflicting_pending_payments_skips_non_new_cart() { [ 'cart_type' => 'upgrade', 'membership_id' => $membership->get_id(), - 'products' => [ $new_plan->get_id() ], + 'products' => [$new_plan->get_id()], ] ); @@ -1710,7 +1708,7 @@ public function test_has_trial_true_for_trial_product_no_customer() { $cart = new Cart( [ - 'products' => [ $plan->get_id() ], + 'products' => [$plan->get_id()], ] ); @@ -1738,7 +1736,7 @@ public function test_should_collect_payment_false_for_free_trial_when_setting_al $cart = new Cart( [ - 'products' => [ $plan->get_id() ], + 'products' => [$plan->get_id()], ] ); @@ -1772,7 +1770,7 @@ public function test_has_trial_false_for_customer_who_trialed() { $cart = new Cart( [ - 'products' => [ $plan->get_id() ], + 'products' => [$plan->get_id()], ] ); @@ -1796,21 +1794,21 @@ public function test_has_trial_false_for_customer_who_trialed() { public function test_billing_start_date_for_downgrade_cart() { wp_set_current_user( self::$customer->get_user_id() ); - $expensive_plan = $this->create_plan( [ 'amount' => 100.00 ] ); - $cheap_plan = $this->create_plan( [ 'amount' => 20.00 ] ); + $expensive_plan = $this->create_plan( ['amount' => 100.00] ); + $cheap_plan = $this->create_plan( ['amount' => 20.00] ); $expiration = gmdate( 'Y-m-d 23:59:59', strtotime( '+30 days' ) ); $membership = $this->create_active_membership( $expensive_plan, - [ 'date_expiration' => $expiration ] + ['date_expiration' => $expiration] ); $cart = new Cart( [ 'cart_type' => 'downgrade', 'membership_id' => $membership->get_id(), - 'products' => [ $cheap_plan->get_id() ], + 'products' => [$cheap_plan->get_id()], ] ); @@ -1832,21 +1830,21 @@ public function test_billing_start_date_for_downgrade_cart() { public function test_billing_next_charge_date_for_downgrade_cart() { wp_set_current_user( self::$customer->get_user_id() ); - $expensive_plan = $this->create_plan( [ 'amount' => 100.00 ] ); - $cheap_plan = $this->create_plan( [ 'amount' => 20.00 ] ); + $expensive_plan = $this->create_plan( ['amount' => 100.00] ); + $cheap_plan = $this->create_plan( ['amount' => 20.00] ); $expiration = gmdate( 'Y-m-d 23:59:59', strtotime( '+30 days' ) ); $membership = $this->create_active_membership( $expensive_plan, - [ 'date_expiration' => $expiration ] + ['date_expiration' => $expiration] ); $cart = new Cart( [ 'cart_type' => 'downgrade', 'membership_id' => $membership->get_id(), - 'products' => [ $cheap_plan->get_id() ], + 'products' => [$cheap_plan->get_id()], ] ); @@ -1869,11 +1867,11 @@ public function test_billing_next_charge_date_for_downgrade_cart() { * Test get_proration_credits returns 0 when no fees. */ public function test_get_proration_credits_zero_without_fees() { - $plan = $this->create_plan( [ 'amount' => 50.00 ] ); + $plan = $this->create_plan( ['amount' => 50.00] ); $cart = new Cart( [ - 'products' => [ $plan->get_id() ], + 'products' => [$plan->get_id()], ] ); @@ -1902,7 +1900,7 @@ public function test_add_product_mismatched_duration_adds_error() { // Force cart to use yearly duration — monthly plan has no yearly variation $cart = new Cart( [ - 'products' => [ $monthly_plan->get_id() ], + 'products' => [$monthly_plan->get_id()], 'duration' => 1, 'duration_unit' => 'year', ] @@ -1928,13 +1926,13 @@ public function test_add_product_mismatched_duration_adds_error() { * Test add_product returns false when wu_add_product_line_item filter returns empty. */ public function test_add_product_returns_false_when_line_item_data_empty() { - $plan = $this->create_plan( [ 'amount' => 50.00 ] ); + $plan = $this->create_plan( ['amount' => 50.00] ); add_filter( 'wu_add_product_line_item', '__return_empty_array' ); $cart = new Cart( [ - 'products' => [ $plan->get_id() ], + 'products' => [$plan->get_id()], ] ); @@ -1967,7 +1965,7 @@ public function test_signup_fee_suppressed_by_filter() { $cart = new Cart( [ - 'products' => [ $plan->get_id() ], + 'products' => [$plan->get_id()], ] ); @@ -1992,7 +1990,7 @@ public function test_signup_fee_suppressed_by_filter() { * Test valid discount code applied via constructor reduces total. */ public function test_valid_discount_code_via_constructor_reduces_total() { - $plan = $this->create_plan( [ 'amount' => 100.00 ] ); + $plan = $this->create_plan( ['amount' => 100.00] ); $code = 'VALID' . uniqid(); @@ -2014,7 +2012,7 @@ public function test_valid_discount_code_via_constructor_reduces_total() { $cart = new Cart( [ - 'products' => [ $plan->get_id() ], + 'products' => [$plan->get_id()], 'discount_code' => $code, ] ); @@ -2051,7 +2049,7 @@ public function test_cart_url_includes_duration_greater_than_one() { $cart = new Cart( [ - 'products' => [ $plan->get_id() ], + 'products' => [$plan->get_id()], ] ); @@ -2077,7 +2075,7 @@ public function test_cart_url_includes_non_month_duration_unit() { $cart = new Cart( [ - 'products' => [ $plan->get_id() ], + 'products' => [$plan->get_id()], ] ); @@ -2096,12 +2094,18 @@ public function test_cart_url_includes_additional_product_slugs() { $plan_uid = uniqid( 'main-plan-' ); $service_uid = uniqid( 'extra-svc-' ); - $plan = $this->create_plan( [ 'slug' => $plan_uid, 'amount' => 50.00 ] ); - $service = $this->create_service( [ 'slug' => $service_uid, 'amount' => 10.00 ] ); + $plan = $this->create_plan( [ + 'slug' => $plan_uid, + 'amount' => 50.00, + ] ); + $service = $this->create_service( [ + 'slug' => $service_uid, + 'amount' => 10.00, + ] ); $cart = new Cart( [ - 'products' => [ $plan->get_id(), $service->get_id() ], + 'products' => [$plan->get_id(), $service->get_id()], ] ); @@ -2122,7 +2126,7 @@ public function test_cart_url_includes_additional_product_slugs() { * Test recurring total excludes discount when discount does not apply to renewals. */ public function test_recurring_total_excludes_non_renewal_discount() { - $plan = $this->create_plan( [ 'amount' => 100.00 ] ); + $plan = $this->create_plan( ['amount' => 100.00] ); // Create discount code object directly (no DB lookup needed) $discount_code = new \WP_Ultimo\Models\Discount_Code(); @@ -2134,7 +2138,7 @@ public function test_recurring_total_excludes_non_renewal_discount() { $cart = new Cart( [ - 'products' => [ $plan->get_id() ], + 'products' => [$plan->get_id()], ] ); @@ -2171,7 +2175,7 @@ public function test_calculate_totals_includes_total_fees() { $cart = new Cart( [ - 'products' => [ $plan->get_id() ], + 'products' => [$plan->get_id()], ] ); @@ -2193,7 +2197,7 @@ public function test_calculate_totals_includes_total_fees() { public function test_done_includes_error_details() { $cart = new Cart( [ - 'products' => [ 999999 ], + 'products' => [999999], ] ); @@ -2244,7 +2248,7 @@ public function test_active_yearly_agreement_blocks_monthly_switch() { [ 'cart_type' => 'downgrade', 'membership_id' => $membership->get_id(), - 'products' => [ $monthly_plan->get_id() ], + 'products' => [$monthly_plan->get_id()], 'duration' => 1, 'duration_unit' => 'month', ] @@ -2269,8 +2273,8 @@ public function test_active_yearly_agreement_blocks_monthly_switch() { public function test_reapply_discounts_triggered_for_addon_with_renewal_discount() { wp_set_current_user( self::$customer->get_user_id() ); - $plan = $this->create_plan( [ 'amount' => 50.00 ] ); - $service = $this->create_service( [ 'amount' => 20.00 ] ); + $plan = $this->create_plan( ['amount' => 50.00] ); + $service = $this->create_service( ['amount' => 20.00] ); $code = 'RNWADDON' . uniqid(); @@ -2304,14 +2308,14 @@ public function test_reapply_discounts_triggered_for_addon_with_renewal_discount $existing_meta = []; } // META_DISCOUNT_CODE = 'discount_code' - $existing_meta['discount_code'] = [ $discount ]; + $existing_meta['discount_code'] = [$discount]; wp_cache_set( $membership_id, $existing_meta, 'wu_membership_meta' ); $cart = new Cart( [ 'cart_type' => 'addon', 'membership_id' => $membership->get_id(), - 'products' => [ $service->get_id() ], + 'products' => [$service->get_id()], ] ); @@ -2337,14 +2341,14 @@ public function test_reapply_discounts_triggered_for_addon_with_renewal_discount * Test wu_cart_should_collect_payment filter overrides result. */ public function test_should_collect_payment_filter() { - $plan = $this->create_plan( [ 'amount' => 50.00 ] ); + $plan = $this->create_plan( ['amount' => 50.00] ); // Create cart first, then test the filter on a fresh cart add_filter( 'wu_cart_should_collect_payment', '__return_false' ); $cart = new Cart( [ - 'products' => [ $plan->get_id() ], + 'products' => [$plan->get_id()], ] ); @@ -2376,7 +2380,7 @@ public function test_is_valid_false_for_mismatched_billing_intervals() { $cart = new Cart( [ - 'products' => [ $monthly_plan->get_id() ], + 'products' => [$monthly_plan->get_id()], ] ); @@ -2426,12 +2430,12 @@ public function test_cart_descriptor_empty_cart() { * Test to_membership_data includes addon products. */ public function test_to_membership_data_includes_addon_products() { - $plan = $this->create_plan( [ 'amount' => 50.00 ] ); - $service = $this->create_service( [ 'amount' => 10.00 ] ); + $plan = $this->create_plan( ['amount' => 50.00] ); + $service = $this->create_service( ['amount' => 10.00] ); $cart = new Cart( [ - 'products' => [ $plan->get_id(), $service->get_id() ], + 'products' => [$plan->get_id(), $service->get_id()], ] ); @@ -2522,11 +2526,14 @@ public function test_apply_discounts_to_item_inactive_discount_code() { * Test get_non_recurring_products returns non-recurring products. */ public function test_get_non_recurring_products() { - $service = $this->create_service( [ 'amount' => 10.00, 'recurring' => false ] ); + $service = $this->create_service( [ + 'amount' => 10.00, + 'recurring' => false, + ] ); $cart = new Cart( [ - 'products' => [ $service->get_id() ], + 'products' => [$service->get_id()], ] ); @@ -2545,11 +2552,14 @@ public function test_get_non_recurring_products() { * Test get_recurring_products returns recurring products. */ public function test_get_recurring_products() { - $plan = $this->create_plan( [ 'amount' => 50.00, 'recurring' => true ] ); + $plan = $this->create_plan( [ + 'amount' => 50.00, + 'recurring' => true, + ] ); $cart = new Cart( [ - 'products' => [ $plan->get_id() ], + 'products' => [$plan->get_id()], ] ); @@ -2577,7 +2587,7 @@ public function test_billing_start_date_zero_for_product_without_trial() { $cart = new Cart( [ - 'products' => [ $plan->get_id() ], + 'products' => [$plan->get_id()], ] ); @@ -2630,18 +2640,18 @@ public function test_apply_taxes_to_item_no_tax_category() { * Test wu_cart_product_amount filter modifies product amount. */ public function test_cart_product_amount_filter() { - $plan = $this->create_plan( [ 'amount' => 50.00 ] ); + $plan = $this->create_plan( ['amount' => 50.00] ); add_filter( 'wu_cart_product_amount', - function ( $amount ) { + function ($amount) { return 75.00; // Override to 75 } ); $cart = new Cart( [ - 'products' => [ $plan->get_id() ], + 'products' => [$plan->get_id()], ] ); @@ -2670,14 +2680,14 @@ public function test_cart_product_setup_fee_filter() { add_filter( 'wu_cart_product_setup_fee', - function ( $fee ) { + function ($fee) { return 25.00; // Override to 25 } ); $cart = new Cart( [ - 'products' => [ $plan->get_id() ], + 'products' => [$plan->get_id()], ] ); diff --git a/tests/WP_Ultimo/Checkout/Cart_Test.php b/tests/WP_Ultimo/Checkout/Cart_Test.php index 74af3514a..f2641c00a 100644 --- a/tests/WP_Ultimo/Checkout/Cart_Test.php +++ b/tests/WP_Ultimo/Checkout/Cart_Test.php @@ -658,8 +658,8 @@ public function test_cancel_conflicting_pending_payments() { // Create a new cart with different total $cart = new Cart([ 'cart_type' => 'new', - 'products' => [1], // Assume product exists - 'country' => 'US', + 'products' => [1], // Assume product exists + 'country' => 'US', ]); // The method should cancel the pending payment if totals differ @@ -899,7 +899,10 @@ public function test_total_for_single_recurring_product() { * Test recurring total for a recurring product. */ public function test_recurring_total_for_recurring_product() { - $product = $this->create_plan(['amount' => 35.00, 'recurring' => true]); + $product = $this->create_plan([ + 'amount' => 35.00, + 'recurring' => true, + ]); $cart = new Cart([ 'products' => [$product->get_id()], @@ -931,7 +934,10 @@ public function test_non_recurring_product_has_zero_recurring_total() { */ public function test_total_with_plan_and_service() { $plan = $this->create_plan(['amount' => 40.00]); - $service = $this->create_service(['amount' => 20.00, 'recurring' => false]); + $service = $this->create_service([ + 'amount' => 20.00, + 'recurring' => false, + ]); $cart = new Cart([ 'products' => [$plan->get_id(), $service->get_id()], @@ -949,12 +955,12 @@ public function test_cart_total_never_negative() { // Manually add a credit line item to try to make total negative $credit = new Line_Item([ - 'type' => 'credit', - 'title' => 'Big Credit', - 'unit_price' => -1000, - 'quantity' => 1, + 'type' => 'credit', + 'title' => 'Big Credit', + 'unit_price' => -1000, + 'quantity' => 1, 'discountable' => false, - 'taxable' => false, + 'taxable' => false, ]); $cart->add_line_item($credit); @@ -2099,7 +2105,10 @@ public function test_discount_applied_to_renewals() { * Test get_total_fees returns zero when no fees. */ public function test_get_total_fees_zero_without_fees() { - $plan = $this->create_plan(['amount' => 50.00, 'setup_fee' => 0]); + $plan = $this->create_plan([ + 'amount' => 50.00, + 'setup_fee' => 0, + ]); $cart = new Cart([ 'products' => [$plan->get_id()], @@ -2342,8 +2351,14 @@ public function test_apply_taxes_to_non_taxable_item() { */ public function test_multiple_product_totals() { $plan = $this->create_plan(['amount' => 50.00]); - $service1 = $this->create_service(['amount' => 10.00, 'recurring' => false]); - $service2 = $this->create_service(['amount' => 5.00, 'recurring' => false]); + $service1 = $this->create_service([ + 'amount' => 10.00, + 'recurring' => false, + ]); + $service2 = $this->create_service([ + 'amount' => 5.00, + 'recurring' => false, + ]); $cart = new Cart([ 'products' => [$plan->get_id(), $service1->get_id(), $service2->get_id()], @@ -2362,7 +2377,10 @@ public function test_multiple_product_totals() { * Test that all returned line items are Line_Item instances. */ public function test_line_items_are_correct_instances() { - $plan = $this->create_plan(['amount' => 50.00, 'setup_fee' => 10.00]); + $plan = $this->create_plan([ + 'amount' => 50.00, + 'setup_fee' => 10.00, + ]); $cart = new Cart([ 'products' => [$plan->get_id()], @@ -2384,7 +2402,10 @@ public function test_line_items_are_correct_instances() { * Test get_recurring_products returns recurring products. */ public function test_get_recurring_products() { - $plan = $this->create_plan(['amount' => 50.00, 'recurring' => true]); + $plan = $this->create_plan([ + 'amount' => 50.00, + 'recurring' => true, + ]); $cart = new Cart([ 'products' => [$plan->get_id()], @@ -2655,14 +2676,14 @@ private function create_cancelled_membership($overrides = []) { ); $defaults = [ - 'customer_id' => self::$customer->get_id(), - 'plan_id' => $plan->get_id(), - 'status' => 'cancelled', - 'amount' => 50.00, - 'recurring' => true, - 'duration' => 1, - 'duration_unit' => 'month', - 'date_cancellation' => wu_get_current_time('mysql'), + 'customer_id' => self::$customer->get_id(), + 'plan_id' => $plan->get_id(), + 'status' => 'cancelled', + 'amount' => 50.00, + 'recurring' => true, + 'duration' => 1, + 'duration_unit' => 'month', + 'date_cancellation' => wu_get_current_time('mysql'), ]; return wu_create_membership(array_merge($defaults, $overrides)); @@ -2675,8 +2696,8 @@ private function create_cancelled_membership($overrides = []) { * override the default 'upgrade' cart_type to 'reactivation'. */ public function test_reactivation_cart_type_set_for_cancelled_membership() { - $customer = self::$customer; - $membership = $this->create_cancelled_membership(); + $customer = self::$customer; + $membership = $this->create_cancelled_membership(); wp_set_current_user($customer->get_user_id(), $customer->get_username()); diff --git a/tests/WP_Ultimo/Checkout/Checkout_Test.php b/tests/WP_Ultimo/Checkout/Checkout_Test.php index 1a0cf5e1a..ab99ec76e 100644 --- a/tests/WP_Ultimo/Checkout/Checkout_Test.php +++ b/tests/WP_Ultimo/Checkout/Checkout_Test.php @@ -1829,7 +1829,12 @@ public function test_get_js_validation_rules_excludes_server_only(): void { public function test_get_js_validation_rules_is_filterable(): void { add_filter('wu_checkout_js_validation_rules', function ($rules) { - $rules['custom_js_field'] = [['rule' => 'required', 'param' => null]]; + $rules['custom_js_field'] = [ + [ + 'rule' => 'required', + 'param' => null, + ], + ]; return $rules; }); @@ -1983,9 +1988,9 @@ public function test_should_collect_payment_with_products_in_request(): void { */ public function test_setup_checkout_sets_already_setup_flag(): void { - $checkout = Checkout::get_instance(); - $reflection = new \ReflectionClass($checkout); - $setup_prop = $reflection->getProperty('already_setup'); + $checkout = Checkout::get_instance(); + $reflection = new \ReflectionClass($checkout); + $setup_prop = $reflection->getProperty('already_setup'); if (PHP_VERSION_ID < 80100) { $setup_prop->setAccessible(true); @@ -2034,10 +2039,10 @@ public function test_setup_checkout_is_idempotent(): void { */ public function test_setup_checkout_initialises_session(): void { - $checkout = Checkout::get_instance(); - $reflection = new \ReflectionClass($checkout); - $session_prop = $this->get_session_prop($reflection); - $setup_prop = $reflection->getProperty('already_setup'); + $checkout = Checkout::get_instance(); + $reflection = new \ReflectionClass($checkout); + $session_prop = $this->get_session_prop($reflection); + $setup_prop = $reflection->getProperty('already_setup'); if (PHP_VERSION_ID < 80100) { $setup_prop->setAccessible(true); @@ -2072,9 +2077,9 @@ public function test_setup_checkout_with_pre_flight(): void { $setup_prop->setValue($checkout, false); - $_REQUEST['pre-flight'] = '1'; - $_REQUEST['checkout_form'] = 'some-form'; - $_REQUEST['some_field'] = 'some_value'; + $_REQUEST['pre-flight'] = '1'; + $_REQUEST['checkout_form'] = 'some-form'; + $_REQUEST['some_field'] = 'some_value'; $checkout->setup_checkout(); @@ -2841,7 +2846,10 @@ public function test_get_validation_rules_adds_required_for_required_fields(): v $checkout = Checkout::get_instance(); $checkout->step = [ 'fields' => [ - ['id' => 'custom_required_field', 'required' => true], + [ + 'id' => 'custom_required_field', + 'required' => true, + ], ], ]; $checkout->steps = []; @@ -4925,7 +4933,10 @@ public function test_get_validation_rules_maps_template_selection_required_to_te $checkout = Checkout::get_instance(); $checkout->step = [ 'fields' => [ - ['id' => 'template_selection', 'required' => true], + [ + 'id' => 'template_selection', + 'required' => true, + ], ], ]; $checkout->steps = []; @@ -4954,7 +4965,10 @@ public function test_get_validation_rules_adds_min_1_to_template_id(): void { $checkout = Checkout::get_instance(); $checkout->step = [ 'fields' => [ - ['id' => 'template_selection', 'required' => true], + [ + 'id' => 'template_selection', + 'required' => true, + ], ], ]; $checkout->steps = []; @@ -4978,7 +4992,10 @@ public function test_validate_rejects_template_id_zero_when_required(): void { $checkout = Checkout::get_instance(); $checkout->step = [ 'fields' => [ - ['id' => 'template_selection', 'required' => true], + [ + 'id' => 'template_selection', + 'required' => true, + ], ], ]; $checkout->steps = []; @@ -5034,7 +5051,10 @@ public function test_get_validation_rules_no_min_1_without_template_selection_fi $checkout = Checkout::get_instance(); $checkout->step = [ 'fields' => [ - ['id' => 'email_address', 'required' => true], + [ + 'id' => 'email_address', + 'required' => true, + ], ], ]; $checkout->steps = []; @@ -5085,7 +5105,10 @@ public function test_get_validation_rules_non_template_required_field_maps_to_it $checkout = Checkout::get_instance(); $checkout->step = [ 'fields' => [ - ['id' => 'site_title', 'required' => true], + [ + 'id' => 'site_title', + 'required' => true, + ], ], ]; $checkout->steps = []; @@ -5167,8 +5190,8 @@ public function test_login_customer_after_checkout_noop_when_logged_in(): void { */ public function test_login_customer_after_checkout_no_password_fires_wp_login(): void { - $unique = uniqid('nopw_', true); - $user_id = self::factory()->user->create([ + $unique = uniqid('nopw_', true); + $user_id = self::factory()->user->create([ 'user_login' => $unique, 'user_pass' => wp_generate_password(), 'user_email' => $unique . '@example.com', @@ -5200,7 +5223,7 @@ public function test_login_customer_after_checkout_no_password_fires_wp_login(): $login_fired = false; $login_user_arg = null; - add_action('wp_login', function($user_login, $user) use (&$login_fired, &$login_user_arg) { + add_action('wp_login', function ($user_login, $user) use (&$login_fired, &$login_user_arg) { $login_fired = true; $login_user_arg = $user; }, 10, 2); @@ -5387,7 +5410,7 @@ public function test_login_customer_after_checkout_missing_wp_user_is_safe(): vo unset($_REQUEST['password']); $login_fired = false; - add_action('wp_login', function() use (&$login_fired) { + add_action('wp_login', function () use (&$login_fired) { $login_fired = true; }); diff --git a/tests/WP_Ultimo/Checkout/Line_Item_Test.php b/tests/WP_Ultimo/Checkout/Line_Item_Test.php index bb1d1beef..e9c358d69 100644 --- a/tests/WP_Ultimo/Checkout/Line_Item_Test.php +++ b/tests/WP_Ultimo/Checkout/Line_Item_Test.php @@ -43,7 +43,10 @@ public function test_constructor_sets_attributes(): void { */ public function test_constructor_generates_id(): void { - $line_item = $this->create_line_item(['hash' => 'abc123', 'type' => 'fee']); + $line_item = $this->create_line_item([ + 'hash' => 'abc123', + 'type' => 'fee', + ]); $id = $line_item->get_id(); diff --git a/tests/WP_Ultimo/Checkout/Signup_Fields/Base_Signup_Field_Test.php b/tests/WP_Ultimo/Checkout/Signup_Fields/Base_Signup_Field_Test.php index c9b1ad0be..65a2ea421 100644 --- a/tests/WP_Ultimo/Checkout/Signup_Fields/Base_Signup_Field_Test.php +++ b/tests/WP_Ultimo/Checkout/Signup_Fields/Base_Signup_Field_Test.php @@ -290,7 +290,10 @@ public function test_defaults_returns_empty_array() { * Test reduce_attributes is a passthrough. */ public function test_reduce_attributes_is_passthrough() { - $input = ['foo' => 'bar', 'baz' => 123]; + $input = [ + 'foo' => 'bar', + 'baz' => 123, + ]; $this->assertSame($input, $this->field->reduce_attributes($input)); } @@ -298,7 +301,10 @@ public function test_reduce_attributes_is_passthrough() { * Test get_editor_fields_html_attr is a passthrough. */ public function test_get_editor_fields_html_attr_is_passthrough() { - $html_attr = ['class' => 'my-class', 'data-foo' => 'bar']; + $html_attr = [ + 'class' => 'my-class', + 'data-foo' => 'bar', + ]; $result = $this->field->get_editor_fields_html_attr($html_attr, 'text'); $this->assertSame($html_attr, $result); } @@ -321,7 +327,10 @@ public function test_get_tabs_returns_content_and_style() { * Test set_attributes stores the attributes array. */ public function test_set_attributes_stores_attributes() { - $attrs = ['id' => 'my_field', 'name' => 'My Field']; + $attrs = [ + 'id' => 'my_field', + 'name' => 'My Field', + ]; $this->field->set_attributes($attrs); $reflection = new \ReflectionClass($this->field); @@ -589,8 +598,8 @@ public function test_fields_list_required_field_is_toggle() { * Test fields_list save_as field has expected options. */ public function test_fields_list_save_as_has_options() { - $fields = Base_Signup_Field::fields_list(); - $save_as = $fields['save_as']; + $fields = Base_Signup_Field::fields_list(); + $save_as = $fields['save_as']; $this->assertEquals('select', $save_as['type']); $this->assertArrayHasKey('options', $save_as); @@ -649,8 +658,8 @@ public function test_get_editor_fields_wrapper_has_v_cloak_and_v_show() { * Test get_editor_fields v-show contains the field type. */ public function test_get_editor_fields_v_show_contains_field_type() { - $fields = $this->field->get_editor_fields([]); - $v_show = $fields['test_option']['wrapper_html_attr']['v-show']; + $fields = $this->field->get_editor_fields([]); + $v_show = $fields['test_option']['wrapper_html_attr']['v-show']; $this->assertStringContainsString('test_field', $v_show); } diff --git a/tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Period_Selection_Test.php b/tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Period_Selection_Test.php index 16c283dcb..afa66416d 100644 --- a/tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Period_Selection_Test.php +++ b/tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Period_Selection_Test.php @@ -296,8 +296,8 @@ public function test_get_fields_template_group_has_fields(): void { * Test period_selection_template nested field is a select. */ public function test_get_fields_template_nested_select(): void { - $fields = $this->field->get_fields(); - $nested = $fields['period_selection_template']['fields']; + $fields = $this->field->get_fields(); + $nested = $fields['period_selection_template']['fields']; $this->assertArrayHasKey('period_selection_template', $nested); $this->assertEquals('select', $nested['period_selection_template']['type']); } @@ -354,7 +354,7 @@ public function test_get_fields_period_options_is_group(): void { * Test period_options group has nested fields. */ public function test_get_fields_period_options_has_nested_fields(): void { - $fields = $this->field->get_fields(); + $fields = $this->field->get_fields(); $this->assertArrayHasKey('fields', $fields['period_options']); $nested = $fields['period_options']['fields']; $this->assertArrayHasKey('period_options_remove', $nested); @@ -385,9 +385,9 @@ public function test_get_fields_duration_unit_is_select(): void { * Test period_options_duration_unit options contain expected keys. */ public function test_get_fields_duration_unit_options(): void { - $fields = $this->field->get_fields(); - $nested = $fields['period_options']['fields']; - $options = $nested['period_options_duration_unit']['options']; + $fields = $this->field->get_fields(); + $nested = $fields['period_options']['fields']; + $options = $nested['period_options_duration_unit']['options']; $this->assertArrayHasKey('day', $options); $this->assertArrayHasKey('week', $options); $this->assertArrayHasKey('month', $options); @@ -431,7 +431,7 @@ public function test_get_fields_order_values(): void { * * @return array */ - private function make_attributes( string $template = 'clean' ): array { + private function make_attributes(string $template = 'clean'): array { return [ 'id' => 'period_selection', 'element_classes' => 'wu-period-selection', @@ -681,7 +681,10 @@ public function test_get_all_attributes_includes_template_key(): void { * Test set_attributes stores the attributes. */ public function test_set_attributes(): void { - $data = ['id' => 'period_selection', 'width' => 50]; + $data = [ + 'id' => 'period_selection', + 'width' => 50, + ]; $this->field->set_attributes($data); $reflection = new \ReflectionClass($this->field); @@ -734,7 +737,10 @@ public function test_calculate_style_attr_no_width(): void { * Test reduce_attributes returns the same array unchanged. */ public function test_reduce_attributes(): void { - $data = ['foo' => 'bar', 'baz' => 123]; + $data = [ + 'foo' => 'bar', + 'baz' => 123, + ]; $result = $this->field->reduce_attributes($data); $this->assertEquals($data, $result); } diff --git a/tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Select_Test.php b/tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Select_Test.php index f56fcc22d..b5b9fc5b6 100644 --- a/tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Select_Test.php +++ b/tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Select_Test.php @@ -134,9 +134,18 @@ public function test_to_fields_array(): void { 'required' => true, 'element_classes' => 'select-class', 'options' => [ - ['key' => 'us', 'label' => 'United States'], - ['key' => 'uk', 'label' => 'United Kingdom'], - ['key' => 'ca', 'label' => 'Canada'], + [ + 'key' => 'us', + 'label' => 'United States', + ], + [ + 'key' => 'uk', + 'label' => 'United Kingdom', + ], + [ + 'key' => 'ca', + 'label' => 'Canada', + ], ], ]; diff --git a/tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Template_Selection_Test.php b/tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Template_Selection_Test.php index cc86e421a..083020d84 100644 --- a/tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Template_Selection_Test.php +++ b/tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Template_Selection_Test.php @@ -271,7 +271,7 @@ public function test_get_fields_has_template_selection_type(): void { * Test template_selection_type field has expected options. */ public function test_get_fields_template_selection_type_options(): void { - $fields = $this->field->get_fields(); + $fields = $this->field->get_fields(); $options = $fields['template_selection_type']['options']; $this->assertArrayHasKey('name', $options); $this->assertArrayHasKey('categories', $options); @@ -344,9 +344,18 @@ public function test_get_fields_sites_data_model(): void { public function test_reduce_attributes_extracts_blog_ids(): void { $attributes = [ 'sites' => [ - ['blog_id' => 1, 'title' => 'Site One'], - ['blog_id' => 2, 'title' => 'Site Two'], - ['blog_id' => 3, 'title' => 'Site Three'], + [ + 'blog_id' => 1, + 'title' => 'Site One', + ], + [ + 'blog_id' => 2, + 'title' => 'Site Two', + ], + [ + 'blog_id' => 3, + 'title' => 'Site Three', + ], ], ]; @@ -365,8 +374,14 @@ public function test_reduce_attributes_extracts_blog_ids(): void { public function test_reduce_attributes_returns_sequential_array(): void { $attributes = [ 'sites' => [ - ['blog_id' => 5, 'title' => 'Site Five'], - ['blog_id' => 10, 'title' => 'Site Ten'], + [ + 'blog_id' => 5, + 'title' => 'Site Five', + ], + [ + 'blog_id' => 10, + 'title' => 'Site Ten', + ], ], ]; @@ -396,7 +411,12 @@ public function test_reduce_attributes_with_empty_sites(): void { */ public function test_reduce_attributes_preserves_other_keys(): void { $attributes = [ - 'sites' => [['blog_id' => 1, 'title' => 'Site']], + 'sites' => [ + [ + 'blog_id' => 1, + 'title' => 'Site', + ], + ], 'some_key' => 'some_value', ]; @@ -514,15 +534,15 @@ public function test_site_list_unknown_type_falls_back_to_name(): void { private function make_attributes(array $overrides = []): array { return array_merge( [ - 'id' => 'template_selection', - 'type' => 'template_selection', - 'name' => 'Template Selection', - 'element_classes' => '', - 'cols' => 3, - 'template_selection_type' => 'name', - 'template_selection_sites' => '', - 'template_selection_template' => 'clean', - 'template_selection_categories' => [], + 'id' => 'template_selection', + 'type' => 'template_selection', + 'name' => 'Template Selection', + 'element_classes' => '', + 'cols' => 3, + 'template_selection_type' => 'name', + 'template_selection_sites' => '', + 'template_selection_template' => 'clean', + 'template_selection_categories' => [], 'hide_template_selection_when_pre_selected' => false, ], $overrides diff --git a/tests/WP_Ultimo/Dashboard_Statistics_Test.php b/tests/WP_Ultimo/Dashboard_Statistics_Test.php index 64db9d97c..03dd1c117 100644 --- a/tests/WP_Ultimo/Dashboard_Statistics_Test.php +++ b/tests/WP_Ultimo/Dashboard_Statistics_Test.php @@ -36,7 +36,7 @@ public function test_constructor_sets_properties() { [ 'start_date' => '2025-01-01', 'end_date' => '2025-12-31', - 'types' => [ 'mrr_growth' ], + 'types' => ['mrr_growth'], ] ); @@ -52,7 +52,7 @@ public function test_constructor_sets_properties() { $this->assertEquals('2025-01-01', $ref_start->getValue($stats)); $this->assertEquals('2025-12-31', $ref_end->getValue($stats)); - $this->assertEquals([ 'mrr_growth' ], $ref_types->getValue($stats)); + $this->assertEquals(['mrr_growth'], $ref_types->getValue($stats)); } // ------------------------------------------------------------------ @@ -67,7 +67,7 @@ public function test_statistics_data_calls_type_methods() { [ 'start_date' => '2025-01-01', 'end_date' => '2025-12-31', - 'types' => [ 'mrr_growth' => 'mrr_growth' ], + 'types' => ['mrr_growth' => 'mrr_growth'], ] ); diff --git a/tests/WP_Ultimo/Dashboard_Widgets_Test.php b/tests/WP_Ultimo/Dashboard_Widgets_Test.php index d61dda54f..6fd1cb6eb 100644 --- a/tests/WP_Ultimo/Dashboard_Widgets_Test.php +++ b/tests/WP_Ultimo/Dashboard_Widgets_Test.php @@ -87,9 +87,9 @@ public function test_enqueue_scripts_skips_non_index_page(): void { global $pagenow, $wp_scripts; - $original = $pagenow; - $original_queue = isset( $wp_scripts ) ? $wp_scripts->queue : []; - $pagenow = 'options.php'; + $original = $pagenow; + $original_queue = isset( $wp_scripts ) ? $wp_scripts->queue : []; + $pagenow = 'options.php'; // Reset the script queue so that wu-vue dependents enqueued by prior // tests do not cause wp_script_is() to return true via recurse_deps(). @@ -156,7 +156,6 @@ public function test_enqueue_scripts_enqueues_activity_stream_on_index(): void { $this->assertNotNull($script, 'wu-activity-stream should be registered'); $this->assertContains('wu-functions', $script->deps); $this->assertContains('moment', $script->deps); - } finally { if (isset($wp_scripts)) { $wp_scripts->queue = $original_queue; @@ -205,7 +204,6 @@ public function test_enqueue_scripts_skips_activity_stream_on_per_site_dashboard wp_script_is('wu-activity-stream', 'enqueued'), 'wu-activity-stream should NOT be enqueued on the per-site dashboard' ); - } finally { if (isset($wp_scripts)) { $wp_scripts->queue = $original_queue; diff --git a/tests/WP_Ultimo/Domain_Mapping/Helper_Test.php b/tests/WP_Ultimo/Domain_Mapping/Helper_Test.php index 7538fed32..aee6972ef 100644 --- a/tests/WP_Ultimo/Domain_Mapping/Helper_Test.php +++ b/tests/WP_Ultimo/Domain_Mapping/Helper_Test.php @@ -116,7 +116,7 @@ public function test_has_valid_ssl_certificate_invalid() { */ public function test_constructor_is_private() { - $ref = new \ReflectionClass(Helper::class); + $ref = new \ReflectionClass(Helper::class); $constructor = $ref->getConstructor(); $this->assertTrue($constructor->isPrivate()); diff --git a/tests/WP_Ultimo/Domain_Mapping/SSO_Test.php b/tests/WP_Ultimo/Domain_Mapping/SSO_Test.php index b7cb8e84a..cb188ba6a 100644 --- a/tests/WP_Ultimo/Domain_Mapping/SSO_Test.php +++ b/tests/WP_Ultimo/Domain_Mapping/SSO_Test.php @@ -19,7 +19,7 @@ class SSO_Test extends \WP_UnitTestCase { private function get_instance() { // Create instance directly to bypass Singleton init() - $ref = new \ReflectionClass(SSO::class); + $ref = new \ReflectionClass(SSO::class); $instance = $ref->newInstanceWithoutConstructor(); return $instance; @@ -60,7 +60,7 @@ public function test_get_instance_returns_correct_class() { */ public function test_get_instance_returns_same_instance() { - $first = SSO::get_instance(); + $first = SSO::get_instance(); $second = SSO::get_instance(); $this->assertSame($first, $second); @@ -81,7 +81,7 @@ public function test_class_namespace() { */ public function test_class_is_deprecated() { - $ref = new \ReflectionClass(SSO::class); + $ref = new \ReflectionClass(SSO::class); $docblock = $ref->getDocComment(); $this->assertNotFalse($docblock); @@ -93,7 +93,7 @@ public function test_class_is_deprecated() { */ public function test_file_references_new_location() { - $file_path = dirname(__DIR__, 3) . '/inc/domain-mapping/class-sso.php'; + $file_path = dirname(__DIR__, 3) . '/inc/domain-mapping/class-sso.php'; $file_contents = file_get_contents($file_path); $this->assertNotFalse($file_contents); @@ -115,7 +115,7 @@ public function test_can_instantiate_without_errors() { */ public function test_has_only_singleton_public_methods() { - $ref = new \ReflectionClass(SSO::class); + $ref = new \ReflectionClass(SSO::class); $methods = $ref->getMethods(\ReflectionMethod::IS_PUBLIC); $method_names = array_map(function ($method) { @@ -131,7 +131,7 @@ public function test_has_only_singleton_public_methods() { // Filter out Singleton methods $non_singleton_methods = array_filter($method_names, function ($name) { - return !in_array($name, ['get_instance', 'init', 'has_parents']); + return ! in_array($name, ['get_instance', 'init', 'has_parents']); }); $this->assertEmpty($non_singleton_methods, 'SSO should have no public methods beyond Singleton trait'); diff --git a/tests/WP_Ultimo/Duplication/MUCD_Data_Test.php b/tests/WP_Ultimo/Duplication/MUCD_Data_Test.php index 25a773059..3cbfcab74 100644 --- a/tests/WP_Ultimo/Duplication/MUCD_Data_Test.php +++ b/tests/WP_Ultimo/Duplication/MUCD_Data_Test.php @@ -182,7 +182,7 @@ public function test_try_replace_elementor_json_data() { [ 'elType' => 'widget', 'settings' => [ - 'link' => [ + 'link' => [ 'url' => 'https://example.com/old-site/services', ], 'button_link' => [ @@ -367,8 +367,8 @@ static function ($errno, $errstr) use (&$warnings) { public function test_try_replace_does_not_instantiate_known_class_objects() { // stdClass is always available; without allowed_classes: false it would // be instantiated and processed by the object-mutation branch. - $obj = new \stdClass(); - $obj->url = 'https://example.com/old/page'; + $obj = new \stdClass(); + $obj->url = 'https://example.com/old/page'; $serialized = serialize($obj); $row = ['meta_value' => $serialized]; @@ -381,14 +381,13 @@ public function test_try_replace_does_not_instantiate_known_class_objects() { /** * Test try_replace with Elementor Kit-like serialized page settings. - * * After URL replacement, all non-URL settings must be preserved * exactly and the result must be valid serialized data. */ public function test_try_replace_elementor_kit_page_settings() { $kit_settings = [ - 'system_colors' => [ + 'system_colors' => [ [ '_id' => 'primary', 'color' => '#6EC1E4', @@ -410,28 +409,28 @@ public function test_try_replace_elementor_kit_page_settings() { 'title' => 'Accent', ], ], - 'system_typography' => [ + 'system_typography' => [ [ - '_id' => 'primary', - 'typography_font_family' => 'Roboto', - 'typography_font_weight' => '600', - 'typography_typography' => 'custom', + '_id' => 'primary', + 'typography_font_family' => 'Roboto', + 'typography_font_weight' => '600', + 'typography_typography' => 'custom', ], [ - '_id' => 'secondary', - 'typography_font_family' => 'Roboto Slab', - 'typography_font_weight' => '400', - 'typography_typography' => 'custom', + '_id' => 'secondary', + 'typography_font_family' => 'Roboto Slab', + 'typography_font_weight' => '400', + 'typography_typography' => 'custom', ], ], - 'custom_colors' => [ + 'custom_colors' => [ [ '_id' => 'brand_dark', 'color' => '#1A1A2E', 'title' => 'Brand Dark', ], ], - 'container_width' => [ + 'container_width' => [ 'size' => 1140, 'unit' => 'px', ], @@ -439,17 +438,17 @@ public function test_try_replace_elementor_kit_page_settings() { 'size' => 20, 'unit' => 'px', ], - 'page_title_selector' => 'h1.entry-title', - 'active_breakpoints' => [ + 'page_title_selector' => 'h1.entry-title', + 'active_breakpoints' => [ 'viewport_mobile', 'viewport_tablet', ], - 'custom_css' => 'body { font-family: "Roboto", sans-serif; } .site-logo img { max-height: 60px; } .hero-section { background-image: url(https://plantilla2.example.com/wp-content/uploads/sites/97/hero-bg.jpg); }', - 'site_logo' => [ + 'custom_css' => 'body { font-family: "Roboto", sans-serif; } .site-logo img { max-height: 60px; } .hero-section { background-image: url(https://plantilla2.example.com/wp-content/uploads/sites/97/hero-bg.jpg); }', + 'site_logo' => [ 'url' => 'https://plantilla2.example.com/wp-content/uploads/sites/97/logo.png', 'id' => 42, ], - 'site_favicon' => [ + 'site_favicon' => [ 'url' => 'https://plantilla2.example.com/wp-content/uploads/sites/97/favicon.png', 'id' => 43, ], @@ -518,7 +517,7 @@ public function test_try_replace_multiple_passes_preserve_data() { 'old.example.com/wp-content/uploads/sites/97', 'new.example.com/wp-content/uploads/sites/200' ); - $row = ['meta_value' => $result]; + $row = ['meta_value' => $result]; // Pass 2: Blog URL $result = \MUCD_Data::try_replace( @@ -527,7 +526,7 @@ public function test_try_replace_multiple_passes_preserve_data() { 'old.example.com', 'new.example.com' ); - $row = ['meta_value' => $result]; + $row = ['meta_value' => $result]; // Pass 3: Prefix $result = \MUCD_Data::try_replace( @@ -820,76 +819,130 @@ public function test_update_preserves_elementor_kit_byte_count() { // This mirrors the structure found in a typical Elementor-powered template // site and triggers the full range of replacement passes. $kit_settings = [ - 'system_colors' => [ - ['_id' => 'primary', 'title' => 'Primary', 'color' => '#6EC1E4'], - ['_id' => 'secondary', 'title' => 'Secondary', 'color' => '#54595F'], - ['_id' => 'text', 'title' => 'Text', 'color' => '#7A7A7A'], - ['_id' => 'accent', 'title' => 'Accent', 'color' => '#61CE70'], + 'system_colors' => [ + [ + '_id' => 'primary', + 'title' => 'Primary', + 'color' => '#6EC1E4', + ], + [ + '_id' => 'secondary', + 'title' => 'Secondary', + 'color' => '#54595F', + ], + [ + '_id' => 'text', + 'title' => 'Text', + 'color' => '#7A7A7A', + ], + [ + '_id' => 'accent', + 'title' => 'Accent', + 'color' => '#61CE70', + ], ], - 'custom_colors' => [ - ['_id' => 'brand_dark', 'title' => 'Brand Dark', 'color' => '#1A1A2E'], - ['_id' => 'brand_light', 'title' => 'Brand Light', 'color' => '#E8E8F0'], + 'custom_colors' => [ + [ + '_id' => 'brand_dark', + 'title' => 'Brand Dark', + 'color' => '#1A1A2E', + ], + [ + '_id' => 'brand_light', + 'title' => 'Brand Light', + 'color' => '#E8E8F0', + ], ], - 'system_typography' => [ + 'system_typography' => [ [ '_id' => 'primary', 'title' => 'Primary', - 'typography_typography' => 'custom', - 'typography_font_family' => 'Roboto', - 'typography_font_weight' => '600', - 'typography_font_size' => ['unit' => 'px', 'size' => 16], - 'typography_line_height' => ['unit' => 'em', 'size' => 1.5], + 'typography_typography' => 'custom', + 'typography_font_family' => 'Roboto', + 'typography_font_weight' => '600', + 'typography_font_size' => [ + 'unit' => 'px', + 'size' => 16, + ], + 'typography_line_height' => [ + 'unit' => 'em', + 'size' => 1.5, + ], ], [ '_id' => 'secondary', 'title' => 'Secondary', - 'typography_typography' => 'custom', - 'typography_font_family' => 'Roboto Slab', - 'typography_font_weight' => '400', - 'typography_font_size' => ['unit' => 'px', 'size' => 14], - 'typography_line_height' => ['unit' => 'em', 'size' => 1.6], + 'typography_typography' => 'custom', + 'typography_font_family' => 'Roboto Slab', + 'typography_font_weight' => '400', + 'typography_font_size' => [ + 'unit' => 'px', + 'size' => 14, + ], + 'typography_line_height' => [ + 'unit' => 'em', + 'size' => 1.6, + ], ], [ '_id' => 'text', 'title' => 'Text', - 'typography_typography' => 'custom', - 'typography_font_family' => 'Open Sans', - 'typography_font_weight' => '400', - 'typography_font_size' => ['unit' => 'px', 'size' => 15], - 'typography_line_height' => ['unit' => 'em', 'size' => 1.7], + 'typography_typography' => 'custom', + 'typography_font_family' => 'Open Sans', + 'typography_font_weight' => '400', + 'typography_font_size' => [ + 'unit' => 'px', + 'size' => 15, + ], + 'typography_line_height' => [ + 'unit' => 'em', + 'size' => 1.7, + ], ], [ '_id' => 'accent', 'title' => 'Accent', - 'typography_typography' => 'custom', - 'typography_font_family' => 'Montserrat', - 'typography_font_weight' => '700', - 'typography_font_size' => ['unit' => 'px', 'size' => 13], - 'typography_line_height' => ['unit' => 'em', 'size' => 1.4], + 'typography_typography' => 'custom', + 'typography_font_family' => 'Montserrat', + 'typography_font_weight' => '700', + 'typography_font_size' => [ + 'unit' => 'px', + 'size' => 13, + ], + 'typography_line_height' => [ + 'unit' => 'em', + 'size' => 1.4, + ], ], ], - 'custom_typography' => [ + 'custom_typography' => [ [ '_id' => 'heading_brand', 'title' => 'Heading Brand', - 'typography_typography' => 'custom', - 'typography_font_family' => 'Playfair Display', - 'typography_font_weight' => '700', + 'typography_typography' => 'custom', + 'typography_font_family' => 'Playfair Display', + 'typography_font_weight' => '700', ], ], - 'container_width' => ['size' => 1140, 'unit' => 'px'], - 'space_between_widgets' => ['size' => 20, 'unit' => 'px'], - 'page_title_selector' => 'h1.entry-title', - 'active_breakpoints' => ['viewport_mobile', 'viewport_tablet'], - 'site_logo' => [ + 'container_width' => [ + 'size' => 1140, + 'unit' => 'px', + ], + 'space_between_widgets' => [ + 'size' => 20, + 'unit' => 'px', + ], + 'page_title_selector' => 'h1.entry-title', + 'active_breakpoints' => ['viewport_mobile', 'viewport_tablet'], + 'site_logo' => [ 'id' => 42, 'url' => 'https://' . $origin_upload_base . '/2024/01/logo.png', ], - 'site_favicon' => [ + 'site_favicon' => [ 'id' => 43, 'url' => 'https://' . $origin_upload_base . '/2024/01/favicon.png', ], - 'custom_css' => implode("\n", [ + 'custom_css' => implode("\n", [ '/* Brand styles — ' . $origin_site_url . ' */', 'body { font-family: "Roboto", sans-serif; color: #7A7A7A; }', 'h1, h2, h3 { color: #1A1A2E; font-family: "Playfair Display", serif; }', @@ -901,8 +954,14 @@ public function test_update_preserves_elementor_kit_byte_count() { '.cta-button:hover { background-color: #54595F; }', ]), '_elementor_page_assets' => [ - 'fonts' => ['Roboto' => 1, 'Roboto Slab' => 1, 'Open Sans' => 1, 'Montserrat' => 1, 'Playfair Display' => 1], - 'icons' => [], + 'fonts' => [ + 'Roboto' => 1, + 'Roboto Slab' => 1, + 'Open Sans' => 1, + 'Montserrat' => 1, + 'Playfair Display' => 1, + ], + 'icons' => [], ], ]; @@ -910,7 +969,10 @@ public function test_update_preserves_elementor_kit_byte_count() { $raw_value = serialize($kit_settings); $original_bytes = strlen($raw_value); - $post_id = self::factory()->post->create(['post_title' => 'Elementor Kit', 'post_status' => 'publish']); + $post_id = self::factory()->post->create([ + 'post_title' => 'Elementor Kit', + 'post_status' => 'publish', + ]); $wpdb->insert( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery $wpdb->postmeta, [ @@ -927,10 +989,10 @@ public function test_update_preserves_elementor_kit_byte_count() { // Simulate all 7 replacement passes that db_update_data() applies. // Pass order mirrors the string_to_replace array in db_update_data(). $passes = [ - $origin_upload_base => $clone_upload_base, + $origin_upload_base => $clone_upload_base, str_replace('/', '\\/', $origin_upload_base) => str_replace('/', '\\/', $clone_upload_base), - $origin_site_url => $clone_site_url, - str_replace('/', '\\/', $origin_site_url) => str_replace('/', '\\/', $clone_site_url), + $origin_site_url => $clone_site_url, + str_replace('/', '\\/', $origin_site_url) => str_replace('/', '\\/', $clone_site_url), ]; foreach ($passes as $from => $to) { @@ -970,10 +1032,10 @@ public function test_update_preserves_elementor_kit_byte_count() { // Typography entries must be fully intact. $this->assertCount(4, $final_data['system_typography'], 'All 4 typography entries must survive'); - $this->assertEquals('Roboto', $final_data['system_typography'][0]['typography_font_family']); - $this->assertEquals('Roboto Slab', $final_data['system_typography'][1]['typography_font_family']); - $this->assertEquals('Open Sans', $final_data['system_typography'][2]['typography_font_family']); - $this->assertEquals('Montserrat', $final_data['system_typography'][3]['typography_font_family']); + $this->assertEquals('Roboto', $final_data['system_typography'][0]['typography_font_family']); + $this->assertEquals('Roboto Slab', $final_data['system_typography'][1]['typography_font_family']); + $this->assertEquals('Open Sans', $final_data['system_typography'][2]['typography_font_family']); + $this->assertEquals('Montserrat', $final_data['system_typography'][3]['typography_font_family']); // Logo and favicon URLs must be rewritten to the clone. $this->assertStringContainsString($clone_upload_base, $final_data['site_logo']['url'], 'Logo URL must point to clone uploads'); diff --git a/tests/WP_Ultimo/Faker_Test.php b/tests/WP_Ultimo/Faker_Test.php index f90d602e8..48b1c3c84 100644 --- a/tests/WP_Ultimo/Faker_Test.php +++ b/tests/WP_Ultimo/Faker_Test.php @@ -139,7 +139,7 @@ public function test_generate_fake_customers_creates_multiple() { public function test_generate_fake_customers_creates_valid_customer_objects() { $this->faker->generate_fake_customers(); - $data = $this->faker->get_fake_data_generated('customers'); + $data = $this->faker->get_fake_data_generated('customers'); $customer = $data[0]; $this->assertInstanceOf(\WP_Ultimo\Models\Customer::class, $customer); @@ -168,7 +168,7 @@ public function test_generate_fake_products_creates_multiple() { public function test_generate_fake_products_creates_valid_product_objects() { $this->faker->generate_fake_products(); - $data = $this->faker->get_fake_data_generated('products'); + $data = $this->faker->get_fake_data_generated('products'); $product = $data[0]; $this->assertInstanceOf(\WP_Ultimo\Models\Product::class, $product); @@ -180,7 +180,7 @@ public function test_generate_fake_products_has_valid_type() { $this->faker->generate_fake_products(5); $valid_types = ['plan', 'package', 'service']; - $data = $this->faker->get_fake_data_generated('products'); + $data = $this->faker->get_fake_data_generated('products'); foreach ($data as $product) { $this->assertContains($product->get_type(), $valid_types); @@ -191,7 +191,7 @@ public function test_generate_fake_products_has_valid_pricing_type() { $this->faker->generate_fake_products(5); $valid_pricing = ['paid', 'free', 'contact_us']; - $data = $this->faker->get_fake_data_generated('products'); + $data = $this->faker->get_fake_data_generated('products'); foreach ($data as $product) { $this->assertContains($product->get_pricing_type(), $valid_pricing); @@ -212,7 +212,7 @@ public function test_generate_fake_memberships_creates_one_by_default() { public function test_generate_fake_memberships_creates_valid_membership_objects() { $this->faker->generate_fake_memberships(); - $data = $this->faker->get_fake_data_generated('memberships'); + $data = $this->faker->get_fake_data_generated('memberships'); $membership = $data[0]; $this->assertInstanceOf(\WP_Ultimo\Models\Membership::class, $membership); @@ -224,7 +224,7 @@ public function test_generate_fake_memberships_auto_creates_customer_and_product // Should have auto-created a customer and product $customers = $this->faker->get_fake_data_generated('customers'); - $products = $this->faker->get_fake_data_generated('products'); + $products = $this->faker->get_fake_data_generated('products'); $this->assertNotEmpty($customers); $this->assertNotEmpty($products); @@ -234,7 +234,7 @@ public function test_generate_fake_memberships_has_valid_status() { $this->faker->generate_fake_memberships(3); $valid_statuses = ['pending', 'active', 'on-hold', 'expired', 'cancelled']; - $data = $this->faker->get_fake_data_generated('memberships'); + $data = $this->faker->get_fake_data_generated('memberships'); foreach ($data as $membership) { $this->assertContains($membership->get_status(), $valid_statuses); @@ -255,7 +255,7 @@ public function test_generate_fake_domain_creates_one_by_default() { public function test_generate_fake_domain_creates_valid_domain_objects() { $this->faker->generate_fake_domain(); - $data = $this->faker->get_fake_data_generated('domains'); + $data = $this->faker->get_fake_data_generated('domains'); $domain = $data[0]; $this->assertInstanceOf(\WP_Ultimo\Models\Domain::class, $domain); @@ -299,7 +299,7 @@ public function test_generate_fake_email_creates_one_by_default() { public function test_generate_fake_email_creates_valid_objects() { $this->faker->generate_fake_email(); - $data = $this->faker->get_fake_data_generated('emails'); + $data = $this->faker->get_fake_data_generated('emails'); $email = $data[0]; $this->assertInstanceOf(\WP_Ultimo\Models\Email::class, $email); @@ -320,7 +320,7 @@ public function test_generate_fake_broadcast_creates_one_by_default() { public function test_generate_fake_broadcast_creates_valid_objects() { $this->faker->generate_fake_broadcast(); - $data = $this->faker->get_fake_data_generated('broadcasts'); + $data = $this->faker->get_fake_data_generated('broadcasts'); $broadcast = $data[0]; $this->assertInstanceOf(\WP_Ultimo\Models\Broadcast::class, $broadcast); @@ -331,7 +331,7 @@ public function test_generate_fake_broadcast_has_valid_notice_type() { $this->faker->generate_fake_broadcast(5); $valid_types = ['info', 'success', 'warning', 'error']; - $data = $this->faker->get_fake_data_generated('broadcasts'); + $data = $this->faker->get_fake_data_generated('broadcasts'); foreach ($data as $broadcast) { $this->assertContains($broadcast->get_notice_type(), $valid_types); @@ -352,7 +352,7 @@ public function test_generate_fake_webhook_creates_one_by_default() { public function test_generate_fake_webhook_creates_valid_objects() { $this->faker->generate_fake_webhook(); - $data = $this->faker->get_fake_data_generated('webhooks'); + $data = $this->faker->get_fake_data_generated('webhooks'); $webhook = $data[0]; $this->assertInstanceOf(\WP_Ultimo\Models\Webhook::class, $webhook); @@ -398,7 +398,7 @@ public function test_generate_fake_payment_creates_valid_objects() { $this->faker->generate_fake_memberships(); $this->faker->generate_fake_payment(); - $data = $this->faker->get_fake_data_generated('payments'); + $data = $this->faker->get_fake_data_generated('payments'); $payment = $data[0]; $this->assertInstanceOf(\WP_Ultimo\Models\Payment::class, $payment); diff --git a/tests/WP_Ultimo/Functions/Array_Helpers_Test.php b/tests/WP_Ultimo/Functions/Array_Helpers_Test.php index 3aa752ed1..1064fe18a 100644 --- a/tests/WP_Ultimo/Functions/Array_Helpers_Test.php +++ b/tests/WP_Ultimo/Functions/Array_Helpers_Test.php @@ -152,8 +152,16 @@ public function test_array_merge_recursive_distinct_no_sum(): void { * Test wu_array_recursive_diff basic diff. */ public function test_array_recursive_diff_basic(): void { - $array1 = ['a' => 1, 'b' => 2, 'c' => 3]; - $array2 = ['a' => 1, 'b' => 2, 'c' => 3]; + $array1 = [ + 'a' => 1, + 'b' => 2, + 'c' => 3, + ]; + $array2 = [ + 'a' => 1, + 'b' => 2, + 'c' => 3, + ]; $result = wu_array_recursive_diff($array1, $array2); @@ -164,8 +172,14 @@ public function test_array_recursive_diff_basic(): void { * Test wu_array_recursive_diff finds differences. */ public function test_array_recursive_diff_finds_differences(): void { - $array1 = ['a' => 1, 'b' => 2]; - $array2 = ['a' => 1, 'b' => 3]; + $array1 = [ + 'a' => 1, + 'b' => 2, + ]; + $array2 = [ + 'a' => 1, + 'b' => 3, + ]; $result = wu_array_recursive_diff($array1, $array2); @@ -177,7 +191,11 @@ public function test_array_recursive_diff_finds_differences(): void { * Test wu_array_recursive_diff with missing keys. */ public function test_array_recursive_diff_missing_keys(): void { - $array1 = ['a' => 1, 'b' => 2, 'c' => 3]; + $array1 = [ + 'a' => 1, + 'b' => 2, + 'c' => 3, + ]; $array2 = ['a' => 1]; $result = wu_array_recursive_diff($array1, $array2); @@ -190,8 +208,18 @@ public function test_array_recursive_diff_missing_keys(): void { * Test wu_array_recursive_diff with nested arrays. */ public function test_array_recursive_diff_nested(): void { - $array1 = ['nested' => ['a' => 1, 'b' => 2]]; - $array2 = ['nested' => ['a' => 1, 'b' => 3]]; + $array1 = [ + 'nested' => [ + 'a' => 1, + 'b' => 2, + ], + ]; + $array2 = [ + 'nested' => [ + 'a' => 1, + 'b' => 3, + ], + ]; $result = wu_array_recursive_diff($array1, $array2); @@ -261,9 +289,18 @@ public function test_key_map_to_array_empty(): void { */ public function test_array_find_first_by(): void { $array = [ - ['id' => 1, 'name' => 'Alice'], - ['id' => 2, 'name' => 'Bob'], - ['id' => 3, 'name' => 'Alice'], + [ + 'id' => 1, + 'name' => 'Alice', + ], + [ + 'id' => 2, + 'name' => 'Bob', + ], + [ + 'id' => 3, + 'name' => 'Alice', + ], ]; $result = wu_array_find_first_by($array, 'name', 'Alice'); @@ -277,9 +314,18 @@ public function test_array_find_first_by(): void { */ public function test_array_find_last_by(): void { $array = [ - ['id' => 1, 'name' => 'Alice'], - ['id' => 2, 'name' => 'Bob'], - ['id' => 3, 'name' => 'Alice'], + [ + 'id' => 1, + 'name' => 'Alice', + ], + [ + 'id' => 2, + 'name' => 'Bob', + ], + [ + 'id' => 3, + 'name' => 'Alice', + ], ]; $result = wu_array_find_last_by($array, 'name', 'Alice'); @@ -293,9 +339,18 @@ public function test_array_find_last_by(): void { */ public function test_array_find_all_by(): void { $array = [ - ['id' => 1, 'name' => 'Alice'], - ['id' => 2, 'name' => 'Bob'], - ['id' => 3, 'name' => 'Alice'], + [ + 'id' => 1, + 'name' => 'Alice', + ], + [ + 'id' => 2, + 'name' => 'Bob', + ], + [ + 'id' => 3, + 'name' => 'Alice', + ], ]; $result = wu_array_find_all_by($array, 'name', 'Alice'); @@ -308,8 +363,14 @@ public function test_array_find_all_by(): void { */ public function test_array_find_first_by_no_match(): void { $array = [ - ['id' => 1, 'name' => 'Alice'], - ['id' => 2, 'name' => 'Bob'], + [ + 'id' => 1, + 'name' => 'Alice', + ], + [ + 'id' => 2, + 'name' => 'Bob', + ], ]; $result = wu_array_find_first_by($array, 'name', 'Charlie'); diff --git a/tests/WP_Ultimo/Functions/Checkout_Form_Functions_Test.php b/tests/WP_Ultimo/Functions/Checkout_Form_Functions_Test.php index 7d954cf7f..5e1c9789d 100644 --- a/tests/WP_Ultimo/Functions/Checkout_Form_Functions_Test.php +++ b/tests/WP_Ultimo/Functions/Checkout_Form_Functions_Test.php @@ -139,7 +139,10 @@ public function test_wu_create_checkout_form(): void { */ public function test_wu_form_field_request_arg_template_selection(): void { - $field = ['type' => 'template_selection', 'id' => 'my_field']; + $field = [ + 'type' => 'template_selection', + 'id' => 'my_field', + ]; $result = wu_form_field_request_arg($field); @@ -151,7 +154,10 @@ public function test_wu_form_field_request_arg_template_selection(): void { */ public function test_wu_form_field_request_arg_pricing_table(): void { - $field = ['type' => 'pricing_table', 'id' => 'my_field']; + $field = [ + 'type' => 'pricing_table', + 'id' => 'my_field', + ]; $result = wu_form_field_request_arg($field); @@ -163,7 +169,10 @@ public function test_wu_form_field_request_arg_pricing_table(): void { */ public function test_wu_form_field_request_arg_other_type(): void { - $field = ['type' => 'text', 'id' => 'my_custom_field']; + $field = [ + 'type' => 'text', + 'id' => 'my_custom_field', + ]; $result = wu_form_field_request_arg($field); @@ -176,9 +185,9 @@ public function test_wu_form_field_request_arg_other_type(): void { public function test_wu_should_hide_form_field_not_preselected(): void { $field = [ - 'type' => 'text', - 'id' => 'some_field', - 'hide_text_when_pre_selected' => '0', + 'type' => 'text', + 'id' => 'some_field', + 'hide_text_when_pre_selected' => '0', ]; $result = wu_should_hide_form_field($field); diff --git a/tests/WP_Ultimo/Functions/Checkout_Functions_Extended_Test.php b/tests/WP_Ultimo/Functions/Checkout_Functions_Extended_Test.php index 941a0e390..0058997f5 100644 --- a/tests/WP_Ultimo/Functions/Checkout_Functions_Extended_Test.php +++ b/tests/WP_Ultimo/Functions/Checkout_Functions_Extended_Test.php @@ -48,7 +48,10 @@ public function test_stripe_idempotency_key_returns_string(): void { */ public function test_stripe_idempotency_key_deterministic(): void { - $args = ['amount' => 100, 'currency' => 'USD']; + $args = [ + 'amount' => 100, + 'currency' => 'USD', + ]; $key1 = wu_stripe_generate_idempotency_key($args); $key2 = wu_stripe_generate_idempotency_key($args); diff --git a/tests/WP_Ultimo/Functions/Customer_Functions_Test.php b/tests/WP_Ultimo/Functions/Customer_Functions_Test.php index 2a3719c94..010d2df6e 100644 --- a/tests/WP_Ultimo/Functions/Customer_Functions_Test.php +++ b/tests/WP_Ultimo/Functions/Customer_Functions_Test.php @@ -279,7 +279,10 @@ public function test_create_customer_reuses_existing_wp_user_on_retry(): void { $this->assertSame($user_id, $customer->get_user_id()); // Confirm only one WP user exists with this email. - $users_with_email = get_users(['search' => $email, 'search_columns' => ['user_email']]); + $users_with_email = get_users([ + 'search' => $email, + 'search_columns' => ['user_email'], + ]); $this->assertCount(1, $users_with_email); } diff --git a/tests/WP_Ultimo/Functions/Danger_Functions_Test.php b/tests/WP_Ultimo/Functions/Danger_Functions_Test.php index 8435eb6bc..cfa770c35 100644 --- a/tests/WP_Ultimo/Functions/Danger_Functions_Test.php +++ b/tests/WP_Ultimo/Functions/Danger_Functions_Test.php @@ -140,7 +140,7 @@ public function test_wu_drop_tables_except_filter_can_add_exclusions(): void { add_filter( 'wu_drop_tables_except', function ($except) use (&$captured_except) { - $except[] = 'custom_table'; + $except[] = 'custom_table'; $captured_except = $except; return $except; } diff --git a/tests/WP_Ultimo/Functions/Date_Functions_Test.php b/tests/WP_Ultimo/Functions/Date_Functions_Test.php index a41d558a5..354fd05f0 100644 --- a/tests/WP_Ultimo/Functions/Date_Functions_Test.php +++ b/tests/WP_Ultimo/Functions/Date_Functions_Test.php @@ -74,7 +74,7 @@ public function test_wu_date_invalid_uses_now(): void { $this->assertInstanceOf(\DateTime::class, $date); // Should be close to current time - $now = new \DateTime(); + $now = new \DateTime(); $diff = $now->getTimestamp() - $date->getTimestamp(); $this->assertLessThan(5, abs($diff)); // Within 5 seconds } @@ -134,7 +134,7 @@ public function test_wu_date_zero_date_uses_now(): void { * Test wu_get_days_ago returns correct value. */ public function test_get_days_ago(): void { - $today = date('Y-m-d H:i:s'); + $today = date('Y-m-d H:i:s'); $yesterday = date('Y-m-d H:i:s', strtotime('-1 day')); $days = wu_get_days_ago($yesterday, $today); @@ -156,7 +156,7 @@ public function test_get_days_ago_same_date(): void { * Test wu_get_days_ago with future date. */ public function test_get_days_ago_future_date(): void { - $today = date('Y-m-d H:i:s'); + $today = date('Y-m-d H:i:s'); $tomorrow = date('Y-m-d H:i:s', strtotime('+1 day')); $days = wu_get_days_ago($tomorrow, $today); diff --git a/tests/WP_Ultimo/Functions/Env_Functions_Test.php b/tests/WP_Ultimo/Functions/Env_Functions_Test.php index b9e7550df..72c979c5b 100644 --- a/tests/WP_Ultimo/Functions/Env_Functions_Test.php +++ b/tests/WP_Ultimo/Functions/Env_Functions_Test.php @@ -37,7 +37,7 @@ public function test_env_picker_backend(): void { */ public function test_env_picker_with_arrays(): void { $frontend = ['class1', 'class2']; - $backend = ['class3', 'class4']; + $backend = ['class3', 'class4']; $result = wu_env_picker($frontend, $backend, false); $this->assertEquals($frontend, $result); diff --git a/tests/WP_Ultimo/Functions/Form_Functions_Test.php b/tests/WP_Ultimo/Functions/Form_Functions_Test.php index 4a3ae8fcc..6d3b27fac 100644 --- a/tests/WP_Ultimo/Functions/Form_Functions_Test.php +++ b/tests/WP_Ultimo/Functions/Form_Functions_Test.php @@ -46,7 +46,10 @@ public function test_wu_get_form_url_inline(): void { */ public function test_wu_get_form_url_inline_custom_dimensions(): void { - $url = wu_get_form_url('my_form', ['width' => '600', 'height' => '500'], true); + $url = wu_get_form_url('my_form', [ + 'width' => '600', + 'height' => '500', + ], true); $this->assertStringContainsString('width=600', $url); $this->assertStringContainsString('height=500', $url); diff --git a/tests/WP_Ultimo/Functions/Helper_Functions_Test.php b/tests/WP_Ultimo/Functions/Helper_Functions_Test.php index c8b0f3eff..9e2590062 100644 --- a/tests/WP_Ultimo/Functions/Helper_Functions_Test.php +++ b/tests/WP_Ultimo/Functions/Helper_Functions_Test.php @@ -49,7 +49,10 @@ public function test_is_must_use(): void { */ public function test_get_isset_existing_key(): void { - $array = ['name' => 'John', 'age' => 30]; + $array = [ + 'name' => 'John', + 'age' => 30, + ]; $this->assertEquals('John', wu_get_isset($array, 'name')); $this->assertEquals(30, wu_get_isset($array, 'age')); @@ -71,7 +74,10 @@ public function test_get_isset_missing_key(): void { */ public function test_get_isset_with_object(): void { - $obj = (object) ['name' => 'Jane', 'role' => 'admin']; + $obj = (object) [ + 'name' => 'Jane', + 'role' => 'admin', + ]; $this->assertEquals('Jane', wu_get_isset($obj, 'name')); $this->assertEquals('admin', wu_get_isset($obj, 'role')); diff --git a/tests/WP_Ultimo/Functions/Membership_Functions_Test.php b/tests/WP_Ultimo/Functions/Membership_Functions_Test.php index 7e9634341..1d5b3f42e 100644 --- a/tests/WP_Ultimo/Functions/Membership_Functions_Test.php +++ b/tests/WP_Ultimo/Functions/Membership_Functions_Test.php @@ -381,7 +381,7 @@ public function test_get_membership_update_url_contains_hash(): void { $this->assertNotWPError($membership); - $url = wu_get_membership_update_url($membership); + $url = wu_get_membership_update_url($membership); $hash = $membership->get_hash(); $this->assertStringContainsString($hash, $url); @@ -754,7 +754,7 @@ public function test_membership_create_new_payment_keep_non_recurring(): void { $this->assertNotWPError($payment_keep); $this->assertInstanceOf(\WP_Ultimo\Models\Payment::class, $payment_keep); - $keep_items = $payment_keep->get_line_items(); + $keep_items = $payment_keep->get_line_items(); $non_recurring_kept = array_filter($keep_items, fn($item) => ! $item->is_recurring()); $this->assertNotEmpty($non_recurring_kept, 'Non-recurring line items must be present when remove_non_recurring=false.'); @@ -764,7 +764,7 @@ public function test_membership_create_new_payment_keep_non_recurring(): void { $this->assertNotWPError($payment_strip); $this->assertInstanceOf(\WP_Ultimo\Models\Payment::class, $payment_strip); - $strip_items = $payment_strip->get_line_items(); + $strip_items = $payment_strip->get_line_items(); $non_recurring_stripped = array_filter($strip_items, fn($item) => ! $item->is_recurring()); $this->assertEmpty($non_recurring_stripped, 'Non-recurring line items must be removed when remove_non_recurring=true.'); } diff --git a/tests/WP_Ultimo/Functions/Model_Functions_Test.php b/tests/WP_Ultimo/Functions/Model_Functions_Test.php index b7277f9f4..e6734813d 100644 --- a/tests/WP_Ultimo/Functions/Model_Functions_Test.php +++ b/tests/WP_Ultimo/Functions/Model_Functions_Test.php @@ -40,7 +40,10 @@ public function test_cast_model_to_array_with_model(): void { */ public function test_cast_model_to_array_with_array(): void { - $input = ['name' => 'Test', 'value' => 123]; + $input = [ + 'name' => 'Test', + 'value' => 123, + ]; $result = wu_cast_model_to_array($input); diff --git a/tests/WP_Ultimo/Functions/Options_Functions_Test.php b/tests/WP_Ultimo/Functions/Options_Functions_Test.php index e16dcf43d..63f831d1b 100644 --- a/tests/WP_Ultimo/Functions/Options_Functions_Test.php +++ b/tests/WP_Ultimo/Functions/Options_Functions_Test.php @@ -46,7 +46,10 @@ public function test_save_and_get_option(): void { */ public function test_save_option_array(): void { - $data = ['key1' => 'val1', 'key2' => 'val2']; + $data = [ + 'key1' => 'val1', + 'key2' => 'val2', + ]; wu_save_option('test_option_array', $data); diff --git a/tests/WP_Ultimo/Functions/Sort_Helpers_Test.php b/tests/WP_Ultimo/Functions/Sort_Helpers_Test.php index e9a520ee0..334bccede 100644 --- a/tests/WP_Ultimo/Functions/Sort_Helpers_Test.php +++ b/tests/WP_Ultimo/Functions/Sort_Helpers_Test.php @@ -85,9 +85,18 @@ public function test_sort_by_order(): void { */ public function test_sort_by_column_with_usort(): void { $items = [ - ['name' => 'C', 'order' => 30], - ['name' => 'A', 'order' => 10], - ['name' => 'B', 'order' => 20], + [ + 'name' => 'C', + 'order' => 30, + ], + [ + 'name' => 'A', + 'order' => 10, + ], + [ + 'name' => 'B', + 'order' => 20, + ], ]; usort($items, fn($a, $b) => wu_sort_by_column($a, $b)); @@ -119,9 +128,15 @@ public function test_set_order_from_index_basic(): void { */ public function test_set_order_from_index_preserves_existing(): void { $items = [ - ['name' => 'First', 'order' => 5], + [ + 'name' => 'First', + 'order' => 5, + ], ['name' => 'Second'], - ['name' => 'Third', 'order' => 100], + [ + 'name' => 'Third', + 'order' => 100, + ], ]; $result = wu_set_order_from_index($items); diff --git a/tests/WP_Ultimo/Functions/Url_Helpers_Test.php b/tests/WP_Ultimo/Functions/Url_Helpers_Test.php index b09412338..71976442d 100644 --- a/tests/WP_Ultimo/Functions/Url_Helpers_Test.php +++ b/tests/WP_Ultimo/Functions/Url_Helpers_Test.php @@ -74,7 +74,10 @@ public function test_network_admin_url_basic(): void { * Test wu_network_admin_url with query parameters. */ public function test_network_admin_url_with_query_params(): void { - $url = wu_network_admin_url('wp-ultimo', ['tab' => 'settings', 'id' => 123]); + $url = wu_network_admin_url('wp-ultimo', [ + 'tab' => 'settings', + 'id' => 123, + ]); $this->assertStringContainsString('admin.php?page=wp-ultimo', $url); $this->assertStringContainsString('tab=settings', $url); $this->assertStringContainsString('id=123', $url); @@ -126,7 +129,10 @@ public function test_ajax_url_without_when_param(): void { * Test wu_ajax_url with custom query args. */ public function test_ajax_url_with_query_args(): void { - $url = wu_ajax_url(null, ['action' => 'test_action', 'id' => 42]); + $url = wu_ajax_url(null, [ + 'action' => 'test_action', + 'id' => 42, + ]); $this->assertStringContainsString('action=test_action', $url); $this->assertStringContainsString('id=42', $url); } diff --git a/tests/WP_Ultimo/Gateways/Base_PayPal_Gateway_Test.php b/tests/WP_Ultimo/Gateways/Base_PayPal_Gateway_Test.php index deb5bd407..71967edc6 100644 --- a/tests/WP_Ultimo/Gateways/Base_PayPal_Gateway_Test.php +++ b/tests/WP_Ultimo/Gateways/Base_PayPal_Gateway_Test.php @@ -79,7 +79,7 @@ public function get_connection_status(): array { * @param mixed $type Checkout type. * @return bool */ - public function process_checkout( $payment, $membership, $customer, $cart, $type ) { + public function process_checkout($payment, $membership, $customer, $cart, $type) { return true; } @@ -90,7 +90,7 @@ public function process_checkout( $payment, $membership, $customer, $cart, $type * @param mixed $customer Customer object. * @return bool */ - public function process_cancellation( $membership, $customer ) { + public function process_cancellation($membership, $customer) { return true; } @@ -103,7 +103,7 @@ public function process_cancellation( $membership, $customer ) { * @param mixed $customer Customer object. * @return bool */ - public function process_refund( $amount, $payment, $membership, $customer ) { + public function process_refund($amount, $payment, $membership, $customer) { return true; } @@ -112,7 +112,7 @@ public function process_refund( $amount, $payment, $membership, $customer ) { * * @param bool $test_mode Test mode flag. */ - public function set_test_mode( bool $test_mode ): void { + public function set_test_mode(bool $test_mode): void { $this->test_mode = $test_mode; } @@ -140,7 +140,7 @@ public function public_get_api_base_url(): string { * @param string $subscription_id Subscription ID. * @return bool */ - public function public_is_rest_subscription_id( string $subscription_id ): bool { + public function public_is_rest_subscription_id(string $subscription_id): bool { return $this->is_rest_subscription_id( $subscription_id ); } @@ -150,7 +150,7 @@ public function public_is_rest_subscription_id( string $subscription_id ): bool * @param array $headers Headers array. * @return array */ - public function public_add_partner_attribution_header( array $headers ): array { + public function public_add_partner_attribution_header(array $headers): array { return $this->add_partner_attribution_header( $headers ); } @@ -160,7 +160,7 @@ public function public_add_partner_attribution_header( array $headers ): array { * @param \WP_Ultimo\Checkout\Cart $cart Cart object. * @return string */ - public function public_get_subscription_description( $cart ): string { + public function public_get_subscription_description($cart): string { return $this->get_subscription_description( $cart ); } @@ -170,7 +170,7 @@ public function public_get_subscription_description( $cart ): string { * @param string $message Message to log. * @param string $level Log level. */ - public function public_log( string $message, string $level = 'info' ): void { + public function public_log(string $message, string $level = 'info'): void { $this->log( $message, $level ); } } @@ -278,7 +278,7 @@ public function test_get_api_base_url_returns_live_in_live_mode(): void { public function test_get_subscription_description_truncates_to_127_chars(): void { $cart_mock = $this->getMockBuilder( \WP_Ultimo\Checkout\Cart::class ) ->disableOriginalConstructor() - ->onlyMethods( array( 'get_cart_descriptor' ) ) + ->onlyMethods( array('get_cart_descriptor') ) ->getMock(); $long_descriptor = str_repeat( 'A', 200 ); @@ -296,7 +296,7 @@ public function test_get_subscription_description_truncates_to_127_chars(): void public function test_get_subscription_description_decodes_html_entities(): void { $cart_mock = $this->getMockBuilder( \WP_Ultimo\Checkout\Cart::class ) ->disableOriginalConstructor() - ->onlyMethods( array( 'get_cart_descriptor' ) ) + ->onlyMethods( array('get_cart_descriptor') ) ->getMock(); $cart_mock->method( 'get_cart_descriptor' )->willReturn( 'Test & Product' ); @@ -312,7 +312,7 @@ public function test_get_subscription_description_decodes_html_entities(): void public function test_get_subscription_description_handles_short_descriptors(): void { $cart_mock = $this->getMockBuilder( \WP_Ultimo\Checkout\Cart::class ) ->disableOriginalConstructor() - ->onlyMethods( array( 'get_cart_descriptor' ) ) + ->onlyMethods( array('get_cart_descriptor') ) ->getMock(); $cart_mock->method( 'get_cart_descriptor' )->willReturn( 'Short' ); @@ -456,7 +456,7 @@ public function test_is_rest_subscription_id_is_case_sensitive(): void { * Test add_partner_attribution_header adds BN code to headers. */ public function test_add_partner_attribution_header_adds_bn_code(): void { - $headers = array( 'Content-Type' => 'application/json' ); + $headers = array('Content-Type' => 'application/json'); $result = $this->gateway->public_add_partner_attribution_header( $headers ); @@ -484,7 +484,7 @@ public function test_add_partner_attribution_header_works_with_empty_array(): vo * Test add_site_actions returns unchanged actions when no membership. */ public function test_add_site_actions_returns_unchanged_when_no_membership(): void { - $actions = array( 'existing_action' => array( 'label' => 'Test' ) ); + $actions = array('existing_action' => array('label' => 'Test')); $result = $this->gateway->add_site_actions( $actions, array(), null, null ); @@ -497,12 +497,12 @@ public function test_add_site_actions_returns_unchanged_when_no_membership(): vo public function test_add_site_actions_returns_unchanged_when_gateway_does_not_match(): void { $membership_mock = $this->getMockBuilder( Membership::class ) ->disableOriginalConstructor() - ->onlyMethods( array( 'get_gateway' ) ) + ->onlyMethods( array('get_gateway') ) ->getMock(); $membership_mock->method( 'get_gateway' )->willReturn( 'stripe' ); - $actions = array( 'existing_action' => array( 'label' => 'Test' ) ); + $actions = array('existing_action' => array('label' => 'Test')); $result = $this->gateway->add_site_actions( $actions, array(), null, $membership_mock ); @@ -515,13 +515,13 @@ public function test_add_site_actions_returns_unchanged_when_gateway_does_not_ma public function test_add_site_actions_returns_unchanged_when_no_subscription_id(): void { $membership_mock = $this->getMockBuilder( Membership::class ) ->disableOriginalConstructor() - ->onlyMethods( array( 'get_gateway', 'get_gateway_subscription_id' ) ) + ->onlyMethods( array('get_gateway', 'get_gateway_subscription_id') ) ->getMock(); $membership_mock->method( 'get_gateway' )->willReturn( 'paypal' ); $membership_mock->method( 'get_gateway_subscription_id' )->willReturn( '' ); - $actions = array( 'existing_action' => array( 'label' => 'Test' ) ); + $actions = array('existing_action' => array('label' => 'Test')); $result = $this->gateway->add_site_actions( $actions, array(), null, $membership_mock ); @@ -536,13 +536,13 @@ public function test_add_site_actions_adds_view_on_paypal_action(): void { $membership_mock = $this->getMockBuilder( Membership::class ) ->disableOriginalConstructor() - ->onlyMethods( array( 'get_gateway', 'get_gateway_subscription_id' ) ) + ->onlyMethods( array('get_gateway', 'get_gateway_subscription_id') ) ->getMock(); $membership_mock->method( 'get_gateway' )->willReturn( 'paypal' ); $membership_mock->method( 'get_gateway_subscription_id' )->willReturn( 'I-TEST123' ); - $actions = array( 'existing_action' => array( 'label' => 'Test' ) ); + $actions = array('existing_action' => array('label' => 'Test')); $result = $this->gateway->add_site_actions( $actions, array(), null, $membership_mock ); @@ -562,7 +562,7 @@ public function test_add_site_actions_works_with_paypal_rest_gateway_id(): void $membership_mock = $this->getMockBuilder( Membership::class ) ->disableOriginalConstructor() - ->onlyMethods( array( 'get_gateway', 'get_gateway_subscription_id' ) ) + ->onlyMethods( array('get_gateway', 'get_gateway_subscription_id') ) ->getMock(); $membership_mock->method( 'get_gateway' )->willReturn( 'paypal-rest' ); diff --git a/tests/WP_Ultimo/Gateways/Base_Stripe_Gateway_Test.php b/tests/WP_Ultimo/Gateways/Base_Stripe_Gateway_Test.php index 2ccaed39f..3cb2a54b5 100644 --- a/tests/WP_Ultimo/Gateways/Base_Stripe_Gateway_Test.php +++ b/tests/WP_Ultimo/Gateways/Base_Stripe_Gateway_Test.php @@ -345,7 +345,10 @@ public function test_add_application_fee_to_intent_skips_when_not_applicable(): $gateway_mock->method('should_apply_application_fee')->willReturn(false); - $intent_args = ['amount' => 1000, 'currency' => 'usd']; + $intent_args = [ + 'amount' => 1000, + 'currency' => 'usd', + ]; $result = $this->gateway->add_application_fee_to_intent($intent_args, $gateway_mock); $this->assertArrayNotHasKey('application_fee_amount', $result); @@ -363,7 +366,10 @@ public function test_add_application_fee_to_intent_skips_zero_amount(): void { $gateway_mock->method('should_apply_application_fee')->willReturn(true); $gateway_mock->method('get_application_fee_percent')->willReturn(3.0); - $intent_args = ['amount' => 0, 'currency' => 'usd']; + $intent_args = [ + 'amount' => 0, + 'currency' => 'usd', + ]; $result = $this->gateway->add_application_fee_to_intent($intent_args, $gateway_mock); $this->assertArrayNotHasKey('application_fee_amount', $result); @@ -380,7 +386,10 @@ public function test_add_application_fee_to_intent_adds_fee(): void { $gateway_mock->method('should_apply_application_fee')->willReturn(true); $gateway_mock->method('get_application_fee_percent')->willReturn(3.0); - $intent_args = ['amount' => 1000, 'currency' => 'usd']; + $intent_args = [ + 'amount' => 1000, + 'currency' => 'usd', + ]; $result = $this->gateway->add_application_fee_to_intent($intent_args, $gateway_mock); $this->assertArrayHasKey('application_fee_amount', $result); @@ -398,7 +407,10 @@ public function test_add_application_fee_to_intent_skips_negative_amount(): void $gateway_mock->method('should_apply_application_fee')->willReturn(true); $gateway_mock->method('get_application_fee_percent')->willReturn(3.0); - $intent_args = ['amount' => -100, 'currency' => 'usd']; + $intent_args = [ + 'amount' => -100, + 'currency' => 'usd', + ]; $result = $this->gateway->add_application_fee_to_intent($intent_args, $gateway_mock); $this->assertArrayNotHasKey('application_fee_amount', $result); @@ -689,9 +701,9 @@ public function test_get_payment_method_display_null_when_no_payment_method(): v $subscription = \Stripe\Subscription::constructFrom( [ - 'id' => 'sub_test123', - 'status' => 'active', - 'default_payment_method' => null, + 'id' => 'sub_test123', + 'status' => 'active', + 'default_payment_method' => null, ] ); @@ -729,11 +741,11 @@ public function test_get_payment_method_display_returns_card_info(): void { $membership_mock->method('get_gateway_subscription_id')->willReturn('sub_test123'); - $card = new \stdClass(); + $card = new \stdClass(); $card->brand = 'visa'; $card->last4 = '4242'; - $pm = new \stdClass(); + $pm = new \stdClass(); $pm->card = $card; $subscription = \Stripe\Subscription::constructFrom( @@ -920,13 +932,13 @@ public function test_fix_saving_settings_preserves_oauth_tokens(): void { $id = 'stripe'; $saved_settings = [ - "{$id}_test_access_token" => 'sk_test_existing_token', - "{$id}_test_refresh_token" => 'rt_test_existing', - "{$id}_test_account_id" => 'acct_existing', + "{$id}_test_access_token" => 'sk_test_existing_token', + "{$id}_test_refresh_token" => 'rt_test_existing', + "{$id}_test_account_id" => 'acct_existing', "{$id}_test_publishable_key" => 'pk_test_existing', - "{$id}_live_access_token" => 'sk_live_existing_token', - "{$id}_live_refresh_token" => 'rt_live_existing', - "{$id}_live_account_id" => 'acct_live_existing', + "{$id}_live_access_token" => 'sk_live_existing_token', + "{$id}_live_refresh_token" => 'rt_live_existing', + "{$id}_live_account_id" => 'acct_live_existing', "{$id}_live_publishable_key" => 'pk_live_existing', ]; @@ -950,7 +962,7 @@ public function test_fix_saving_settings_returns_early_when_not_active(): void { $id = 'stripe'; $settings = [ - "{$id}_sandbox_mode" => '1', + "{$id}_sandbox_mode" => '1', "{$id}_webhook_listener_explanation" => 'some_url', ]; @@ -973,7 +985,7 @@ public function test_fix_saving_settings_sets_sandbox_mode_false(): void { $id = 'stripe'; $settings = [ - "{$id}_sandbox_mode" => '1', + "{$id}_sandbox_mode" => '1', "{$id}_webhook_listener_explanation" => 'some_url', ]; @@ -1023,13 +1035,13 @@ public function test_process_membership_update_returns_error_when_no_subscriptio * Test convert_to_stripe_address maps fields correctly. */ public function test_convert_to_stripe_address_maps_fields(): void { - $billing_address = new \stdClass(); - $billing_address->billing_city = 'New York'; - $billing_address->billing_country = 'US'; + $billing_address = new \stdClass(); + $billing_address->billing_city = 'New York'; + $billing_address->billing_country = 'US'; $billing_address->billing_address_line_1 = '123 Main St'; $billing_address->billing_address_line_2 = 'Apt 4'; - $billing_address->billing_zip_code = '10001'; - $billing_address->billing_state = 'NY'; + $billing_address->billing_zip_code = '10001'; + $billing_address->billing_state = 'NY'; $result = $this->gateway->convert_to_stripe_address($billing_address); @@ -2461,7 +2473,10 @@ public function test_handle_disconnect_clears_oauth_settings(): void { 'pre_http_request', function ($preempt, $args, $url) { if (strpos($url, '/deauthorize') !== false) { - return ['response' => ['code' => 200], 'body' => '{}']; + return [ + 'response' => ['code' => 200], + 'body' => '{}', + ]; } return $preempt; }, @@ -2693,10 +2708,10 @@ function ($property) use ($tax_rates_mock) { $result = $this->gateway->maybe_create_tax_rate( [ - 'country' => 'US', - 'tax_rate' => 10, - 'type' => 'vat', - 'title' => 'VAT', + 'country' => 'US', + 'tax_rate' => 10, + 'type' => 'vat', + 'title' => 'VAT', 'inclusive' => false, ] ); @@ -2768,11 +2783,11 @@ public function test_check_keys_status_returns_early_when_not_active(): void { $id = 'stripe'; $settings = [ - "{$id}_sandbox_mode" => '1', - "{$id}_test_pk_key" => 'pk_test_new', - "{$id}_test_sk_key" => 'sk_test_new', - "{$id}_live_pk_key" => '', - "{$id}_live_sk_key" => '', + "{$id}_sandbox_mode" => '1', + "{$id}_test_pk_key" => 'pk_test_new', + "{$id}_test_sk_key" => 'sk_test_new', + "{$id}_live_pk_key" => '', + "{$id}_live_sk_key" => '', ]; $settings_to_save = [ @@ -2794,11 +2809,11 @@ public function test_check_keys_status_returns_early_when_unchanged(): void { $id = 'stripe'; $settings = [ - "{$id}_sandbox_mode" => '1', - "{$id}_test_pk_key" => 'pk_test_same', - "{$id}_test_sk_key" => 'sk_test_same', - "{$id}_live_pk_key" => '', - "{$id}_live_sk_key" => '', + "{$id}_sandbox_mode" => '1', + "{$id}_test_pk_key" => 'pk_test_same', + "{$id}_test_sk_key" => 'sk_test_same', + "{$id}_live_pk_key" => '', + "{$id}_live_sk_key" => '', ]; $settings_to_save = [ @@ -2823,7 +2838,7 @@ public function test_check_keys_status_returns_early_when_unchanged(): void { * Uses Base_Stripe_Gateway_Stub since Stripe_Gateway overrides run_preflight() with real logic. */ public function test_run_preflight_returns_nothing(): void { - $stub = new Base_Stripe_Gateway_Stub(); + $stub = new Base_Stripe_Gateway_Stub(); $result = $stub->run_preflight(); $this->assertNull($result); @@ -2924,9 +2939,9 @@ public function test_handle_oauth_callbacks_returns_early_when_no_params(): void public function test_handle_oauth_callbacks_ignores_invalid_state(): void { // Set up GET params for OAuth callback. $_GET = [ - 'page' => 'wp-ultimo-settings', - 'wcs_stripe_code' => 'encrypted_code_123', - 'wcs_stripe_state' => 'invalid_state', + 'page' => 'wp-ultimo-settings', + 'wcs_stripe_code' => 'encrypted_code_123', + 'wcs_stripe_state' => 'invalid_state', ]; // Set a different expected state. diff --git a/tests/WP_Ultimo/Gateways/Free_Gateway_Test.php b/tests/WP_Ultimo/Gateways/Free_Gateway_Test.php index 25ac4df6e..c4e7d824b 100644 --- a/tests/WP_Ultimo/Gateways/Free_Gateway_Test.php +++ b/tests/WP_Ultimo/Gateways/Free_Gateway_Test.php @@ -99,7 +99,7 @@ public function test_process_checkout_new(): void { $this->gateway->process_checkout($payment, $membership, $customer, $cart, 'new'); // Reload from database - $updated_payment = wu_get_payment($payment->get_id()); + $updated_payment = wu_get_payment($payment->get_id()); $updated_membership = wu_get_membership($membership->get_id()); // Assert payment is completed diff --git a/tests/WP_Ultimo/Gateways/Manual_Gateway_Test.php b/tests/WP_Ultimo/Gateways/Manual_Gateway_Test.php index 5ed180436..e62d6b1d1 100644 --- a/tests/WP_Ultimo/Gateways/Manual_Gateway_Test.php +++ b/tests/WP_Ultimo/Gateways/Manual_Gateway_Test.php @@ -302,7 +302,7 @@ public function test_save_and_get_swap() { $gateway = $this->get_gateway(); // Use a simple object as a stand-in for a cart - $cart = new \stdClass(); + $cart = new \stdClass(); $cart->test = 'value'; $swap_id = $gateway->save_swap($cart); diff --git a/tests/WP_Ultimo/Gateways/PayPal_REST_Gateway_Test.php b/tests/WP_Ultimo/Gateways/PayPal_REST_Gateway_Test.php index 0cd2cfd5d..3ad78400d 100644 --- a/tests/WP_Ultimo/Gateways/PayPal_REST_Gateway_Test.php +++ b/tests/WP_Ultimo/Gateways/PayPal_REST_Gateway_Test.php @@ -685,7 +685,10 @@ public function test_maybe_remove_for_unsupported_currency_keeps_when_supported( wu_save_setting('currency', 'USD'); - $gateways = ['paypal-rest' => $this->gateway, 'stripe' => 'stripe']; + $gateways = [ + 'paypal-rest' => $this->gateway, + 'stripe' => 'stripe', + ]; $result = $this->gateway->maybe_remove_for_unsupported_currency($gateways); $this->assertArrayHasKey('paypal-rest', $result); @@ -698,7 +701,10 @@ public function test_maybe_remove_for_unsupported_currency_removes_when_unsuppor wu_save_setting('currency', 'NGN'); - $gateways = ['paypal-rest' => $this->gateway, 'stripe' => 'stripe']; + $gateways = [ + 'paypal-rest' => $this->gateway, + 'stripe' => 'stripe', + ]; $result = $this->gateway->maybe_remove_for_unsupported_currency($gateways); $this->assertArrayNotHasKey('paypal-rest', $result); @@ -712,7 +718,11 @@ public function test_maybe_remove_for_unsupported_currency_preserves_other_gatew wu_save_setting('currency', 'NGN'); - $gateways = ['paypal-rest' => $this->gateway, 'stripe' => 'stripe', 'manual' => 'manual']; + $gateways = [ + 'paypal-rest' => $this->gateway, + 'stripe' => 'stripe', + 'manual' => 'manual', + ]; $result = $this->gateway->maybe_remove_for_unsupported_currency($gateways); $this->assertArrayHasKey('stripe', $result); @@ -833,9 +843,12 @@ public function test_maybe_remove_for_invalid_merchant_status_keeps_when_valid() wu_save_setting('paypal_rest_sandbox_email_confirmed', true); wu_save_setting('paypal_rest_sandbox_mode', 1); - $gateway = new PayPal_REST_Gateway(); + $gateway = new PayPal_REST_Gateway(); $gateway->init(); - $gateways = ['paypal-rest' => $gateway, 'stripe' => 'stripe']; + $gateways = [ + 'paypal-rest' => $gateway, + 'stripe' => 'stripe', + ]; $result = $gateway->maybe_remove_for_invalid_merchant_status($gateways); $this->assertArrayHasKey('paypal-rest', $result); @@ -851,9 +864,12 @@ public function test_maybe_remove_for_invalid_merchant_status_removes_when_payme wu_save_setting('paypal_rest_sandbox_email_confirmed', true); wu_save_setting('paypal_rest_sandbox_mode', 1); - $gateway = new PayPal_REST_Gateway(); + $gateway = new PayPal_REST_Gateway(); $gateway->init(); - $gateways = ['paypal-rest' => $gateway, 'stripe' => 'stripe']; + $gateways = [ + 'paypal-rest' => $gateway, + 'stripe' => 'stripe', + ]; $result = $gateway->maybe_remove_for_invalid_merchant_status($gateways); $this->assertArrayNotHasKey('paypal-rest', $result); @@ -870,9 +886,12 @@ public function test_maybe_remove_for_invalid_merchant_status_removes_when_email wu_save_setting('paypal_rest_sandbox_email_confirmed', false); wu_save_setting('paypal_rest_sandbox_mode', 1); - $gateway = new PayPal_REST_Gateway(); + $gateway = new PayPal_REST_Gateway(); $gateway->init(); - $gateways = ['paypal-rest' => $gateway, 'stripe' => 'stripe']; + $gateways = [ + 'paypal-rest' => $gateway, + 'stripe' => 'stripe', + ]; $result = $gateway->maybe_remove_for_invalid_merchant_status($gateways); $this->assertArrayNotHasKey('paypal-rest', $result); @@ -889,7 +908,10 @@ public function test_maybe_remove_for_invalid_merchant_status_keeps_without_oaut wu_save_setting('paypal_rest_sandbox_payments_receivable', false); wu_save_setting('paypal_rest_sandbox_email_confirmed', false); - $gateways = ['paypal-rest' => $this->gateway, 'stripe' => 'stripe']; + $gateways = [ + 'paypal-rest' => $this->gateway, + 'stripe' => 'stripe', + ]; $result = $this->gateway->maybe_remove_for_invalid_merchant_status($gateways); $this->assertArrayHasKey('paypal-rest', $result); @@ -905,9 +927,13 @@ public function test_maybe_remove_for_invalid_merchant_status_preserves_other_ga wu_save_setting('paypal_rest_sandbox_email_confirmed', false); wu_save_setting('paypal_rest_sandbox_mode', 1); - $gateway = new PayPal_REST_Gateway(); + $gateway = new PayPal_REST_Gateway(); $gateway->init(); - $gateways = ['paypal-rest' => $gateway, 'stripe' => 'stripe', 'manual' => 'manual']; + $gateways = [ + 'paypal-rest' => $gateway, + 'stripe' => 'stripe', + 'manual' => 'manual', + ]; $result = $gateway->maybe_remove_for_invalid_merchant_status($gateways); $this->assertArrayHasKey('stripe', $result); @@ -1914,8 +1940,8 @@ private function create_order_test_fixtures(): array { private function invoke_create_order_and_capture(PayPal_REST_Gateway $gateway, array $fixtures): ?array { // Set $this->payment on the gateway so get_confirm_url() can call get_hash(). - $reflection = new \ReflectionClass($gateway); - $payment_prop = $reflection->getParentClass()->getProperty('payment'); + $reflection = new \ReflectionClass($gateway); + $payment_prop = $reflection->getParentClass()->getProperty('payment'); $payment_prop->setAccessible(true); $payment_prop->setValue($gateway, $fixtures['payment']); diff --git a/tests/WP_Ultimo/Gateways/Stripe_Gateway_Test.php b/tests/WP_Ultimo/Gateways/Stripe_Gateway_Test.php index 6fa3eb285..bead8c66c 100644 --- a/tests/WP_Ultimo/Gateways/Stripe_Gateway_Test.php +++ b/tests/WP_Ultimo/Gateways/Stripe_Gateway_Test.php @@ -134,7 +134,16 @@ private function build_stripe_client_mock(array $overrides = []) { $customers_mock->method('update')->willReturn($stripe_customer); // Default payment method stub. - $stripe_pm = \Stripe\PaymentMethod::constructFrom(['id' => 'pm_test123', 'type' => 'card', 'card' => ['brand' => 'visa', 'last4' => '4242', 'exp_month' => 12, 'exp_year' => 2030]]); + $stripe_pm = \Stripe\PaymentMethod::constructFrom([ + 'id' => 'pm_test123', + 'type' => 'card', + 'card' => [ + 'brand' => 'visa', + 'last4' => '4242', + 'exp_month' => 12, + 'exp_year' => 2030, + ], + ]); $payment_methods_mock->method('retrieve')->willReturn($stripe_pm); // Default payment methods list (for get_user_saved_payment_methods). @@ -393,7 +402,7 @@ function ($fields) use (&$registered_field_ids) { $sections = $settings->get_sections(); $payment_gateway_fields = $sections['payment-gateways']['fields'] ?? []; - $field_ids = array_keys($payment_gateway_fields); + $field_ids = array_keys($payment_gateway_fields); $this->assertContains( 'stripe_header', @@ -441,7 +450,11 @@ public function test_run_preflight_creates_payment_intent_for_paid_order(): void $client = $this->build_stripe_client_mock(['paymentIntents' => $payment_intents_mock]); $this->gateway->set_stripe_client($client); - $context = $this->build_checkout_context(['recurring' => false, 'trial' => false, 'amount' => 50.00]); + $context = $this->build_checkout_context([ + 'recurring' => false, + 'trial' => false, + 'amount' => 50.00, + ]); $result = $this->gateway->run_preflight(); @@ -480,7 +493,11 @@ public function test_run_preflight_creates_setup_intent_for_trial_order(): void $client = $this->build_stripe_client_mock(['setupIntents' => $setup_intents_mock]); $this->gateway->set_stripe_client($client); - $context = $this->build_checkout_context(['recurring' => true, 'trial' => true, 'amount' => 29.00]); + $context = $this->build_checkout_context([ + 'recurring' => true, + 'trial' => true, + 'amount' => 29.00, + ]); $result = $this->gateway->run_preflight(); @@ -534,7 +551,11 @@ public function test_run_preflight_updates_existing_payment_intent(): void { $client = $this->build_stripe_client_mock(['paymentIntents' => $payment_intents_mock]); $this->gateway->set_stripe_client($client); - $context = $this->build_checkout_context(['recurring' => false, 'trial' => false, 'amount' => 50.00]); + $context = $this->build_checkout_context([ + 'recurring' => false, + 'trial' => false, + 'amount' => 50.00, + ]); // Pre-set the payment intent ID on the payment. $context['payment']->update_meta('stripe_payment_intent_id', 'pi_existing123'); @@ -577,7 +598,11 @@ public function test_run_preflight_reuses_existing_setup_intent(): void { $client = $this->build_stripe_client_mock(['setupIntents' => $setup_intents_mock]); $this->gateway->set_stripe_client($client); - $context = $this->build_checkout_context(['recurring' => true, 'trial' => true, 'amount' => 29.00]); + $context = $this->build_checkout_context([ + 'recurring' => true, + 'trial' => true, + 'amount' => 29.00, + ]); // Pre-set the setup intent ID on the payment. $context['payment']->update_meta('stripe_payment_intent_id', 'seti_existing123'); @@ -629,7 +654,11 @@ public function test_run_preflight_creates_new_intent_when_existing_is_canceled( $client = $this->build_stripe_client_mock(['paymentIntents' => $payment_intents_mock]); $this->gateway->set_stripe_client($client); - $context = $this->build_checkout_context(['recurring' => false, 'trial' => false, 'amount' => 50.00]); + $context = $this->build_checkout_context([ + 'recurring' => false, + 'trial' => false, + 'amount' => 50.00, + ]); $context['payment']->update_meta('stripe_payment_intent_id', 'pi_canceled123'); $result = $this->gateway->run_preflight(); @@ -760,8 +789,18 @@ public function test_run_preflight_returns_wp_error_on_stripe_exception(): void $card_exception = \Stripe\Exception\CardException::factory( 'Your card was declined.', 402, - wp_json_encode(['error' => ['code' => 'card_declined', 'message' => 'Your card was declined.']]), - ['error' => ['code' => 'card_declined', 'message' => 'Your card was declined.']], + wp_json_encode([ + 'error' => [ + 'code' => 'card_declined', + 'message' => 'Your card was declined.', + ], + ]), + [ + 'error' => [ + 'code' => 'card_declined', + 'message' => 'Your card was declined.', + ], + ], null, 'card_declined', 'insufficient_funds' @@ -769,13 +808,22 @@ public function test_run_preflight_returns_wp_error_on_stripe_exception(): void $payment_intents_mock->method('create')->willThrowException($card_exception); $payment_intents_mock->method('retrieve')->willReturn( - \Stripe\PaymentIntent::constructFrom(['id' => 'pi_x', 'object' => 'payment_intent', 'status' => 'canceled', 'client_secret' => 'x']) + \Stripe\PaymentIntent::constructFrom([ + 'id' => 'pi_x', + 'object' => 'payment_intent', + 'status' => 'canceled', + 'client_secret' => 'x', + ]) ); $client = $this->build_stripe_client_mock(['paymentIntents' => $payment_intents_mock]); $this->gateway->set_stripe_client($client); - $context = $this->build_checkout_context(['recurring' => false, 'trial' => false, 'amount' => 50.00]); + $context = $this->build_checkout_context([ + 'recurring' => false, + 'trial' => false, + 'amount' => 50.00, + ]); $result = $this->gateway->run_preflight(); @@ -803,13 +851,22 @@ public function test_run_preflight_returns_wp_error_on_generic_exception(): void $payment_intents_mock->method('create') ->willThrowException(new \RuntimeException('Something went wrong', 500)); $payment_intents_mock->method('retrieve')->willReturn( - \Stripe\PaymentIntent::constructFrom(['id' => 'pi_x', 'object' => 'payment_intent', 'status' => 'canceled', 'client_secret' => 'x']) + \Stripe\PaymentIntent::constructFrom([ + 'id' => 'pi_x', + 'object' => 'payment_intent', + 'status' => 'canceled', + 'client_secret' => 'x', + ]) ); $client = $this->build_stripe_client_mock(['paymentIntents' => $payment_intents_mock]); $this->gateway->set_stripe_client($client); - $context = $this->build_checkout_context(['recurring' => false, 'trial' => false, 'amount' => 50.00]); + $context = $this->build_checkout_context([ + 'recurring' => false, + 'trial' => false, + 'amount' => 50.00, + ]); $result = $this->gateway->run_preflight(); @@ -839,8 +896,18 @@ public function test_run_preflight_returns_wp_error_when_customer_creation_fails $retrieve_exception = \Stripe\Exception\InvalidRequestException::factory( 'No such customer', 404, - wp_json_encode(['error' => ['code' => 'resource_missing', 'message' => 'No such customer']]), - ['error' => ['code' => 'resource_missing', 'message' => 'No such customer']], + wp_json_encode([ + 'error' => [ + 'code' => 'resource_missing', + 'message' => 'No such customer', + ], + ]), + [ + 'error' => [ + 'code' => 'resource_missing', + 'message' => 'No such customer', + ], + ], null, 'resource_missing' ); @@ -848,8 +915,18 @@ public function test_run_preflight_returns_wp_error_when_customer_creation_fails $create_exception = \Stripe\Exception\InvalidRequestException::factory( 'Invalid customer', 400, - wp_json_encode(['error' => ['code' => 'invalid_request_error', 'message' => 'Invalid customer']]), - ['error' => ['code' => 'invalid_request_error', 'message' => 'Invalid customer']], + wp_json_encode([ + 'error' => [ + 'code' => 'invalid_request_error', + 'message' => 'Invalid customer', + ], + ]), + [ + 'error' => [ + 'code' => 'invalid_request_error', + 'message' => 'Invalid customer', + ], + ], null, 'invalid_request_error' ); @@ -860,7 +937,11 @@ public function test_run_preflight_returns_wp_error_when_customer_creation_fails $client = $this->build_stripe_client_mock(['customers' => $customers_mock]); $this->gateway->set_stripe_client($client); - $context = $this->build_checkout_context(['recurring' => false, 'trial' => false, 'amount' => 50.00]); + $context = $this->build_checkout_context([ + 'recurring' => false, + 'trial' => false, + 'amount' => 50.00, + ]); $result = $this->gateway->run_preflight(); @@ -889,13 +970,22 @@ public function test_run_preflight_handles_exception_with_empty_error_code(): vo $payment_intents_mock->method('create') ->willThrowException(new \RuntimeException('Empty code error', 0)); $payment_intents_mock->method('retrieve')->willReturn( - \Stripe\PaymentIntent::constructFrom(['id' => 'pi_x', 'object' => 'payment_intent', 'status' => 'canceled', 'client_secret' => 'x']) + \Stripe\PaymentIntent::constructFrom([ + 'id' => 'pi_x', + 'object' => 'payment_intent', + 'status' => 'canceled', + 'client_secret' => 'x', + ]) ); $client = $this->build_stripe_client_mock(['paymentIntents' => $payment_intents_mock]); $this->gateway->set_stripe_client($client); - $context = $this->build_checkout_context(['recurring' => false, 'trial' => false, 'amount' => 50.00]); + $context = $this->build_checkout_context([ + 'recurring' => false, + 'trial' => false, + 'amount' => 50.00, + ]); $result = $this->gateway->run_preflight(); @@ -946,7 +1036,11 @@ public function test_run_preflight_applies_payment_intent_args_filter(): void { $client = $this->build_stripe_client_mock(['paymentIntents' => $payment_intents_mock]); $this->gateway->set_stripe_client($client); - $context = $this->build_checkout_context(['recurring' => false, 'trial' => false, 'amount' => 50.00]); + $context = $this->build_checkout_context([ + 'recurring' => false, + 'trial' => false, + 'amount' => 50.00, + ]); $this->gateway->run_preflight(); @@ -998,12 +1092,12 @@ public function test_fields_includes_saved_payment_method_radio_when_cards_exist wp_set_current_user($customer->get_user_id(), $customer->get_username()); $membership = wu_create_membership([ - 'customer_id' => $customer->get_id(), - 'plan_id' => 0, - 'status' => Membership_Status::ACTIVE, - 'gateway_customer_id' => 'cus_test123', - 'gateway' => 'stripe', - 'date_expiration' => gmdate('Y-m-d 23:59:59', strtotime('+30 days')), + 'customer_id' => $customer->get_id(), + 'plan_id' => 0, + 'status' => Membership_Status::ACTIVE, + 'gateway_customer_id' => 'cus_test123', + 'gateway' => 'stripe', + 'date_expiration' => gmdate('Y-m-d 23:59:59', strtotime('+30 days')), ]); $this->gateway->set_customer($customer); @@ -1318,7 +1412,7 @@ public function test_render_oauth_connection_shows_oauth_error(): void { // Inject an OAuth error via reflection. $reflection = new \ReflectionClass($gateway); - $prop = $reflection->getProperty('oauth_error'); + $prop = $reflection->getProperty('oauth_error'); $prop->setAccessible(true); $prop->setValue($gateway, 'OAuth connection failed: access_denied'); diff --git a/tests/WP_Ultimo/Gateways/Stripe_OAuth_E2E_Test.php b/tests/WP_Ultimo/Gateways/Stripe_OAuth_E2E_Test.php index c219a1b68..5c4d98143 100644 --- a/tests/WP_Ultimo/Gateways/Stripe_OAuth_E2E_Test.php +++ b/tests/WP_Ultimo/Gateways/Stripe_OAuth_E2E_Test.php @@ -50,7 +50,7 @@ public function test_oauth_tokens_saved_correctly() { // Verify account ID is loaded $reflection = new \ReflectionClass($gateway); - $property = $reflection->getProperty('oauth_account_id'); + $property = $reflection->getProperty('oauth_account_id'); $property->setAccessible(true); $this->assertEquals('acct_test_xyz789', $property->getValue($gateway)); } @@ -72,7 +72,7 @@ public function test_stripe_client_has_account_header_in_oauth_mode() { // Access oauth_account_id via reflection $reflection = new \ReflectionClass($gateway); - $property = $reflection->getProperty('oauth_account_id'); + $property = $reflection->getProperty('oauth_account_id'); $property->setAccessible(true); // Verify account ID is set @@ -104,7 +104,7 @@ public function test_complete_oauth_flow_simulation() { $this->assertEquals('oauth', $gateway->get_authentication_mode()); // Verify account ID is loaded - $reflection = new \ReflectionClass($gateway); + $reflection = new \ReflectionClass($gateway); $account_property = $reflection->getProperty('oauth_account_id'); $account_property->setAccessible(true); $this->assertEquals('acct_connected_xyz', $account_property->getValue($gateway)); diff --git a/tests/WP_Ultimo/Gateways/Stripe_OAuth_Test.php b/tests/WP_Ultimo/Gateways/Stripe_OAuth_Test.php index 69aa351ea..19b60d11a 100644 --- a/tests/WP_Ultimo/Gateways/Stripe_OAuth_Test.php +++ b/tests/WP_Ultimo/Gateways/Stripe_OAuth_Test.php @@ -98,13 +98,13 @@ public function test_oauth_precedence_over_direct() { */ public function test_oauth_authorization_url_generation() { // Mock proxy response - add_filter('pre_http_request', function($preempt, $args, $url) { + add_filter('pre_http_request', function ($preempt, $args, $url) { if (strpos($url, '/oauth/init') !== false) { return [ 'response' => ['code' => 200], - 'body' => wp_json_encode([ + 'body' => wp_json_encode([ 'oauthUrl' => 'https://connect.stripe.com/oauth/authorize?client_id=ca_test123&state=encrypted_state&scope=read_write', - 'state' => 'test_state_123', + 'state' => 'test_state_123', ]), ]; } @@ -112,7 +112,7 @@ public function test_oauth_authorization_url_generation() { }, 10, 3); $gateway = new Stripe_Gateway(); - $url = $gateway->get_connect_authorization_url(''); + $url = $gateway->get_connect_authorization_url(''); $this->assertStringContainsString('connect.stripe.com/oauth/authorize', $url); $this->assertStringContainsString('client_id=ca_test123', $url); @@ -127,7 +127,7 @@ public function test_oauth_authorization_url_generation() { */ public function test_oauth_authorization_url_requires_client_id() { // Mock proxy returning error or invalid response - add_filter('pre_http_request', function($preempt, $args, $url) { + add_filter('pre_http_request', function ($preempt, $args, $url) { if (strpos($url, '/oauth/init') !== false) { return new \WP_Error('http_request_failed', 'Connection failed'); } @@ -135,7 +135,7 @@ public function test_oauth_authorization_url_requires_client_id() { }, 10, 3); $gateway = new Stripe_Gateway(); - $url = $gateway->get_connect_authorization_url(''); + $url = $gateway->get_connect_authorization_url(''); $this->assertEmpty($url); } @@ -157,7 +157,7 @@ public function test_backwards_compatibility_with_existing_keys() { $this->assertFalse($gateway->is_using_oauth()); // Verify API keys are loaded - $reflection = new \ReflectionClass($gateway); + $reflection = new \ReflectionClass($gateway); $secret_property = $reflection->getProperty('secret_key'); $secret_property->setAccessible(true); @@ -180,7 +180,7 @@ public function test_oauth_account_id_loaded() { // Verify account ID is loaded $reflection = new \ReflectionClass($gateway); - $property = $reflection->getProperty('oauth_account_id'); + $property = $reflection->getProperty('oauth_account_id'); $property->setAccessible(true); $this->assertEquals('acct_test123', $property->getValue($gateway)); @@ -201,7 +201,7 @@ public function test_oauth_account_id_not_loaded_for_direct() { // Verify account ID is empty $reflection = new \ReflectionClass($gateway); - $property = $reflection->getProperty('oauth_account_id'); + $property = $reflection->getProperty('oauth_account_id'); $property->setAccessible(true); $this->assertEmpty($property->getValue($gateway)); @@ -285,7 +285,7 @@ public function test_disconnect_url_has_nonce() { $gateway = new Stripe_Gateway(); $reflection = new \ReflectionClass($gateway); - $method = $reflection->getMethod('get_disconnect_url'); + $method = $reflection->getMethod('get_disconnect_url'); $method->setAccessible(true); $url = $method->invoke($gateway); diff --git a/tests/WP_Ultimo/Helpers/Arr_Test.php b/tests/WP_Ultimo/Helpers/Arr_Test.php index ca701f1da..19ee243a6 100644 --- a/tests/WP_Ultimo/Helpers/Arr_Test.php +++ b/tests/WP_Ultimo/Helpers/Arr_Test.php @@ -11,7 +11,10 @@ class Arr_Test extends WP_UnitTestCase { */ public function test_get_simple_key(): void { - $array = ['name' => 'John', 'age' => 30]; + $array = [ + 'name' => 'John', + 'age' => 30, + ]; $this->assertEquals('John', Arr::get($array, 'name')); $this->assertEquals(30, Arr::get($array, 'age')); @@ -54,7 +57,10 @@ public function test_get_missing_key_returns_default(): void { */ public function test_get_null_key_returns_array(): void { - $array = ['name' => 'John', 'age' => 30]; + $array = [ + 'name' => 'John', + 'age' => 30, + ]; $this->assertEquals($array, Arr::get($array, null)); } @@ -153,9 +159,18 @@ public function test_filter_with_closure(): void { public function test_filter_preserves_matching_items(): void { $array = [ - ['name' => 'John', 'active' => true], - ['name' => 'Jane', 'active' => false], - ['name' => 'Bob', 'active' => true], + [ + 'name' => 'John', + 'active' => true, + ], + [ + 'name' => 'Jane', + 'active' => false, + ], + [ + 'name' => 'Bob', + 'active' => true, + ], ]; $result = Arr::filter($array, function ($item) { @@ -173,9 +188,18 @@ public function test_filter_preserves_matching_items(): void { public function test_filter_by_property_simple(): void { $array = [ - ['name' => 'John', 'role' => 'admin'], - ['name' => 'Jane', 'role' => 'editor'], - ['name' => 'Bob', 'role' => 'admin'], + [ + 'name' => 'John', + 'role' => 'admin', + ], + [ + 'name' => 'Jane', + 'role' => 'editor', + ], + [ + 'name' => 'Bob', + 'role' => 'admin', + ], ]; $result = Arr::filter_by_property($array, 'role', 'admin'); @@ -189,9 +213,18 @@ public function test_filter_by_property_simple(): void { public function test_filter_by_property_dot_notation(): void { $array = [ - ['name' => 'John', 'meta' => ['status' => 'active']], - ['name' => 'Jane', 'meta' => ['status' => 'inactive']], - ['name' => 'Bob', 'meta' => ['status' => 'active']], + [ + 'name' => 'John', + 'meta' => ['status' => 'active'], + ], + [ + 'name' => 'Jane', + 'meta' => ['status' => 'inactive'], + ], + [ + 'name' => 'Bob', + 'meta' => ['status' => 'active'], + ], ]; $result = Arr::filter_by_property($array, 'meta.status', 'active'); @@ -205,8 +238,14 @@ public function test_filter_by_property_dot_notation(): void { public function test_filter_by_property_returns_first(): void { $array = [ - ['name' => 'John', 'role' => 'admin'], - ['name' => 'Bob', 'role' => 'admin'], + [ + 'name' => 'John', + 'role' => 'admin', + ], + [ + 'name' => 'Bob', + 'role' => 'admin', + ], ]; $result = Arr::filter_by_property($array, 'role', 'admin', Arr::RESULTS_FIRST); @@ -221,8 +260,14 @@ public function test_filter_by_property_returns_first(): void { public function test_filter_by_property_returns_last(): void { $array = [ - ['name' => 'John', 'role' => 'admin'], - ['name' => 'Bob', 'role' => 'admin'], + [ + 'name' => 'John', + 'role' => 'admin', + ], + [ + 'name' => 'Bob', + 'role' => 'admin', + ], ]; $result = Arr::filter_by_property($array, 'role', 'admin', Arr::RESULTS_LAST); @@ -237,7 +282,10 @@ public function test_filter_by_property_returns_last(): void { public function test_filter_by_property_no_matches(): void { $array = [ - ['name' => 'John', 'role' => 'admin'], + [ + 'name' => 'John', + 'role' => 'admin', + ], ]; $result = Arr::filter_by_property($array, 'role', 'nonexistent'); diff --git a/tests/WP_Ultimo/Helpers/Credential_Store_Test.php b/tests/WP_Ultimo/Helpers/Credential_Store_Test.php index b61872f95..ac746e7b4 100644 --- a/tests/WP_Ultimo/Helpers/Credential_Store_Test.php +++ b/tests/WP_Ultimo/Helpers/Credential_Store_Test.php @@ -56,7 +56,7 @@ public function test_encrypted_value_starts_with_prefix() { } public function test_encrypt_decrypt_round_trip() { - $original = 'my_super_secret_api_key_12345'; + $original = 'my_super_secret_api_key_12345'; $encrypted = Credential_Store::encrypt($original); $decrypted = Credential_Store::decrypt($encrypted); @@ -64,7 +64,7 @@ public function test_encrypt_decrypt_round_trip() { } public function test_encrypt_decrypt_round_trip_with_special_chars() { - $original = 'p@$$w0rd!#%^&*()_+-={}[]|\\:";\'<>?,./~`'; + $original = 'p@$$w0rd!#%^&*()_+-={}[]|\\:";\'<>?,./~`'; $encrypted = Credential_Store::encrypt($original); $decrypted = Credential_Store::decrypt($encrypted); @@ -72,7 +72,7 @@ public function test_encrypt_decrypt_round_trip_with_special_chars() { } public function test_encrypt_decrypt_round_trip_with_unicode() { - $original = 'Héllo Wörld 日本語 中文'; + $original = 'Héllo Wörld 日本語 中文'; $encrypted = Credential_Store::encrypt($original); $decrypted = Credential_Store::decrypt($encrypted); @@ -81,8 +81,8 @@ public function test_encrypt_decrypt_round_trip_with_unicode() { public function test_encrypt_produces_different_ciphertext_each_time() { $value = 'same_value'; - $enc1 = Credential_Store::encrypt($value); - $enc2 = Credential_Store::encrypt($value); + $enc1 = Credential_Store::encrypt($value); + $enc2 = Credential_Store::encrypt($value); // Due to random IV, encryptions should differ $this->assertNotEquals($enc1, $enc2); @@ -146,7 +146,7 @@ public function test_get_sodium_key_returns_32_bytes() { // ------------------------------------------------------------------ public function test_encrypt_decrypt_long_value() { - $original = str_repeat('A', 10000); + $original = str_repeat('A', 10000); $encrypted = Credential_Store::encrypt($original); $decrypted = Credential_Store::decrypt($encrypted); diff --git a/tests/WP_Ultimo/Helpers/Screenshot_Test.php b/tests/WP_Ultimo/Helpers/Screenshot_Test.php index 797f11eb5..93daae59d 100644 --- a/tests/WP_Ultimo/Helpers/Screenshot_Test.php +++ b/tests/WP_Ultimo/Helpers/Screenshot_Test.php @@ -86,7 +86,7 @@ public function test_api_url_accepts_custom_dimensions() { public function test_api_url_filter_can_override() { add_filter( 'wu_screenshot_api_url', - function ( $url, $domain ) { + function ($url, $domain) { return 'https://custom-screenshot.com/' . $domain; }, 10, @@ -130,7 +130,7 @@ public function test_fallback_api_url_accepts_custom_dimensions() { public function test_fallback_api_url_filter_can_override() { add_filter( 'wu_screenshot_fallback_api_url', - function ( $url, $domain ) { + function ($url, $domain) { return 'https://other-fallback.com/' . $domain; }, 10, @@ -150,7 +150,10 @@ public function test_save_image_returns_false_for_non_image_body() { 'pre_http_request', function () { return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], 'body' => 'not an image', ]; } @@ -165,7 +168,10 @@ public function test_save_image_returns_false_on_http_error() { 'pre_http_request', function () { return [ - 'response' => [ 'code' => 500, 'message' => 'Server Error' ], + 'response' => [ + 'code' => 500, + 'message' => 'Server Error', + ], 'body' => '', ]; } @@ -192,7 +198,10 @@ public function test_save_image_accepts_png_body() { 'pre_http_request', function () { return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], 'body' => $this->png_body(), ]; } @@ -210,7 +219,10 @@ public function test_save_image_accepts_jpeg_body() { 'pre_http_request', function () { return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], 'body' => $this->jpeg_body(), ]; } @@ -231,7 +243,10 @@ public function test_take_screenshot_returns_false_when_both_providers_fail() { 'pre_http_request', function () { return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], 'body' => 'not an image', ]; } @@ -246,9 +261,12 @@ public function test_take_screenshot_succeeds_on_primary_provider() { add_filter( 'pre_http_request', - function () use ( $png_body ) { + function () use ($png_body) { return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], 'body' => $png_body, ]; } @@ -265,19 +283,25 @@ public function test_take_screenshot_falls_back_to_thum_io_on_primary_failure() add_filter( 'pre_http_request', - function ( $preempt, $args, $url ) use ( &$call_count, $png_body ) { + function ($preempt, $args, $url) use (&$call_count, $png_body) { $call_count++; // First call (Microlink) fails, second call (thum.io) succeeds. if (strpos($url, 'microlink') !== false) { return [ - 'response' => [ 'code' => 429, 'message' => 'Too Many Requests' ], + 'response' => [ + 'code' => 429, + 'message' => 'Too Many Requests', + ], 'body' => '', ]; } return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], 'body' => $png_body, ]; }, @@ -297,11 +321,14 @@ public function test_take_screenshot_does_not_call_fallback_when_primary_succeed add_filter( 'pre_http_request', - function () use ( &$call_count, $png_body ) { + function () use (&$call_count, $png_body) { $call_count++; return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], 'body' => $png_body, ]; } diff --git a/tests/WP_Ultimo/Helpers/Unique_Customer_Email_Test.php b/tests/WP_Ultimo/Helpers/Unique_Customer_Email_Test.php index d836753ff..32408d20a 100644 --- a/tests/WP_Ultimo/Helpers/Unique_Customer_Email_Test.php +++ b/tests/WP_Ultimo/Helpers/Unique_Customer_Email_Test.php @@ -52,7 +52,7 @@ public function test_new_email_passes() { public function test_email_with_user_but_no_customer_passes() { // Create a WordPress user without a customer using a unique email - $email = 'user-only-' . wp_generate_uuid4() . '@example.com'; + $email = 'user-only-' . wp_generate_uuid4() . '@example.com'; $user_id = $this->factory()->user->create([ 'user_email' => $email, ]); diff --git a/tests/WP_Ultimo/Helpers/Validation_Rules/State_Test.php b/tests/WP_Ultimo/Helpers/Validation_Rules/State_Test.php index 6adc7d36e..21829d72d 100644 --- a/tests/WP_Ultimo/Helpers/Validation_Rules/State_Test.php +++ b/tests/WP_Ultimo/Helpers/Validation_Rules/State_Test.php @@ -13,7 +13,6 @@ /** * Test State validation rule. - */ class State_Test extends WP_UnitTestCase { @@ -78,22 +77,22 @@ public function test_all_german_state_codes_pass(string $code) { */ public function german_state_codes_provider(): array { return [ - 'Baden-Württemberg' => ['BW'], - 'Bavaria' => ['BY'], - 'Berlin' => ['BE'], - 'Brandenburg' => ['BB'], - 'Bremen' => ['HB'], - 'Hamburg' => ['HH'], - 'Hesse' => ['HE'], - 'Lower Saxony' => ['NI'], - 'Mecklenburg-Vorpommern' => ['MV'], - 'North Rhine-Westphalia' => ['NW'], - 'Rhineland-Palatinate' => ['RP'], - 'Saarland' => ['SL'], - 'Saxony' => ['SN'], - 'Saxony-Anhalt' => ['ST'], - 'Schleswig-Holstein' => ['SH'], - 'Thuringia' => ['TH'], + 'Baden-Württemberg' => ['BW'], + 'Bavaria' => ['BY'], + 'Berlin' => ['BE'], + 'Brandenburg' => ['BB'], + 'Bremen' => ['HB'], + 'Hamburg' => ['HH'], + 'Hesse' => ['HE'], + 'Lower Saxony' => ['NI'], + 'Mecklenburg-Vorpommern' => ['MV'], + 'North Rhine-Westphalia' => ['NW'], + 'Rhineland-Palatinate' => ['RP'], + 'Saarland' => ['SL'], + 'Saxony' => ['SN'], + 'Saxony-Anhalt' => ['ST'], + 'Schleswig-Holstein' => ['SH'], + 'Thuringia' => ['TH'], ]; } diff --git a/tests/WP_Ultimo/Helpers/WooCommerce_API_Client_Test.php b/tests/WP_Ultimo/Helpers/WooCommerce_API_Client_Test.php index 78cd7a95d..2ac7597b5 100644 --- a/tests/WP_Ultimo/Helpers/WooCommerce_API_Client_Test.php +++ b/tests/WP_Ultimo/Helpers/WooCommerce_API_Client_Test.php @@ -201,8 +201,14 @@ public function test_get_addons() { return [ 'response' => ['code' => 200], 'body' => wp_json_encode([ - ['id' => 1, 'name' => 'Addon 1'], - ['id' => 2, 'name' => 'Addon 2'], + [ + 'id' => 1, + 'name' => 'Addon 1', + ], + [ + 'id' => 2, + 'name' => 'Addon 2', + ], ]), ]; }, 10, 3); diff --git a/tests/WP_Ultimo/Installers/Migrator_Test.php b/tests/WP_Ultimo/Installers/Migrator_Test.php index f9420f4ab..312901fa0 100644 --- a/tests/WP_Ultimo/Installers/Migrator_Test.php +++ b/tests/WP_Ultimo/Installers/Migrator_Test.php @@ -185,7 +185,7 @@ protected function create_legacy_tables(): void { * @param array $args Arguments to pass. * @return mixed */ - protected function invoke_method( string $method_name, array $args = [] ) { + protected function invoke_method(string $method_name, array $args = []) { $ref = new \ReflectionClass( $this->migrator ); $method = $ref->getMethod( $method_name ); $method->setAccessible( true ); @@ -198,7 +198,7 @@ protected function invoke_method( string $method_name, array $args = [] ) { * @param string $property_name The property name. * @return mixed */ - protected function get_property( string $property_name ) { + protected function get_property(string $property_name) { $ref = new \ReflectionClass( $this->migrator ); $prop = $ref->getProperty( $property_name ); $prop->setAccessible( true ); @@ -211,7 +211,7 @@ protected function get_property( string $property_name ) { * @param string $property_name The property name. * @param mixed $value The value to set. */ - protected function set_property( string $property_name, $value ): void { + protected function set_property(string $property_name, $value): void { $ref = new \ReflectionClass( $this->migrator ); $prop = $ref->getProperty( $property_name ); $prop->setAccessible( true ); @@ -335,7 +335,7 @@ public function test_is_legacy_network_is_inverse_of_is_migration_done(): void { */ public function test_get_errors_returns_empty_array_initially(): void { $this->migrator->errors = null; - $result = $this->migrator->get_errors(); + $result = $this->migrator->get_errors(); $this->assertIsArray( $result ); $this->assertEmpty( $result ); } @@ -344,8 +344,8 @@ public function test_get_errors_returns_empty_array_initially(): void { * Test get_errors returns unique errors. */ public function test_get_errors_returns_unique_values(): void { - $this->migrator->errors = [ 'error1', 'error1', 'error2' ]; - $result = $this->migrator->get_errors(); + $this->migrator->errors = ['error1', 'error1', 'error2']; + $result = $this->migrator->get_errors(); $this->assertCount( 2, $result ); $this->assertContains( 'error1', $result ); $this->assertContains( 'error2', $result ); @@ -356,7 +356,7 @@ public function test_get_errors_returns_unique_values(): void { */ public function test_get_errors_handles_non_array_errors(): void { $this->migrator->errors = 'some string error'; - $result = $this->migrator->get_errors(); + $result = $this->migrator->get_errors(); $this->assertIsArray( $result ); } @@ -364,8 +364,8 @@ public function test_get_errors_handles_non_array_errors(): void { * Test get_errors with multiple distinct errors. */ public function test_get_errors_returns_all_distinct_errors(): void { - $this->migrator->errors = [ 'err_a', 'err_b', 'err_c' ]; - $result = $this->migrator->get_errors(); + $this->migrator->errors = ['err_a', 'err_b', 'err_c']; + $result = $this->migrator->get_errors(); $this->assertCount( 3, $result ); } @@ -373,8 +373,8 @@ public function test_get_errors_returns_all_distinct_errors(): void { * Test get_errors deduplicates. */ public function test_get_errors_deduplicates(): void { - $this->migrator->errors = [ 'err', 'err', 'err', 'other' ]; - $result = $this->migrator->get_errors(); + $this->migrator->errors = ['err', 'err', 'err', 'other']; + $result = $this->migrator->get_errors(); $this->assertCount( 2, $result ); } @@ -387,7 +387,7 @@ public function test_get_errors_deduplicates(): void { */ public function test_get_back_traces_returns_empty_array_initially(): void { $this->migrator->back_traces = null; - $result = $this->migrator->get_back_traces(); + $result = $this->migrator->get_back_traces(); $this->assertIsArray( $result ); $this->assertEmpty( $result ); } @@ -396,8 +396,8 @@ public function test_get_back_traces_returns_empty_array_initially(): void { * Test get_back_traces returns unique traces. */ public function test_get_back_traces_returns_unique_values(): void { - $this->migrator->back_traces = [ 'trace1', 'trace1', 'trace2' ]; - $result = $this->migrator->get_back_traces(); + $this->migrator->back_traces = ['trace1', 'trace1', 'trace2']; + $result = $this->migrator->get_back_traces(); $this->assertCount( 2, $result ); } @@ -406,7 +406,7 @@ public function test_get_back_traces_returns_unique_values(): void { */ public function test_get_back_traces_handles_non_array(): void { $this->migrator->back_traces = false; - $result = $this->migrator->get_back_traces(); + $result = $this->migrator->get_back_traces(); $this->assertIsArray( $result ); } @@ -414,8 +414,8 @@ public function test_get_back_traces_handles_non_array(): void { * Test get_back_traces deduplicates traces. */ public function test_get_back_traces_deduplicates(): void { - $this->migrator->back_traces = [ 'trace', 'trace', 'unique' ]; - $result = $this->migrator->get_back_traces(); + $this->migrator->back_traces = ['trace', 'trace', 'unique']; + $result = $this->migrator->get_back_traces(); $this->assertCount( 2, $result ); } @@ -445,7 +445,7 @@ public function test_get_steps_dry_run_returns_only_dry_run_check(): void { */ public function test_get_steps_non_dry_run_returns_all_steps(): void { $_REQUEST['dry-run'] = '0'; - $steps = $this->migrator->get_steps(); + $steps = $this->migrator->get_steps(); $expected_keys = [ 'backup', @@ -486,9 +486,9 @@ public function test_get_steps_force_all_returns_all_steps(): void { */ public function test_get_steps_each_step_has_required_fields(): void { $_REQUEST['dry-run'] = '0'; - $steps = $this->migrator->get_steps(); + $steps = $this->migrator->get_steps(); - $required_fields = [ 'title', 'description', 'pending', 'installing', 'success', 'done', 'help' ]; + $required_fields = ['title', 'description', 'pending', 'installing', 'success', 'done', 'help']; foreach ( $steps as $key => $step ) { foreach ( $required_fields as $field ) { @@ -519,7 +519,7 @@ public function test_get_steps_dry_run_check_step_structure(): void { */ public function test_get_steps_non_dry_run_excludes_dry_run_check(): void { $_REQUEST['dry-run'] = '0'; - $steps = $this->migrator->get_steps(); + $steps = $this->migrator->get_steps(); $this->assertArrayNotHasKey( 'dry_run_check', $steps ); } @@ -533,7 +533,7 @@ public function test_get_steps_applies_filter(): void { $filter_called = false; add_filter( 'wu_get_migration_steps', - function ( $steps ) use ( &$filter_called ) { + function ($steps) use (&$filter_called) { $filter_called = true; return $steps; } @@ -554,7 +554,7 @@ public function test_get_steps_filter_can_add_custom_step(): void { add_filter( 'wu_get_migration_steps', - function ( $steps ) { + function ($steps) { $steps['custom_step'] = [ 'title' => 'Custom Step', 'description' => 'A custom migration step', @@ -586,8 +586,8 @@ public function test_get_old_settings_returns_null_when_no_settings(): void { $wpdb->delete( $wpdb->base_prefix . 'sitemeta', - [ 'meta_key' => 'wp-ultimo_settings' ], - [ '%s' ] + ['meta_key' => 'wp-ultimo_settings'], + ['%s'] ); $this->set_property( 'settings', null ); @@ -600,7 +600,10 @@ public function test_get_old_settings_returns_null_when_no_settings(): void { * Test get_old_settings returns cached value on second call. */ public function test_get_old_settings_returns_cached_value(): void { - $cached = [ 'currency' => 'USD', 'test_key' => 'test_value' ]; + $cached = [ + 'currency' => 'USD', + 'test_key' => 'test_value', + ]; $this->set_property( 'settings', $cached ); $result = $this->migrator->get_old_settings(); @@ -613,7 +616,10 @@ public function test_get_old_settings_returns_cached_value(): void { public function test_get_old_settings_reads_from_sitemeta(): void { global $wpdb; - $settings_data = [ 'currency' => 'EUR', 'enable_signup' => true ]; + $settings_data = [ + 'currency' => 'EUR', + 'enable_signup' => true, + ]; $wpdb->replace( $wpdb->base_prefix . 'sitemeta', @@ -622,7 +628,7 @@ public function test_get_old_settings_reads_from_sitemeta(): void { 'meta_key' => 'wp-ultimo_settings', 'meta_value' => serialize( $settings_data ), ], - [ '%d', '%s', '%s' ] + ['%d', '%s', '%s'] ); $this->set_property( 'settings', null ); @@ -633,8 +639,8 @@ public function test_get_old_settings_reads_from_sitemeta(): void { $wpdb->delete( $wpdb->base_prefix . 'sitemeta', - [ 'meta_key' => 'wp-ultimo_settings' ], - [ '%s' ] + ['meta_key' => 'wp-ultimo_settings'], + ['%s'] ); } @@ -656,7 +662,10 @@ public function test_get_old_setting_returns_default_when_no_settings(): void { * Test get_old_setting returns correct value when key exists. */ public function test_get_old_setting_returns_value_when_key_exists(): void { - $this->set_property( 'settings', [ 'currency' => 'GBP', 'precision' => 2 ] ); + $this->set_property( 'settings', [ + 'currency' => 'GBP', + 'precision' => 2, + ] ); $result = $this->migrator->get_old_setting( 'currency', 'USD' ); $this->assertSame( 'GBP', $result ); @@ -666,7 +675,7 @@ public function test_get_old_setting_returns_value_when_key_exists(): void { * Test get_old_setting returns default when key does not exist. */ public function test_get_old_setting_returns_default_when_key_missing(): void { - $this->set_property( 'settings', [ 'currency' => 'USD' ] ); + $this->set_property( 'settings', ['currency' => 'USD'] ); $result = $this->migrator->get_old_setting( 'missing_key', 'fallback' ); $this->assertSame( 'fallback', $result ); @@ -686,7 +695,7 @@ public function test_get_old_setting_default_is_false(): void { * Test get_old_setting returns integer value correctly. */ public function test_get_old_setting_returns_integer_value(): void { - $this->set_property( 'settings', [ 'precision' => 3 ] ); + $this->set_property( 'settings', ['precision' => 3] ); $result = $this->migrator->get_old_setting( 'precision', 2 ); $this->assertSame( 3, $result ); @@ -711,7 +720,7 @@ public function test_add_id_of_interest_adds_single_id(): void { * Test add_id_of_interest adds multiple IDs as array. */ public function test_add_id_of_interest_adds_array_of_ids(): void { - $this->migrator->add_id_of_interest( [ 1, 2, 3 ], 'plan_not_migrated', 'memberships' ); + $this->migrator->add_id_of_interest( [1, 2, 3], 'plan_not_migrated', 'memberships' ); $ids = $this->get_property( 'ids_of_interest' ); $this->assertArrayHasKey( 'memberships:plan_not_migrated', $ids ); @@ -781,7 +790,7 @@ public function test_log_ids_of_interest_handles_corrupted_data(): void { * Test log_ids_of_interest skips empty ID lists. */ public function test_log_ids_of_interest_skips_empty_id_lists(): void { - $this->set_property( 'ids_of_interest', [ 'customers:not_found' => [] ] ); + $this->set_property( 'ids_of_interest', ['customers:not_found' => []] ); $this->migrator->log_ids_of_interest(); $this->assertTrue( true ); @@ -791,7 +800,7 @@ public function test_log_ids_of_interest_skips_empty_id_lists(): void { * Test log_ids_of_interest processes non-empty ID lists. */ public function test_log_ids_of_interest_processes_non_empty_lists(): void { - $this->migrator->add_id_of_interest( [ 1, 2, 3 ], 'not_found', 'customers' ); + $this->migrator->add_id_of_interest( [1, 2, 3], 'not_found', 'customers' ); $this->migrator->log_ids_of_interest(); $this->assertTrue( true ); @@ -928,7 +937,7 @@ public function test_fake_register_settings_with_settings_no_throw(): void { * Test fake_register_settings adds wu_settings_section_core_fields filter. */ public function test_fake_register_settings_adds_filter(): void { - $this->migrator->fake_register_settings( [ 'test_key' => 'test_value' ] ); + $this->migrator->fake_register_settings( ['test_key' => 'test_value'] ); $this->assertNotFalse( has_filter( 'wu_settings_section_core_fields' ) ); } @@ -971,7 +980,7 @@ public function test_handle_respects_installer_callback_filter(): void { add_filter( 'wu_installer_test_step_callback', - function ( $callable ) use ( &$filter_called ) { + function ($callable) use (&$filter_called) { $filter_called = true; return null; } @@ -1243,7 +1252,7 @@ public function test_install_customers_skips_existing_customers(): void { 'price' => 0.00, 'created_at' => '2020-01-01 00:00:00', ], - [ '%d', '%d', '%f', '%s' ] + ['%d', '%d', '%f', '%s'] ); $this->set_property( 'dry_run', true ); @@ -1299,7 +1308,7 @@ public function test_install_memberships_with_subscription_data(): void { 'created_at' => '2020-01-01 00:00:00', 'gateway' => null, ], - [ '%d', '%d', '%f', '%d', '%s', '%s', '%s', '%s' ] + ['%d', '%d', '%f', '%d', '%s', '%s', '%s', '%s'] ); $this->set_property( 'dry_run', true ); @@ -1334,7 +1343,7 @@ public function test_install_memberships_freq_3_quarterly(): void { 'created_at' => '2020-01-01 00:00:00', 'gateway' => null, ], - [ '%d', '%d', '%f', '%d', '%s', '%s', '%s', '%s' ] + ['%d', '%d', '%f', '%d', '%s', '%s', '%s', '%s'] ); $this->set_property( 'dry_run', true ); @@ -1369,7 +1378,7 @@ public function test_install_memberships_freq_12_annual(): void { 'created_at' => '2020-01-01 00:00:00', 'gateway' => null, ], - [ '%d', '%d', '%f', '%d', '%s', '%s', '%s', '%s' ] + ['%d', '%d', '%f', '%d', '%s', '%s', '%s', '%s'] ); $this->set_property( 'dry_run', true ); @@ -1404,7 +1413,7 @@ public function test_install_memberships_with_trial(): void { 'created_at' => '2020-01-01 00:00:00', 'gateway' => null, ], - [ '%d', '%d', '%f', '%d', '%s', '%s', '%s', '%s' ] + ['%d', '%d', '%f', '%d', '%s', '%s', '%s', '%s'] ); $this->set_property( 'dry_run', true ); @@ -1427,7 +1436,7 @@ public function test_install_memberships_stripe_gateway(): void { $user_id = wp_create_user( 'teststripe', 'password', 'teststripe@example.com' ); - $meta = serialize( (object) [ 'subscription_id' => 'sub_test123' ] ); + $meta = serialize( (object) ['subscription_id' => 'sub_test123'] ); $wpdb->insert( $wpdb->base_prefix . 'wu_subscriptions', @@ -1444,7 +1453,7 @@ public function test_install_memberships_stripe_gateway(): void { 'integration_status' => 1, 'meta_object' => $meta, ], - [ '%d', '%d', '%f', '%d', '%s', '%s', '%s', '%s', '%s', '%d', '%s' ] + ['%d', '%d', '%f', '%d', '%s', '%s', '%s', '%s', '%s', '%d', '%s'] ); $this->set_property( 'dry_run', true ); @@ -1482,7 +1491,7 @@ public function test_install_memberships_paypal_gateway(): void { 'integration_status' => 0, 'meta_object' => null, ], - [ '%d', '%d', '%f', '%d', '%s', '%s', '%s', '%s', '%s', '%d', '%s' ] + ['%d', '%d', '%f', '%d', '%s', '%s', '%s', '%s', '%s', '%d', '%s'] ); $this->set_property( 'dry_run', true ); @@ -1531,7 +1540,7 @@ public function test_install_transactions_skips_recurring_setup_and_cancel(): vo 'description' => 'Recurring setup', 'time' => '2020-01-01 00:00:00', ], - [ '%d', '%f', '%s', '%s', '%s' ] + ['%d', '%f', '%s', '%s', '%s'] ); $wpdb->insert( @@ -1543,7 +1552,7 @@ public function test_install_transactions_skips_recurring_setup_and_cancel(): vo 'description' => 'Cancel', 'time' => '2020-01-01 00:00:00', ], - [ '%d', '%f', '%s', '%s', '%s' ] + ['%d', '%f', '%s', '%s', '%s'] ); $this->set_property( 'dry_run', true ); @@ -1577,7 +1586,7 @@ public function test_install_transactions_processes_payment_type(): void { 'reference_id' => 'ch_test123', 'time' => '2020-01-01 00:00:00', ], - [ '%d', '%d', '%f', '%s', '%s', '%s', '%s', '%s' ] + ['%d', '%d', '%f', '%s', '%s', '%s', '%s', '%s'] ); $this->set_property( 'dry_run', true ); @@ -1599,7 +1608,7 @@ public function test_install_transactions_handles_failed_and_refund_types(): voi $user_id = wp_create_user( 'testtxfail', 'password', 'testtxfail@example.com' ); - foreach ( [ 'failed', 'refund', 'pending' ] as $type ) { + foreach ( ['failed', 'refund', 'pending'] as $type ) { $wpdb->insert( $wpdb->base_prefix . 'wu_transactions', [ @@ -1609,7 +1618,7 @@ public function test_install_transactions_handles_failed_and_refund_types(): voi 'description' => ucfirst( $type ) . ' transaction', 'time' => '2020-01-01 00:00:00', ], - [ '%d', '%f', '%s', '%s', '%s' ] + ['%d', '%f', '%s', '%s', '%s'] ); } @@ -1692,7 +1701,7 @@ public function test_install_sites_skips_nonexistent_sites(): void { 'site_id' => 99999, 'user_id' => $user_id, ], - [ '%d', '%d' ] + ['%d', '%d'] ); $this->set_property( 'dry_run', true ); @@ -1731,7 +1740,7 @@ public function test_install_domains_empty_table_no_error(): void { $wpdb->query( "TRUNCATE TABLE `{$wpdb->base_prefix}domain_mapping`" ); $this->set_property( 'dry_run', true ); - $this->set_property( 'settings', [ 'force_mapped_https' => true ] ); + $this->set_property( 'settings', ['force_mapped_https' => true] ); $this->invoke_method( '_install_domains' ); $this->assertTrue( true ); @@ -1752,11 +1761,11 @@ public function test_install_domains_processes_domains(): void { 'domain' => 'test-migrator-domain-' . uniqid() . '.example.com', 'active' => 1, ], - [ '%d', '%s', '%d' ] + ['%d', '%s', '%d'] ); $this->set_property( 'dry_run', true ); - $this->set_property( 'settings', [ 'force_mapped_https' => false ] ); + $this->set_property( 'settings', ['force_mapped_https' => false] ); $this->invoke_method( '_install_domains' ); $this->assertTrue( true ); @@ -1891,7 +1900,7 @@ public function test_install_dry_run_check_runs_all_steps(): void { * Test add_id_of_interest followed by log_ids_of_interest completes without error. */ public function test_add_and_log_ids_of_interest_round_trip(): void { - $this->migrator->add_id_of_interest( [ 100, 200 ], 'not_found', 'customers' ); + $this->migrator->add_id_of_interest( [100, 200], 'not_found', 'customers' ); $this->migrator->add_id_of_interest( 300, 'plan_not_migrated', 'memberships' ); $this->migrator->log_ids_of_interest(); diff --git a/tests/WP_Ultimo/Installers/Multisite_Network_Installer_Test.php b/tests/WP_Ultimo/Installers/Multisite_Network_Installer_Test.php index 981828a49..534c95877 100644 --- a/tests/WP_Ultimo/Installers/Multisite_Network_Installer_Test.php +++ b/tests/WP_Ultimo/Installers/Multisite_Network_Installer_Test.php @@ -74,8 +74,8 @@ public function tearDown(): void { unset( $plugins[ WP_ULTIMO_PLUGIN_BASENAME ] ); $wpdb->update( $this->sitemeta_table, - array( 'meta_value' => serialize( $plugins ) ), - array( 'meta_id' => $row->meta_id ) + array('meta_value' => serialize( $plugins )), + array('meta_id' => $row->meta_id) ); } } @@ -139,7 +139,7 @@ public function test_get_steps_contains_expected_keys(): void { */ public function test_get_steps_each_step_has_required_keys(): void { - $required = array( 'done', 'title', 'description', 'pending', 'installing', 'success' ); + $required = array('done', 'title', 'description', 'pending', 'installing', 'success'); foreach ( $this->installer->get_steps() as $key => $step ) { foreach ( $required as $field ) { @@ -327,8 +327,8 @@ public function test_install_network_activate_returns_early_when_already_active( if ( $row ) { $wpdb->update( $this->sitemeta_table, - array( 'meta_value' => serialize( $plugins ) ), - array( 'meta_id' => $row->meta_id ) + array('meta_value' => serialize( $plugins )), + array('meta_id' => $row->meta_id) ); } else { $wpdb->insert( @@ -361,7 +361,7 @@ public function test_install_network_activate_preserves_existing_plugins(): void $existing_plugin = 'some-other-plugin/plugin.php'; // Pre-populate sitemeta with a different plugin already active. - $plugins = array( $existing_plugin => time() ); + $plugins = array($existing_plugin => time()); $row = $wpdb->get_row( $wpdb->prepare( @@ -374,8 +374,8 @@ public function test_install_network_activate_preserves_existing_plugins(): void if ( $row ) { $wpdb->update( $this->sitemeta_table, - array( 'meta_value' => serialize( $plugins ) ), - array( 'meta_id' => $row->meta_id ) + array('meta_value' => serialize( $plugins )), + array('meta_id' => $row->meta_id) ); } else { $wpdb->insert( diff --git a/tests/WP_Ultimo/Integrations/Host_Providers/Base_Host_Provider_Test.php b/tests/WP_Ultimo/Integrations/Host_Providers/Base_Host_Provider_Test.php index b332d0579..ea2368c70 100644 --- a/tests/WP_Ultimo/Integrations/Host_Providers/Base_Host_Provider_Test.php +++ b/tests/WP_Ultimo/Integrations/Host_Providers/Base_Host_Provider_Test.php @@ -743,7 +743,11 @@ public function test_get_dns_records_returns_wp_error(): void { */ public function test_create_dns_record_returns_wp_error(): void { - $result = $this->provider->create_dns_record('example.com', ['type' => 'A', 'name' => 'test', 'content' => '1.2.3.4']); + $result = $this->provider->create_dns_record('example.com', [ + 'type' => 'A', + 'name' => 'test', + 'content' => '1.2.3.4', + ]); $this->assertInstanceOf(\WP_Error::class, $result); $this->assertSame('dns-not-supported', $result->get_error_code()); @@ -758,7 +762,10 @@ public function test_create_dns_record_returns_wp_error(): void { */ public function test_update_dns_record_returns_wp_error(): void { - $result = $this->provider->update_dns_record('example.com', 'record-1', ['type' => 'A', 'content' => '1.2.3.5']); + $result = $this->provider->update_dns_record('example.com', 'record-1', [ + 'type' => 'A', + 'content' => '1.2.3.5', + ]); $this->assertInstanceOf(\WP_Error::class, $result); $this->assertSame('dns-not-supported', $result->get_error_code()); diff --git a/tests/WP_Ultimo/Integrations/Host_Providers/CPanel_Host_Provider_Test.php b/tests/WP_Ultimo/Integrations/Host_Providers/CPanel_Host_Provider_Test.php index 2deb50284..eb79e760b 100644 --- a/tests/WP_Ultimo/Integrations/Host_Providers/CPanel_Host_Provider_Test.php +++ b/tests/WP_Ultimo/Integrations/Host_Providers/CPanel_Host_Provider_Test.php @@ -100,11 +100,11 @@ private function make_api2_success(string $reason = 'OK'): \stdClass { $data = new \stdClass(); $data->reason = $reason; - $result = new \stdClass(); - $result->data = [$data]; + $result = new \stdClass(); + $result->data = [$data]; $result->cpanelresult = $result; // Self-reference for log_calls. - $root = new \stdClass(); + $root = new \stdClass(); $root->cpanelresult = $result; return $root; @@ -511,7 +511,7 @@ public function test_log_calls_with_array_data(): void { $cpanelresult = new \stdClass(); $cpanelresult->data = [$data]; - $results = new \stdClass(); + $results = new \stdClass(); $results->cpanelresult = $cpanelresult; // Should not throw. @@ -531,7 +531,7 @@ public function test_log_calls_with_object_data(): void { $cpanelresult = new \stdClass(); $cpanelresult->data = $data; // Object, not array. - $results = new \stdClass(); + $results = new \stdClass(); $results->cpanelresult = $cpanelresult; // Should not throw. @@ -548,7 +548,7 @@ public function test_log_calls_with_missing_data_logs_error(): void { $cpanelresult = new \stdClass(); $cpanelresult->data = []; // Empty array — no data[0]. - $results = new \stdClass(); + $results = new \stdClass(); $results->cpanelresult = $cpanelresult; // Should not throw. diff --git a/tests/WP_Ultimo/Integrations/Host_Providers/Cloudflare_Host_Provider_Test.php b/tests/WP_Ultimo/Integrations/Host_Providers/Cloudflare_Host_Provider_Test.php index 332c42026..c80faf7cc 100644 --- a/tests/WP_Ultimo/Integrations/Host_Providers/Cloudflare_Host_Provider_Test.php +++ b/tests/WP_Ultimo/Integrations/Host_Providers/Cloudflare_Host_Provider_Test.php @@ -64,16 +64,19 @@ public function tear_down(): void { * @param array $result_info Optional result_info (e.g. pagination). * @return array WordPress HTTP response array. */ - private function make_cf_response( $result, array $result_info = [] ): array { + private function make_cf_response($result, array $result_info = []): array { - $body = [ 'result' => $result ]; + $body = ['result' => $result]; if ( ! empty( $result_info ) ) { $body['result_info'] = $result_info; } return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], 'body' => wp_json_encode( $body ), ]; } @@ -86,10 +89,13 @@ private function make_cf_response( $result, array $result_info = [] ): array { * @param string $body Response body. * @return array WordPress HTTP response array. */ - private function make_cf_error_response( int $code = 403, string $message = 'Forbidden', string $body = '{"errors":[{"message":"Invalid API key"}]}' ): array { + private function make_cf_error_response(int $code = 403, string $message = 'Forbidden', string $body = '{"errors":[{"message":"Invalid API key"}]}'): array { return [ - 'response' => [ 'code' => $code, 'message' => $message ], + 'response' => [ + 'code' => $code, + 'message' => $message, + ], 'body' => $body, ]; } @@ -102,11 +108,11 @@ private function make_cf_error_response( int $code = 403, string $message = 'For * @param string $url_fragment Substring that must appear in the request URL. * @return void */ - private function mock_http( array $response, string $url_fragment = '' ): void { + private function mock_http(array $response, string $url_fragment = ''): void { add_filter( 'pre_http_request', - function ( $preempt, $args, $url ) use ( $response, $url_fragment ) { + function ($preempt, $args, $url) use ($response, $url_fragment) { if ( '' === $url_fragment || str_contains( $url, $url_fragment ) ) { return $response; } @@ -125,11 +131,11 @@ function ( $preempt, $args, $url ) use ( $response, $url_fragment ) { * @param string $message Error message. * @return void */ - private function mock_http_wp_error( string $code = 'http-error', string $message = 'Connection failed' ): void { + private function mock_http_wp_error(string $code = 'http-error', string $message = 'Connection failed'): void { add_filter( 'pre_http_request', - function () use ( $code, $message ) { + function () use ($code, $message) { return new \WP_Error( $code, $message ); }, 10, @@ -329,7 +335,7 @@ public function test_additional_hooks_registers_dns_filter(): void { $this->provider->additional_hooks(); - $this->assertIsInt( has_filter( 'wu_domain_dns_get_record', [ $this->provider, 'add_cloudflare_dns_entries' ] ) ); + $this->assertIsInt( has_filter( 'wu_domain_dns_get_record', [$this->provider, 'add_cloudflare_dns_entries'] ) ); } // ------------------------------------------------------------------------- @@ -384,8 +390,8 @@ public function test_get_supported_record_types_returns_expected_types(): void { */ public function test_get_zone_id_returns_zone_id_from_api(): void { - $zone = (object) [ 'id' => 'zone-abc-123' ]; - $this->mock_http( $this->make_cf_response( [ $zone ] ), 'client/v4/zones' ); + $zone = (object) ['id' => 'zone-abc-123']; + $this->mock_http( $this->make_cf_response( [$zone] ), 'client/v4/zones' ); $result = $this->provider->get_zone_id( 'example.com' ); @@ -433,24 +439,30 @@ public function test_get_zone_id_returns_null_when_api_errors_and_no_constant(): public function test_get_zone_id_iterates_domain_parts(): void { $callCount = 0; - $zone = (object) [ 'id' => 'zone-from-root' ]; + $zone = (object) ['id' => 'zone-from-root']; add_filter( 'pre_http_request', - function ( $preempt, $args, $url ) use ( &$callCount, $zone ) { + function ($preempt, $args, $url) use (&$callCount, $zone) { ++$callCount; // Return empty for the first call (sub.example.com), zone on second (example.com). if ( $callCount === 1 ) { return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], - 'body' => wp_json_encode( [ 'result' => [] ] ), + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], + 'body' => wp_json_encode( ['result' => []] ), ]; } return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], - 'body' => wp_json_encode( [ 'result' => [ $zone ] ] ), + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], + 'body' => wp_json_encode( ['result' => [$zone]] ), ]; }, 10, @@ -490,20 +502,23 @@ public function test_get_dns_records_returns_wp_error_when_zone_not_found(): voi */ public function test_get_dns_records_returns_wp_error_on_api_failure(): void { - $zone = (object) [ 'id' => 'zone-xyz' ]; + $zone = (object) ['id' => 'zone-xyz']; $callCount = 0; add_filter( 'pre_http_request', - function ( $preempt, $args, $url ) use ( &$callCount, $zone ) { + function ($preempt, $args, $url) use (&$callCount, $zone) { ++$callCount; // First call: zone lookup succeeds. if ( $callCount === 1 ) { return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], - 'body' => wp_json_encode( [ 'result' => [ $zone ] ] ), + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], + 'body' => wp_json_encode( ['result' => [$zone]] ), ]; } @@ -524,25 +539,31 @@ function ( $preempt, $args, $url ) use ( &$callCount, $zone ) { */ public function test_get_dns_records_returns_wp_error_on_invalid_response(): void { - $zone = (object) [ 'id' => 'zone-xyz' ]; + $zone = (object) ['id' => 'zone-xyz']; $callCount = 0; add_filter( 'pre_http_request', - function ( $preempt, $args, $url ) use ( &$callCount, $zone ) { + function ($preempt, $args, $url) use (&$callCount, $zone) { ++$callCount; if ( $callCount === 1 ) { return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], - 'body' => wp_json_encode( [ 'result' => [ $zone ] ] ), + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], + 'body' => wp_json_encode( ['result' => [$zone]] ), ]; } // Invalid response — no 'result' key. return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], - 'body' => wp_json_encode( [ 'success' => true ] ), + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], + 'body' => wp_json_encode( ['success' => true] ), ]; }, 10, @@ -560,7 +581,7 @@ function ( $preempt, $args, $url ) use ( &$callCount, $zone ) { */ public function test_get_dns_records_returns_array_on_success(): void { - $zone = (object) [ 'id' => 'zone-success' ]; + $zone = (object) ['id' => 'zone-success']; $record = (object) [ 'id' => 'rec-001', @@ -577,23 +598,29 @@ public function test_get_dns_records_returns_array_on_success(): void { add_filter( 'pre_http_request', - function ( $preempt, $args, $url ) use ( &$callCount, $zone, $record ) { + function ($preempt, $args, $url) use (&$callCount, $zone, $record) { ++$callCount; if ( $callCount === 1 ) { // Zone lookup. return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], - 'body' => wp_json_encode( [ 'result' => [ $zone ] ] ), + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], + 'body' => wp_json_encode( ['result' => [$zone]] ), ]; } // DNS records page 1 (only page). return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], 'body' => wp_json_encode( [ - 'result' => [ $record ], - 'result_info' => [ 'total_pages' => 1 ], + 'result' => [$record], + 'result_info' => ['total_pages' => 1], ] ), ]; }, @@ -612,7 +639,7 @@ function ( $preempt, $args, $url ) use ( &$callCount, $zone, $record ) { */ public function test_get_dns_records_filters_unsupported_types(): void { - $zone = (object) [ 'id' => 'zone-filter' ]; + $zone = (object) ['id' => 'zone-filter']; $supported_record = (object) [ 'id' => 'rec-a', @@ -640,21 +667,27 @@ public function test_get_dns_records_filters_unsupported_types(): void { add_filter( 'pre_http_request', - function ( $preempt, $args, $url ) use ( &$callCount, $zone, $supported_record, $unsupported_record ) { + function ($preempt, $args, $url) use (&$callCount, $zone, $supported_record, $unsupported_record) { ++$callCount; if ( $callCount === 1 ) { return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], - 'body' => wp_json_encode( [ 'result' => [ $zone ] ] ), + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], + 'body' => wp_json_encode( ['result' => [$zone]] ), ]; } return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], 'body' => wp_json_encode( [ - 'result' => [ $supported_record, $unsupported_record ], - 'result_info' => [ 'total_pages' => 1 ], + 'result' => [$supported_record, $unsupported_record], + 'result_info' => ['total_pages' => 1], ] ), ]; }, @@ -674,7 +707,7 @@ function ( $preempt, $args, $url ) use ( &$callCount, $zone, $supported_record, */ public function test_get_dns_records_paginates(): void { - $zone = (object) [ 'id' => 'zone-paginate' ]; + $zone = (object) ['id' => 'zone-paginate']; $record1 = (object) [ 'id' => 'rec-p1', @@ -702,34 +735,43 @@ public function test_get_dns_records_paginates(): void { add_filter( 'pre_http_request', - function ( $preempt, $args, $url ) use ( &$callCount, $zone, $record1, $record2 ) { + function ($preempt, $args, $url) use (&$callCount, $zone, $record1, $record2) { ++$callCount; if ( $callCount === 1 ) { // Zone lookup. return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], - 'body' => wp_json_encode( [ 'result' => [ $zone ] ] ), + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], + 'body' => wp_json_encode( ['result' => [$zone]] ), ]; } if ( $callCount === 2 ) { // Page 1 of 2. return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], 'body' => wp_json_encode( [ - 'result' => [ $record1 ], - 'result_info' => [ 'total_pages' => 2 ], + 'result' => [$record1], + 'result_info' => ['total_pages' => 2], ] ), ]; } // Page 2 of 2. return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], 'body' => wp_json_encode( [ - 'result' => [ $record2 ], - 'result_info' => [ 'total_pages' => 2 ], + 'result' => [$record2], + 'result_info' => ['total_pages' => 2], ] ), ]; }, @@ -774,18 +816,21 @@ public function test_create_dns_record_returns_wp_error_when_zone_not_found(): v */ public function test_create_dns_record_returns_wp_error_on_api_failure(): void { - $zone = (object) [ 'id' => 'zone-create' ]; + $zone = (object) ['id' => 'zone-create']; $callCount = 0; add_filter( 'pre_http_request', - function ( $preempt, $args, $url ) use ( &$callCount, $zone ) { + function ($preempt, $args, $url) use (&$callCount, $zone) { ++$callCount; if ( $callCount === 1 ) { return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], - 'body' => wp_json_encode( [ 'result' => [ $zone ] ] ), + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], + 'body' => wp_json_encode( ['result' => [$zone]] ), ]; } @@ -809,25 +854,31 @@ function ( $preempt, $args, $url ) use ( &$callCount, $zone ) { */ public function test_create_dns_record_returns_wp_error_on_invalid_response(): void { - $zone = (object) [ 'id' => 'zone-create-invalid' ]; + $zone = (object) ['id' => 'zone-create-invalid']; $callCount = 0; add_filter( 'pre_http_request', - function ( $preempt, $args, $url ) use ( &$callCount, $zone ) { + function ($preempt, $args, $url) use (&$callCount, $zone) { ++$callCount; if ( $callCount === 1 ) { return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], - 'body' => wp_json_encode( [ 'result' => [ $zone ] ] ), + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], + 'body' => wp_json_encode( ['result' => [$zone]] ), ]; } // No 'result' key in response. return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], - 'body' => wp_json_encode( [ 'success' => true ] ), + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], + 'body' => wp_json_encode( ['success' => true] ), ]; }, 10, @@ -849,7 +900,7 @@ function ( $preempt, $args, $url ) use ( &$callCount, $zone ) { */ public function test_create_dns_record_returns_array_on_success(): void { - $zone = (object) [ 'id' => 'zone-create-ok' ]; + $zone = (object) ['id' => 'zone-create-ok']; $created = (object) [ 'id' => 'rec-new', 'type' => 'A', @@ -862,19 +913,25 @@ public function test_create_dns_record_returns_array_on_success(): void { add_filter( 'pre_http_request', - function ( $preempt, $args, $url ) use ( &$callCount, $zone, $created ) { + function ($preempt, $args, $url) use (&$callCount, $zone, $created) { ++$callCount; if ( $callCount === 1 ) { return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], - 'body' => wp_json_encode( [ 'result' => [ $zone ] ] ), + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], + 'body' => wp_json_encode( ['result' => [$zone]] ), ]; } return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], - 'body' => wp_json_encode( [ 'result' => $created ] ), + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], + 'body' => wp_json_encode( ['result' => $created] ), ]; }, 10, @@ -898,7 +955,7 @@ function ( $preempt, $args, $url ) use ( &$callCount, $zone, $created ) { */ public function test_create_dns_record_strips_proxied_for_mx(): void { - $zone = (object) [ 'id' => 'zone-mx' ]; + $zone = (object) ['id' => 'zone-mx']; $created = (object) [ 'id' => 'rec-mx', 'type' => 'MX', @@ -912,21 +969,27 @@ public function test_create_dns_record_strips_proxied_for_mx(): void { add_filter( 'pre_http_request', - function ( $preempt, $args, $url ) use ( &$callCount, &$sentBody, $zone, $created ) { + function ($preempt, $args, $url) use (&$callCount, &$sentBody, $zone, $created) { ++$callCount; if ( $callCount === 1 ) { return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], - 'body' => wp_json_encode( [ 'result' => [ $zone ] ] ), + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], + 'body' => wp_json_encode( ['result' => [$zone]] ), ]; } $sentBody = json_decode( $args['body'], true ); return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], - 'body' => wp_json_encode( [ 'result' => $created ] ), + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], + 'body' => wp_json_encode( ['result' => $created] ), ]; }, 10, @@ -955,7 +1018,7 @@ function ( $preempt, $args, $url ) use ( &$callCount, &$sentBody, $zone, $create */ public function test_create_dns_record_strips_proxied_for_txt(): void { - $zone = (object) [ 'id' => 'zone-txt' ]; + $zone = (object) ['id' => 'zone-txt']; $created = (object) [ 'id' => 'rec-txt', 'type' => 'TXT', @@ -968,21 +1031,27 @@ public function test_create_dns_record_strips_proxied_for_txt(): void { add_filter( 'pre_http_request', - function ( $preempt, $args, $url ) use ( &$callCount, &$sentBody, $zone, $created ) { + function ($preempt, $args, $url) use (&$callCount, &$sentBody, $zone, $created) { ++$callCount; if ( $callCount === 1 ) { return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], - 'body' => wp_json_encode( [ 'result' => [ $zone ] ] ), + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], + 'body' => wp_json_encode( ['result' => [$zone]] ), ]; } $sentBody = json_decode( $args['body'], true ); return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], - 'body' => wp_json_encode( [ 'result' => $created ] ), + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], + 'body' => wp_json_encode( ['result' => $created] ), ]; }, 10, @@ -1031,18 +1100,21 @@ public function test_update_dns_record_returns_wp_error_when_zone_not_found(): v */ public function test_update_dns_record_returns_wp_error_on_api_failure(): void { - $zone = (object) [ 'id' => 'zone-update' ]; + $zone = (object) ['id' => 'zone-update']; $callCount = 0; add_filter( 'pre_http_request', - function ( $preempt, $args, $url ) use ( &$callCount, $zone ) { + function ($preempt, $args, $url) use (&$callCount, $zone) { ++$callCount; if ( $callCount === 1 ) { return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], - 'body' => wp_json_encode( [ 'result' => [ $zone ] ] ), + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], + 'body' => wp_json_encode( ['result' => [$zone]] ), ]; } @@ -1066,24 +1138,30 @@ function ( $preempt, $args, $url ) use ( &$callCount, $zone ) { */ public function test_update_dns_record_returns_wp_error_on_invalid_response(): void { - $zone = (object) [ 'id' => 'zone-update-invalid' ]; + $zone = (object) ['id' => 'zone-update-invalid']; $callCount = 0; add_filter( 'pre_http_request', - function ( $preempt, $args, $url ) use ( &$callCount, $zone ) { + function ($preempt, $args, $url) use (&$callCount, $zone) { ++$callCount; if ( $callCount === 1 ) { return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], - 'body' => wp_json_encode( [ 'result' => [ $zone ] ] ), + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], + 'body' => wp_json_encode( ['result' => [$zone]] ), ]; } return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], - 'body' => wp_json_encode( [ 'success' => true ] ), + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], + 'body' => wp_json_encode( ['success' => true] ), ]; }, 10, @@ -1105,7 +1183,7 @@ function ( $preempt, $args, $url ) use ( &$callCount, $zone ) { */ public function test_update_dns_record_returns_array_on_success(): void { - $zone = (object) [ 'id' => 'zone-update-ok' ]; + $zone = (object) ['id' => 'zone-update-ok']; $updated = (object) [ 'id' => 'rec-123', 'type' => 'A', @@ -1118,19 +1196,25 @@ public function test_update_dns_record_returns_array_on_success(): void { add_filter( 'pre_http_request', - function ( $preempt, $args, $url ) use ( &$callCount, $zone, $updated ) { + function ($preempt, $args, $url) use (&$callCount, $zone, $updated) { ++$callCount; if ( $callCount === 1 ) { return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], - 'body' => wp_json_encode( [ 'result' => [ $zone ] ] ), + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], + 'body' => wp_json_encode( ['result' => [$zone]] ), ]; } return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], - 'body' => wp_json_encode( [ 'result' => $updated ] ), + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], + 'body' => wp_json_encode( ['result' => $updated] ), ]; }, 10, @@ -1154,7 +1238,7 @@ function ( $preempt, $args, $url ) use ( &$callCount, $zone, $updated ) { */ public function test_update_dns_record_strips_proxied_for_mx(): void { - $zone = (object) [ 'id' => 'zone-update-mx' ]; + $zone = (object) ['id' => 'zone-update-mx']; $updated = (object) [ 'id' => 'rec-mx-upd', 'type' => 'MX', @@ -1168,21 +1252,27 @@ public function test_update_dns_record_strips_proxied_for_mx(): void { add_filter( 'pre_http_request', - function ( $preempt, $args, $url ) use ( &$callCount, &$sentBody, $zone, $updated ) { + function ($preempt, $args, $url) use (&$callCount, &$sentBody, $zone, $updated) { ++$callCount; if ( $callCount === 1 ) { return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], - 'body' => wp_json_encode( [ 'result' => [ $zone ] ] ), + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], + 'body' => wp_json_encode( ['result' => [$zone]] ), ]; } $sentBody = json_decode( $args['body'], true ); return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], - 'body' => wp_json_encode( [ 'result' => $updated ] ), + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], + 'body' => wp_json_encode( ['result' => $updated] ), ]; }, 10, @@ -1229,18 +1319,21 @@ public function test_delete_dns_record_returns_wp_error_when_zone_not_found(): v */ public function test_delete_dns_record_returns_wp_error_on_api_failure(): void { - $zone = (object) [ 'id' => 'zone-delete' ]; + $zone = (object) ['id' => 'zone-delete']; $callCount = 0; add_filter( 'pre_http_request', - function ( $preempt, $args, $url ) use ( &$callCount, $zone ) { + function ($preempt, $args, $url) use (&$callCount, $zone) { ++$callCount; if ( $callCount === 1 ) { return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], - 'body' => wp_json_encode( [ 'result' => [ $zone ] ] ), + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], + 'body' => wp_json_encode( ['result' => [$zone]] ), ]; } @@ -1260,24 +1353,30 @@ function ( $preempt, $args, $url ) use ( &$callCount, $zone ) { */ public function test_delete_dns_record_returns_true_on_success(): void { - $zone = (object) [ 'id' => 'zone-delete-ok' ]; + $zone = (object) ['id' => 'zone-delete-ok']; $callCount = 0; add_filter( 'pre_http_request', - function ( $preempt, $args, $url ) use ( &$callCount, $zone ) { + function ($preempt, $args, $url) use (&$callCount, $zone) { ++$callCount; if ( $callCount === 1 ) { return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], - 'body' => wp_json_encode( [ 'result' => [ $zone ] ] ), + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], + 'body' => wp_json_encode( ['result' => [$zone]] ), ]; } return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], - 'body' => wp_json_encode( [ 'result' => [] ] ), + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], + 'body' => wp_json_encode( ['result' => []] ), ]; }, 10, @@ -1305,7 +1404,14 @@ public function test_add_cloudflare_dns_entries_returns_original_when_no_zones() // API returns empty zones. $this->mock_http( $this->make_cf_response( [] ), 'client/v4/zones' ); - $original = [ [ 'type' => 'A', 'data' => '1.2.3.4', 'host' => 'example.com', 'ttl' => 300 ] ]; + $original = [ + [ + 'type' => 'A', + 'data' => '1.2.3.4', + 'host' => 'example.com', + 'ttl' => 300, + ], + ]; $result = $this->provider->add_cloudflare_dns_entries( $original, 'example.com' ); @@ -1321,7 +1427,7 @@ public function test_add_cloudflare_dns_entries_returns_original_when_no_zones() */ public function test_add_cloudflare_dns_entries_appends_entries(): void { - $zone = (object) [ 'id' => 'zone-dns-entries' ]; + $zone = (object) ['id' => 'zone-dns-entries']; $dns_entry = (object) [ 'ttl' => 1, 'content' => '1.2.3.4', @@ -1332,19 +1438,25 @@ public function test_add_cloudflare_dns_entries_appends_entries(): void { add_filter( 'pre_http_request', - function ( $preempt, $args, $url ) use ( $zone, $dns_entry ) { + function ($preempt, $args, $url) use ($zone, $dns_entry) { if ( str_contains( $url, 'dns_records' ) ) { // DNS records lookup — return one entry. return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], - 'body' => wp_json_encode( [ 'result' => [ $dns_entry ] ] ), + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], + 'body' => wp_json_encode( ['result' => [$dns_entry]] ), ]; } // Zone lookup. return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], - 'body' => wp_json_encode( [ 'result' => [ $zone ] ] ), + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], + 'body' => wp_json_encode( ['result' => [$zone]] ), ]; }, 10, @@ -1365,7 +1477,7 @@ function ( $preempt, $args, $url ) use ( $zone, $dns_entry ) { */ public function test_add_cloudflare_dns_entries_adds_proxied_tag(): void { - $zone = (object) [ 'id' => 'zone-proxied' ]; + $zone = (object) ['id' => 'zone-proxied']; $dns_entry = (object) [ 'ttl' => 1, 'content' => '1.2.3.4', @@ -1376,17 +1488,23 @@ public function test_add_cloudflare_dns_entries_adds_proxied_tag(): void { add_filter( 'pre_http_request', - function ( $preempt, $args, $url ) use ( $zone, $dns_entry ) { + function ($preempt, $args, $url) use ($zone, $dns_entry) { if ( str_contains( $url, 'dns_records' ) ) { return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], - 'body' => wp_json_encode( [ 'result' => [ $dns_entry ] ] ), + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], + 'body' => wp_json_encode( ['result' => [$dns_entry]] ), ]; } return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], - 'body' => wp_json_encode( [ 'result' => [ $zone ] ] ), + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], + 'body' => wp_json_encode( ['result' => [$zone]] ), ]; }, 10, @@ -1405,7 +1523,7 @@ function ( $preempt, $args, $url ) use ( $zone, $dns_entry ) { */ public function test_add_cloudflare_dns_entries_adds_not_proxied_tag(): void { - $zone = (object) [ 'id' => 'zone-not-proxied' ]; + $zone = (object) ['id' => 'zone-not-proxied']; $dns_entry = (object) [ 'ttl' => 3600, 'content' => '1.2.3.4', @@ -1416,17 +1534,23 @@ public function test_add_cloudflare_dns_entries_adds_not_proxied_tag(): void { add_filter( 'pre_http_request', - function ( $preempt, $args, $url ) use ( $zone, $dns_entry ) { + function ($preempt, $args, $url) use ($zone, $dns_entry) { if ( str_contains( $url, 'dns_records' ) ) { return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], - 'body' => wp_json_encode( [ 'result' => [ $dns_entry ] ] ), + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], + 'body' => wp_json_encode( ['result' => [$dns_entry]] ), ]; } return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], - 'body' => wp_json_encode( [ 'result' => [ $zone ] ] ), + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], + 'body' => wp_json_encode( ['result' => [$zone]] ), ]; }, 10, @@ -1449,29 +1573,42 @@ public function test_add_cloudflare_dns_entries_skips_empty_dns_results(): void $this->markTestSkipped( 'WU_CLOUDFLARE_ZONE_ID is defined — constant zone always present.' ); } - $zone = (object) [ 'id' => 'zone-empty-dns' ]; + $zone = (object) ['id' => 'zone-empty-dns']; add_filter( 'pre_http_request', - function ( $preempt, $args, $url ) use ( $zone ) { + function ($preempt, $args, $url) use ($zone) { if ( str_contains( $url, 'dns_records' ) ) { // Empty DNS entries. return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], - 'body' => wp_json_encode( [ 'result' => [] ] ), + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], + 'body' => wp_json_encode( ['result' => []] ), ]; } return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], - 'body' => wp_json_encode( [ 'result' => [ $zone ] ] ), + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], + 'body' => wp_json_encode( ['result' => [$zone]] ), ]; }, 10, 3 ); - $original = [ [ 'type' => 'A', 'data' => '5.5.5.5', 'host' => 'example.com', 'ttl' => 300 ] ]; + $original = [ + [ + 'type' => 'A', + 'data' => '5.5.5.5', + 'host' => 'example.com', + 'ttl' => 300, + ], + ]; $result = $this->provider->add_cloudflare_dns_entries( $original, 'example.com' ); // Original records unchanged — no Cloudflare entries appended. @@ -1496,7 +1633,7 @@ public function test_on_add_subdomain_returns_early_without_zone_id(): void { add_filter( 'pre_http_request', - function () use ( &$called ) { + function () use (&$called) { $called = true; return new \WP_Error( 'should-not-be-called', 'Should not be called' ); @@ -1528,7 +1665,7 @@ public function test_on_add_subdomain_returns_early_when_not_subdomain_of_curren add_filter( 'pre_http_request', - function () use ( &$called ) { + function () use (&$called) { $called = true; return new \WP_Error( 'should-not-be-called', 'Should not be called' ); @@ -1561,7 +1698,7 @@ public function test_on_add_subdomain_returns_early_when_subdomain_empty(): void add_filter( 'pre_http_request', - function () use ( &$called ) { + function () use (&$called) { $called = true; return new \WP_Error( 'should-not-be-called', 'Should not be called' ); @@ -1597,18 +1734,23 @@ public function test_on_add_subdomain_makes_api_call_for_valid_subdomain(): void add_filter( 'pre_http_request', - function ( $preempt, $args, $url ) use ( &$apiCalled ) { + function ($preempt, $args, $url) use (&$apiCalled) { if ( str_contains( $url, 'dns_records' ) ) { $apiCalled = true; return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], - 'body' => wp_json_encode( [ 'result' => (object) [ - 'id' => 'new-rec', - 'type' => 'CNAME', - 'name' => 'newsite.mynetwork.com', - 'content' => '@', - ] ] ), + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], + 'body' => wp_json_encode( [ + 'result' => (object) [ + 'id' => 'new-rec', + 'type' => 'CNAME', + 'name' => 'newsite.mynetwork.com', + 'content' => '@', + ], + ] ), ]; } @@ -1644,7 +1786,7 @@ public function test_on_add_subdomain_logs_error_on_api_failure(): void { add_filter( 'pre_http_request', - function ( $preempt, $args, $url ) { + function ($preempt, $args, $url) { if ( str_contains( $url, 'dns_records' ) ) { return new \WP_Error( 'api-fail', 'API failure' ); } @@ -1680,7 +1822,7 @@ public function test_on_remove_subdomain_returns_early_without_zone_id(): void { add_filter( 'pre_http_request', - function () use ( &$called ) { + function () use (&$called) { $called = true; return new \WP_Error( 'should-not-be-called', 'Should not be called' ); @@ -1712,7 +1854,7 @@ public function test_on_remove_subdomain_returns_early_when_not_subdomain_of_cur add_filter( 'pre_http_request', - function () use ( &$called ) { + function () use (&$called) { $called = true; return new \WP_Error( 'should-not-be-called', 'Should not be called' ); @@ -1744,7 +1886,7 @@ public function test_on_remove_subdomain_returns_early_when_subdomain_empty(): v add_filter( 'pre_http_request', - function () use ( &$called ) { + function () use (&$called) { $called = true; return new \WP_Error( 'should-not-be-called', 'Should not be called' ); @@ -1774,11 +1916,14 @@ public function test_on_remove_subdomain_returns_early_when_dns_entry_not_found( add_filter( 'pre_http_request', - function ( $preempt, $args, $url ) { + function ($preempt, $args, $url) { // DNS lookup returns empty result. return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], - 'body' => wp_json_encode( [ 'result' => [] ] ), + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], + 'body' => wp_json_encode( ['result' => []] ), ]; }, 10, @@ -1806,24 +1951,30 @@ public function test_on_remove_subdomain_makes_delete_api_call(): void { $current_site->domain = 'mynetwork.com'; $deleteCalled = false; - $dnsEntry = (object) [ 'id' => 'rec-to-delete' ]; + $dnsEntry = (object) ['id' => 'rec-to-delete']; add_filter( 'pre_http_request', - function ( $preempt, $args, $url ) use ( &$deleteCalled, $dnsEntry ) { + function ($preempt, $args, $url) use (&$deleteCalled, $dnsEntry) { if ( 'DELETE' === $args['method'] ) { $deleteCalled = true; return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], - 'body' => wp_json_encode( [ 'result' => [] ] ), + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], + 'body' => wp_json_encode( ['result' => []] ), ]; } // GET for DNS lookup. return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], - 'body' => wp_json_encode( [ 'result' => [ $dnsEntry ] ] ), + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], + 'body' => wp_json_encode( ['result' => [$dnsEntry]] ), ]; }, 10, @@ -1849,18 +2000,21 @@ public function test_on_remove_subdomain_logs_error_on_delete_failure(): void { $current_site = new \stdClass(); $current_site->domain = 'mynetwork.com'; - $dnsEntry = (object) [ 'id' => 'rec-fail-delete' ]; + $dnsEntry = (object) ['id' => 'rec-fail-delete']; add_filter( 'pre_http_request', - function ( $preempt, $args, $url ) use ( $dnsEntry ) { + function ($preempt, $args, $url) use ($dnsEntry) { if ( 'DELETE' === $args['method'] ) { return new \WP_Error( 'delete-fail', 'Delete failed' ); } return [ - 'response' => [ 'code' => 200, 'message' => 'OK' ], - 'body' => wp_json_encode( [ 'result' => [ $dnsEntry ] ] ), + 'response' => [ + 'code' => 200, + 'message' => 'OK', + ], + 'body' => wp_json_encode( ['result' => [$dnsEntry]] ), ]; }, 10, diff --git a/tests/WP_Ultimo/Integrations/Host_Providers/DNS_Record_Test.php b/tests/WP_Ultimo/Integrations/Host_Providers/DNS_Record_Test.php index a0801c9ee..0d6365ac1 100644 --- a/tests/WP_Ultimo/Integrations/Host_Providers/DNS_Record_Test.php +++ b/tests/WP_Ultimo/Integrations/Host_Providers/DNS_Record_Test.php @@ -312,11 +312,32 @@ public function test_from_provider_hestia() { * Test get_type_class returns correct CSS class for each type. */ public function test_get_type_class() { - $a_record = new DNS_Record(['type' => 'A', 'name' => 'test', 'content' => '1.1.1.1']); - $aaaa_record = new DNS_Record(['type' => 'AAAA', 'name' => 'test', 'content' => '::1']); - $cname_record = new DNS_Record(['type' => 'CNAME', 'name' => 'test', 'content' => 'target.com']); - $mx_record = new DNS_Record(['type' => 'MX', 'name' => 'test', 'content' => 'mail.test.com', 'priority' => 10]); - $txt_record = new DNS_Record(['type' => 'TXT', 'name' => 'test', 'content' => 'test']); + $a_record = new DNS_Record([ + 'type' => 'A', + 'name' => 'test', + 'content' => '1.1.1.1', + ]); + $aaaa_record = new DNS_Record([ + 'type' => 'AAAA', + 'name' => 'test', + 'content' => '::1', + ]); + $cname_record = new DNS_Record([ + 'type' => 'CNAME', + 'name' => 'test', + 'content' => 'target.com', + ]); + $mx_record = new DNS_Record([ + 'type' => 'MX', + 'name' => 'test', + 'content' => 'mail.test.com', + 'priority' => 10, + ]); + $txt_record = new DNS_Record([ + 'type' => 'TXT', + 'name' => 'test', + 'content' => 'test', + ]); $this->assertStringContainsString('blue', $a_record->get_type_class()); $this->assertStringContainsString('purple', $aaaa_record->get_type_class()); @@ -329,10 +350,20 @@ public function test_get_type_class() { * Test get_ttl_label returns correct human-readable format. */ public function test_get_ttl_label() { - $auto_record = new DNS_Record(['type' => 'A', 'name' => 'test', 'content' => '1.1.1.1', 'ttl' => 1]); + $auto_record = new DNS_Record([ + 'type' => 'A', + 'name' => 'test', + 'content' => '1.1.1.1', + 'ttl' => 1, + ]); $this->assertEquals('Auto', $auto_record->get_ttl_label()); - $hour_record = new DNS_Record(['type' => 'A', 'name' => 'test', 'content' => '1.1.1.1', 'ttl' => 3600]); + $hour_record = new DNS_Record([ + 'type' => 'A', + 'name' => 'test', + 'content' => '1.1.1.1', + 'ttl' => 3600, + ]); $this->assertEquals('1 hour', $hour_record->get_ttl_label()); } diff --git a/tests/WP_Ultimo/Integrations/Host_Providers/Hestia_Host_Provider_Test.php b/tests/WP_Ultimo/Integrations/Host_Providers/Hestia_Host_Provider_Test.php index 3c87a696c..9cda42988 100644 --- a/tests/WP_Ultimo/Integrations/Host_Providers/Hestia_Host_Provider_Test.php +++ b/tests/WP_Ultimo/Integrations/Host_Providers/Hestia_Host_Provider_Test.php @@ -102,7 +102,7 @@ public function set_up(): void { $this->http_response = null; // Install HTTP interceptor - add_filter( 'pre_http_request', [ $this, 'intercept_http_request' ], 10, 3 ); + add_filter( 'pre_http_request', [$this, 'intercept_http_request'], 10, 3 ); } /** @@ -110,7 +110,7 @@ public function set_up(): void { */ public function tear_down(): void { - remove_filter( 'pre_http_request', [ $this, 'intercept_http_request' ] ); + remove_filter( 'pre_http_request', [$this, 'intercept_http_request'] ); parent::tear_down(); } @@ -127,7 +127,7 @@ public function tear_down(): void { * @param string $url Request URL. * @return false|array|\WP_Error */ - public function intercept_http_request( $preempt, $args, $url ) { + public function intercept_http_request($preempt, $args, $url) { $this->http_requests[] = [ 'url' => $url, @@ -153,7 +153,7 @@ public function intercept_http_request( $preempt, $args, $url ) { * @param string $body Response body. * @return array */ - private function make_http_response( int $code, string $body ): array { + private function make_http_response(int $code, string $body): array { return [ 'headers' => [], @@ -180,7 +180,7 @@ private function queue_success(): void { * * @param mixed $data Data to JSON-encode. */ - private function queue_json( $data ): void { + private function queue_json($data): void { $this->http_response = $this->make_http_response( 200, wp_json_encode( $data ) ); } @@ -191,7 +191,7 @@ private function queue_json( $data ): void { * @param int $code HTTP status code. * @param string $body Response body. */ - private function queue_http_error( int $code, string $body ): void { + private function queue_http_error(int $code, string $body): void { $this->http_response = $this->make_http_response( $code, $body ); } @@ -201,7 +201,7 @@ private function queue_http_error( int $code, string $body ): void { * * @param string $message Error message. */ - private function queue_wp_error( string $message = 'Connection refused' ): void { + private function queue_wp_error(string $message = 'Connection refused'): void { $this->http_response = new \WP_Error( 'http_request_failed', $message ); } @@ -477,7 +477,7 @@ public function test_on_add_domain_skips_www_when_domain_starts_with_www(): void // Only one request (the primary alias); no www. prefix added $www_requests = array_filter( $this->http_requests, - function ( $req ) { + function ($req) { return isset( $req['args']['body']['arg3'] ) && str_starts_with( $req['args']['body']['arg3'], 'www.www.' ); } ); @@ -542,7 +542,7 @@ public function test_on_remove_domain_skips_extra_www_for_www_domain(): void { // Should only have 1 request (no www.www.) $www_www_requests = array_filter( $this->http_requests, - function ( $req ) { + function ($req) { return isset( $req['args']['body']['arg3'] ) && str_starts_with( $req['args']['body']['arg3'], 'www.www.' ); } ); @@ -581,7 +581,7 @@ public function test_send_hestia_request_returns_error_when_no_url(): void { $this->queue_wp_error( 'Connection refused' ); $method = $this->get_send_request_method(); - $result = $method->invoke( $this->provider, 'v-list-web-domains', [ 'admin' ] ); + $result = $method->invoke( $this->provider, 'v-list-web-domains', ['admin'] ); $this->assertInstanceOf( \WP_Error::class, $result ); } @@ -594,7 +594,7 @@ public function test_send_hestia_request_returns_zero_on_success(): void { $this->queue_success(); $method = $this->get_send_request_method(); - $result = $method->invoke( $this->provider, 'v-add-web-domain-alias', [ 'admin', 'mysite.com', 'example.com', 'yes' ] ); + $result = $method->invoke( $this->provider, 'v-add-web-domain-alias', ['admin', 'mysite.com', 'example.com', 'yes'] ); $this->assertSame( '0', $result ); } @@ -618,11 +618,18 @@ public function test_send_hestia_request_returns_error_on_non_200(): void { */ public function test_send_hestia_request_decodes_json_response(): void { - $data = [ 'DOMAIN1' => [ 'TYPE' => 'A', 'RECORD' => '@', 'VALUE' => '1.2.3.4', 'TTL' => 3600 ] ]; + $data = [ + 'DOMAIN1' => [ + 'TYPE' => 'A', + 'RECORD' => '@', + 'VALUE' => '1.2.3.4', + 'TTL' => 3600, + ], + ]; $this->queue_json( $data ); $method = $this->get_send_request_method(); - $result = $method->invoke( $this->provider, 'v-list-dns-records', [ 'admin', 'example.com', 'json' ] ); + $result = $method->invoke( $this->provider, 'v-list-dns-records', ['admin', 'example.com', 'json'] ); $this->assertIsObject( $result ); } @@ -649,7 +656,7 @@ public function test_send_hestia_request_maps_args_to_numbered_keys(): void { $this->queue_success(); $method = $this->get_send_request_method(); - $method->invoke( $this->provider, 'v-test-cmd', [ 'first', 'second', 'third' ] ); + $method->invoke( $this->provider, 'v-test-cmd', ['first', 'second', 'third'] ); $body = $this->http_requests[0]['args']['body']; $this->assertSame( 'first', $body['arg1'] ); @@ -716,7 +723,7 @@ public function test_call_and_log_on_success(): void { $method->setAccessible( true ); // Should not throw - $method->invoke( $this->provider, 'v-add-web-domain-alias', [ 'admin', 'mysite.com', 'example.com', 'yes' ], 'Add alias example.com' ); + $method->invoke( $this->provider, 'v-add-web-domain-alias', ['admin', 'mysite.com', 'example.com', 'yes'], 'Add alias example.com' ); $this->assertCount( 1, $this->http_requests ); } @@ -806,10 +813,10 @@ public function test_get_dns_records_parses_json_response(): void { 'TTL' => 3600, ], '2' => (object) [ - 'TYPE' => 'MX', - 'RECORD' => '@', - 'VALUE' => 'mail.example.com', - 'TTL' => 3600, + 'TYPE' => 'MX', + 'RECORD' => '@', + 'VALUE' => 'mail.example.com', + 'TTL' => 3600, 'PRIORITY' => 10, ], ]; @@ -892,7 +899,7 @@ public function test_create_dns_record_calls_add_dns_record(): void { $call_count = 0; add_filter( 'pre_http_request', - function ( $preempt, $args, $url ) use ( &$call_count ) { + function ($preempt, $args, $url) use (&$call_count) { ++$call_count; if ( 1 === $call_count ) { return $this->make_http_response( 200, '0' ); @@ -925,7 +932,7 @@ function ( $preempt, $args, $url ) use ( &$call_count ) { remove_all_filters( 'pre_http_request' ); // Re-add our main interceptor for subsequent tests - add_filter( 'pre_http_request', [ $this, 'intercept_http_request' ], 10, 3 ); + add_filter( 'pre_http_request', [$this, 'intercept_http_request'], 10, 3 ); $this->assertIsArray( $result ); $this->assertArrayHasKey( 'type', $result ); @@ -979,11 +986,14 @@ public function test_create_dns_record_adds_mx_priority(): void { $call_count = 0; add_filter( 'pre_http_request', - function ( $preempt, $args, $url ) use ( &$call_count ) { + function ($preempt, $args, $url) use (&$call_count) { ++$call_count; if ( 1 === $call_count ) { // Capture the body for assertion - $this->http_requests[] = [ 'url' => $url, 'args' => $args ]; + $this->http_requests[] = [ + 'url' => $url, + 'args' => $args, + ]; return $this->make_http_response( 200, '0' ); } @@ -1005,7 +1015,7 @@ function ( $preempt, $args, $url ) use ( &$call_count ) { $this->provider->create_dns_record( 'example.com', $record ); remove_all_filters( 'pre_http_request' ); - add_filter( 'pre_http_request', [ $this, 'intercept_http_request' ], 10, 3 ); + add_filter( 'pre_http_request', [$this, 'intercept_http_request'], 10, 3 ); if ( ! empty( $this->http_requests ) ) { $body = $this->http_requests[0]['args']['body']; @@ -1025,7 +1035,7 @@ public function test_create_dns_record_result_has_expected_keys(): void { $call_count = 0; add_filter( 'pre_http_request', - function ( $preempt, $args, $url ) use ( &$call_count ) { + function ($preempt, $args, $url) use (&$call_count) { ++$call_count; if ( 1 === $call_count ) { return $this->make_http_response( 200, '0' ); @@ -1047,7 +1057,7 @@ function ( $preempt, $args, $url ) use ( &$call_count ) { $result = $this->provider->create_dns_record( 'example.com', $record ); remove_all_filters( 'pre_http_request' ); - add_filter( 'pre_http_request', [ $this, 'intercept_http_request' ], 10, 3 ); + add_filter( 'pre_http_request', [$this, 'intercept_http_request'], 10, 3 ); $this->assertIsArray( $result ); $this->assertArrayHasKey( 'type', $result ); diff --git a/tests/WP_Ultimo/Integrations/Integration_Test.php b/tests/WP_Ultimo/Integrations/Integration_Test.php index c9c6bb96a..ab298e80e 100644 --- a/tests/WP_Ultimo/Integrations/Integration_Test.php +++ b/tests/WP_Ultimo/Integrations/Integration_Test.php @@ -136,8 +136,8 @@ public function test_save_and_get_credentials(): void { public function test_save_credentials_ignores_unknown_keys(): void { $this->integration->save_credentials([ - 'CONST_A' => 'value_a', - 'UNKNOWN' => 'should_be_ignored', + 'CONST_A' => 'value_a', + 'UNKNOWN' => 'should_be_ignored', ]); $this->assertSame('value_a', $this->integration->get_credential('CONST_A')); diff --git a/tests/WP_Ultimo/Integrations/Providers/Amazon_SES/Amazon_SES_Integration_Test.php b/tests/WP_Ultimo/Integrations/Providers/Amazon_SES/Amazon_SES_Integration_Test.php index 679924f8c..b4f7ea67a 100644 --- a/tests/WP_Ultimo/Integrations/Providers/Amazon_SES/Amazon_SES_Integration_Test.php +++ b/tests/WP_Ultimo/Integrations/Providers/Amazon_SES/Amazon_SES_Integration_Test.php @@ -119,7 +119,10 @@ public function test_test_connection_returns_true_on_success(): void { ->getMock(); $integration->method('ses_api_call') - ->willReturn(['SendingEnabled' => true, 'SendingQuota' => []]); + ->willReturn([ + 'SendingEnabled' => true, + 'SendingQuota' => [], + ]); $result = $integration->test_connection(); diff --git a/tests/WP_Ultimo/Integrations/Providers/Amazon_SES/Amazon_SES_Transactional_Email_Test.php b/tests/WP_Ultimo/Integrations/Providers/Amazon_SES/Amazon_SES_Transactional_Email_Test.php index 9af6cec4f..04b220923 100644 --- a/tests/WP_Ultimo/Integrations/Providers/Amazon_SES/Amazon_SES_Transactional_Email_Test.php +++ b/tests/WP_Ultimo/Integrations/Providers/Amazon_SES/Amazon_SES_Transactional_Email_Test.php @@ -86,7 +86,13 @@ public function test_intercept_wp_mail_returns_original_when_return_is_not_null( $result = $this->module->intercept_wp_mail( true, - ['to' => 'test@example.com', 'subject' => 'Test', 'message' => 'Body', 'headers' => [], 'attachments' => []] + [ + 'to' => 'test@example.com', + 'subject' => 'Test', + 'message' => 'Body', + 'headers' => [], + 'attachments' => [], + ] ); $this->assertTrue($result); @@ -143,8 +149,8 @@ public function test_verify_domain_returns_success_with_dns_records(): void { 'VerifiedForSendingStatus' => false, 'DkimAttributes' => [ 'SigningEnabled' => false, - 'Status' => 'NOT_STARTED', - 'Tokens' => ['token1abc', 'token2def', 'token3ghi'], + 'Status' => 'NOT_STARTED', + 'Tokens' => ['token1abc', 'token2def', 'token3ghi'], ], ]); @@ -269,9 +275,9 @@ public function test_get_sending_statistics_returns_totals(): void { ->willReturn([ 'SendingEnabled' => true, 'SendQuota' => [ - 'Max24HourSend' => 50000, - 'MaxSendRate' => 14, - 'SentLast24Hours' => 100, + 'Max24HourSend' => 50000, + 'MaxSendRate' => 14, + 'SentLast24Hours' => 100, ], ]); diff --git a/tests/WP_Ultimo/Integrations/Providers/BunnyNet_Domain_Mapping_Test.php b/tests/WP_Ultimo/Integrations/Providers/BunnyNet_Domain_Mapping_Test.php index 5cbc516ba..f0be0dcc9 100644 --- a/tests/WP_Ultimo/Integrations/Providers/BunnyNet_Domain_Mapping_Test.php +++ b/tests/WP_Ultimo/Integrations/Providers/BunnyNet_Domain_Mapping_Test.php @@ -104,7 +104,12 @@ public function test_add_bunnynet_dns_entries_returns_unchanged_when_no_zone_id( ->with('WU_BUNNYNET_ZONE_ID') ->willReturn(''); - $existing = [['type' => 'A', 'data' => '1.2.3.4']]; + $existing = [ + [ + 'type' => 'A', + 'data' => '1.2.3.4', + ], + ]; $result = $this->module->add_bunnynet_dns_entries($existing, 'example.com'); @@ -120,7 +125,12 @@ public function test_add_bunnynet_dns_entries_returns_unchanged_on_api_error(): $this->integration->method('send_bunnynet_request') ->willReturn(new \WP_Error('fail', 'error')); - $existing = [['type' => 'A', 'data' => '1.2.3.4']]; + $existing = [ + [ + 'type' => 'A', + 'data' => '1.2.3.4', + ], + ]; $result = $this->module->add_bunnynet_dns_entries($existing, 'example.com'); diff --git a/tests/WP_Ultimo/Integrations/Providers/Cloudflare/Cloudflare_Domain_Mapping_Test.php b/tests/WP_Ultimo/Integrations/Providers/Cloudflare/Cloudflare_Domain_Mapping_Test.php index 8ce14b6a7..709136cd2 100644 --- a/tests/WP_Ultimo/Integrations/Providers/Cloudflare/Cloudflare_Domain_Mapping_Test.php +++ b/tests/WP_Ultimo/Integrations/Providers/Cloudflare/Cloudflare_Domain_Mapping_Test.php @@ -179,7 +179,12 @@ public function test_add_cloudflare_dns_entries_returns_unchanged_when_no_zone_i $this->integration->method('cloudflare_api_call') ->willReturn(new \WP_Error('fail', 'error')); - $existing = [['type' => 'A', 'data' => '1.2.3.4']]; + $existing = [ + [ + 'type' => 'A', + 'data' => '1.2.3.4', + ], + ]; $result = $this->module->add_cloudflare_dns_entries($existing, 'example.com'); @@ -200,7 +205,12 @@ public function test_add_cloudflare_dns_entries_returns_unchanged_on_api_error() $this->integration->method('cloudflare_api_call') ->willReturn(new \WP_Error('fail', 'error')); - $existing = [['type' => 'A', 'data' => '1.2.3.4']]; + $existing = [ + [ + 'type' => 'A', + 'data' => '1.2.3.4', + ], + ]; $result = $this->module->add_cloudflare_dns_entries($existing, 'example.com'); diff --git a/tests/WP_Ultimo/Integrations/Providers/Enhance_Domain_Mapping_Test.php b/tests/WP_Ultimo/Integrations/Providers/Enhance_Domain_Mapping_Test.php index e997c729b..e29a04776 100644 --- a/tests/WP_Ultimo/Integrations/Providers/Enhance_Domain_Mapping_Test.php +++ b/tests/WP_Ultimo/Integrations/Providers/Enhance_Domain_Mapping_Test.php @@ -131,7 +131,10 @@ public function test_on_remove_domain_fetches_domain_list_first(): void { if ('GET' === $method) { return [ 'items' => [ - ['id' => 'domain-uuid-abc', 'domain' => 'example.com'], + [ + 'id' => 'domain-uuid-abc', + 'domain' => 'example.com', + ], ], ]; } diff --git a/tests/WP_Ultimo/Integrations/Providers/LaravelForge_Domain_Mapping_Test.php b/tests/WP_Ultimo/Integrations/Providers/LaravelForge_Domain_Mapping_Test.php index 9dd8a0882..3e4666704 100644 --- a/tests/WP_Ultimo/Integrations/Providers/LaravelForge_Domain_Mapping_Test.php +++ b/tests/WP_Ultimo/Integrations/Providers/LaravelForge_Domain_Mapping_Test.php @@ -80,7 +80,10 @@ public function test_on_add_domain_creates_site_on_server(): void { $this->integration->method('get_primary_site_id')->willReturn(67890); $this->integration->method('get_deploy_command')->willReturn(''); - $fake_response = ['response' => ['code' => 201], 'body' => '{"site":{"id":99}}']; + $fake_response = [ + 'response' => ['code' => 201], + 'body' => '{"site":{"id":99}}', + ]; $this->integration->expects($this->atLeast(1)) ->method('send_forge_request') @@ -100,7 +103,10 @@ public function test_on_remove_domain_skips_when_site_not_found(): void { $this->integration->expects($this->once()) ->method('send_forge_request') ->with($this->stringContains('/servers/12345/sites'), [], 'GET') - ->willReturn(['response' => ['code' => 200], 'body' => '{"sites":[]}']); + ->willReturn([ + 'response' => ['code' => 200], + 'body' => '{"sites":[]}', + ]); $this->integration->method('parse_response') ->willReturn(['sites' => []]); @@ -131,7 +137,10 @@ public function test_test_connection_delegates_to_integration(): void { $this->integration->expects($this->once()) ->method('send_forge_request') ->with('/servers/12345', [], 'GET') - ->willReturn(['response' => ['code' => 200], 'body' => '{"server":{"id":12345}}']); + ->willReturn([ + 'response' => ['code' => 200], + 'body' => '{"server":{"id":12345}}', + ]); $this->integration->method('parse_response') ->willReturn(['server' => ['id' => 12345]]); diff --git a/tests/WP_Ultimo/Integrations/Providers/Rocket_Domain_Mapping_Test.php b/tests/WP_Ultimo/Integrations/Providers/Rocket_Domain_Mapping_Test.php index 3905d6df4..916472523 100644 --- a/tests/WP_Ultimo/Integrations/Providers/Rocket_Domain_Mapping_Test.php +++ b/tests/WP_Ultimo/Integrations/Providers/Rocket_Domain_Mapping_Test.php @@ -69,7 +69,10 @@ public function test_on_add_domain_posts_to_domains_endpoint(): void { ['domain' => 'example.com'], 'POST' ) - ->willReturn(['response' => ['code' => 201], 'body' => '{"id":42}']); + ->willReturn([ + 'response' => ['code' => 201], + 'body' => '{"id":42}', + ]); $this->module->on_add_domain('example.com', 1); } @@ -96,7 +99,10 @@ public function test_on_remove_domain_fetches_domain_list_first(): void { ]; } - return ['response' => ['code' => 204], 'body' => '']; + return [ + 'response' => ['code' => 204], + 'body' => '', + ]; }); $this->module->on_remove_domain('example.com', 1); @@ -108,7 +114,10 @@ public function test_on_remove_domain_skips_delete_when_domain_not_found(): void $this->integration->expects($this->once()) ->method('send_rocket_request') ->with('domains', [], 'GET') - ->willReturn(['response' => ['code' => 200], 'body' => '{"data":[]}']); + ->willReturn([ + 'response' => ['code' => 200], + 'body' => '{"data":[]}', + ]); $this->module->on_remove_domain('notfound.com', 1); } @@ -134,7 +143,10 @@ public function test_test_connection_delegates_to_integration(): void { $this->integration->expects($this->once()) ->method('send_rocket_request') ->with('domains', [], 'GET') - ->willReturn(['response' => ['code' => 200], 'body' => '{"data":[]}']); + ->willReturn([ + 'response' => ['code' => 200], + 'body' => '{"data":[]}', + ]); $result = $this->module->test_connection(); diff --git a/tests/WP_Ultimo/Integrations/Providers/RunCloud_Domain_Mapping_Test.php b/tests/WP_Ultimo/Integrations/Providers/RunCloud_Domain_Mapping_Test.php index e58e720d9..b90c17fc2 100644 --- a/tests/WP_Ultimo/Integrations/Providers/RunCloud_Domain_Mapping_Test.php +++ b/tests/WP_Ultimo/Integrations/Providers/RunCloud_Domain_Mapping_Test.php @@ -62,11 +62,17 @@ public function test_on_add_domain_calls_api(): void { $this->assertSame('example.com', $data['name']); $this->assertSame('alias', $data['type']); - return ['response' => ['code' => 200], 'body' => '{"id":1}']; + return [ + 'response' => ['code' => 200], + 'body' => '{"id":1}', + ]; } // GET requests for SSL - return ['response' => ['code' => 200], 'body' => '{}']; + return [ + 'response' => ['code' => 200], + 'body' => '{}', + ]; }); $this->module->on_add_domain('example.com', 1); @@ -101,7 +107,10 @@ public function test_test_connection_delegates_to_integration(): void { $this->integration->expects($this->atLeast(1)) ->method('send_runcloud_request') - ->willReturn(['response' => ['code' => 200], 'body' => '{"data":{}}']); + ->willReturn([ + 'response' => ['code' => 200], + 'body' => '{"data":{}}', + ]); $result = $this->module->test_connection(); diff --git a/tests/WP_Ultimo/Invoices/Invoice_Test.php b/tests/WP_Ultimo/Invoices/Invoice_Test.php index 6e4a9c44a..908c07554 100644 --- a/tests/WP_Ultimo/Invoices/Invoice_Test.php +++ b/tests/WP_Ultimo/Invoices/Invoice_Test.php @@ -159,9 +159,9 @@ public function test_custom_attributes_override_defaults() { $payment = $this->create_test_payment(); $invoice = new Invoice($payment, [ - 'company_name' => 'Test Company', + 'company_name' => 'Test Company', 'primary_color' => '#ff0000', - 'font' => 'DejaVuSerifCondensed', + 'font' => 'DejaVuSerifCondensed', ]); $this->assertEquals('Test Company', $invoice->company_name); @@ -226,7 +226,10 @@ public function test_render_contains_line_items() { */ public function test_render_contains_payment_total() { - $payment = $this->create_test_payment(['total' => 110.00, 'currency' => 'USD']); + $payment = $this->create_test_payment([ + 'total' => 110.00, + 'currency' => 'USD', + ]); $invoice = new Invoice($payment); $html = $invoice->render(); @@ -305,7 +308,7 @@ public function test_pdf_generation_does_not_fatal() { $payment = $this->create_test_payment(); $invoice = new Invoice($payment); - $folder = Invoice::get_folder(); + $folder = Invoice::get_folder(); $file_name = 'test-invoice-' . time() . '.pdf'; $invoice->save_file($file_name); @@ -328,7 +331,7 @@ public function test_generated_pdf_has_content() { $payment = $this->create_test_payment(); $invoice = new Invoice($payment); - $folder = Invoice::get_folder(); + $folder = Invoice::get_folder(); $file_name = 'test-invoice-content-' . time() . '.pdf'; $invoice->save_file($file_name); @@ -351,7 +354,7 @@ public function test_generated_pdf_has_valid_header() { $payment = $this->create_test_payment(); $invoice = new Invoice($payment); - $folder = Invoice::get_folder(); + $folder = Invoice::get_folder(); $file_name = 'test-invoice-header-' . time() . '.pdf'; $invoice->save_file($file_name); @@ -373,14 +376,14 @@ public function test_generated_pdf_has_valid_header() { public function test_pdf_generation_with_eur_currency() { $payment = $this->create_test_payment([ - 'currency' => 'EUR', - 'total' => 58.31, - 'subtotal' => 49.00, + 'currency' => 'EUR', + 'total' => 58.31, + 'subtotal' => 49.00, 'tax_total' => 9.31, ]); $invoice = new Invoice($payment); - $folder = Invoice::get_folder(); + $folder = Invoice::get_folder(); $file_name = 'test-invoice-eur-' . time() . '.pdf'; $invoice->save_file($file_name); @@ -420,7 +423,7 @@ public function test_pdf_generation_with_zero_amount() { ]); $invoice = new Invoice($payment); - $folder = Invoice::get_folder(); + $folder = Invoice::get_folder(); $file_name = 'test-invoice-free-' . time() . '.pdf'; $invoice->save_file($file_name); @@ -462,7 +465,7 @@ public function test_pdf_generation_with_footer() { 'footer_message' => 'Thank you for your business!', ]); - $folder = Invoice::get_folder(); + $folder = Invoice::get_folder(); $file_name = 'test-invoice-footer-' . time() . '.pdf'; $invoice->save_file($file_name); @@ -638,7 +641,7 @@ public function test_pdf_with_special_characters() { 'company_address' => "Königstraße 42\n10117 Berlin\nDeutschland", ]); - $folder = Invoice::get_folder(); + $folder = Invoice::get_folder(); $file_name = 'test-invoice-unicode-' . time() . '.pdf'; $invoice->save_file($file_name); diff --git a/tests/WP_Ultimo/Light_Ajax_Test.php b/tests/WP_Ultimo/Light_Ajax_Test.php index a81aa2843..008d6963c 100644 --- a/tests/WP_Ultimo/Light_Ajax_Test.php +++ b/tests/WP_Ultimo/Light_Ajax_Test.php @@ -113,7 +113,7 @@ public function test_should_skip_referer_check_for_allowed_actions() { foreach ($allowed_actions as $action) { $_REQUEST['action'] = $action; - $result = $method->invoke($instance); + $result = $method->invoke($instance); $this->assertTrue($result, "Action '$action' should skip referer check"); } @@ -130,7 +130,7 @@ public function test_should_not_skip_referer_check_for_unknown_actions() { } $_REQUEST['action'] = 'some_random_action'; - $result = $method->invoke($instance); + $result = $method->invoke($instance); $this->assertFalse($result); unset($_REQUEST['action']); @@ -190,7 +190,7 @@ public function test_skip_referer_check_filter_can_add_actions() { }); $_REQUEST['action'] = 'my_custom_action'; - $result = $method->invoke($instance); + $result = $method->invoke($instance); $this->assertTrue($result); unset($_REQUEST['action']); diff --git a/tests/WP_Ultimo/Limits/Customer_User_Role_Limits_Test.php b/tests/WP_Ultimo/Limits/Customer_User_Role_Limits_Test.php index 159c39af8..425f6da65 100644 --- a/tests/WP_Ultimo/Limits/Customer_User_Role_Limits_Test.php +++ b/tests/WP_Ultimo/Limits/Customer_User_Role_Limits_Test.php @@ -107,8 +107,13 @@ public function test_filter_editable_roles_removes_role_when_over_limit_in_admin // Ensure wp_users.can is an array before calling revoke_super_admin // (required on some WP versions to avoid a fatal error) wp_cache_flush(); - if (!is_array(get_option('wp_users.can'))) { - update_option('wp_users.can', ['list_users' => true, 'promote_users' => true, 'remove_users' => true, 'edit_users' => true]); + if (! is_array(get_option('wp_users.can'))) { + update_option('wp_users.can', [ + 'list_users' => true, + 'promote_users' => true, + 'remove_users' => true, + 'edit_users' => true, + ]); } revoke_super_admin($admin_id); } @@ -303,7 +308,7 @@ public function test_handle_downgrade_fires_demoted_action(): void { add_action( 'wu_customer_user_role_downgrade_demoted', - function($user_id) use (&$demoted_user_ids) { + function ($user_id) use (&$demoted_user_ids) { $demoted_user_ids[] = $user_id; } ); @@ -393,7 +398,7 @@ public function test_handle_downgrade_no_demotion_within_quota(): void { add_action( 'wu_customer_user_role_downgrade_demoted', - function($user_id) use (&$demoted_user_ids) { + function ($user_id) use (&$demoted_user_ids) { $demoted_user_ids[] = $user_id; } ); diff --git a/tests/WP_Ultimo/Limits/Disk_Space_Limits_Test.php b/tests/WP_Ultimo/Limits/Disk_Space_Limits_Test.php index 9e4b71c79..81f602eb0 100644 --- a/tests/WP_Ultimo/Limits/Disk_Space_Limits_Test.php +++ b/tests/WP_Ultimo/Limits/Disk_Space_Limits_Test.php @@ -62,7 +62,7 @@ public function test_handle_downgrade_fires_action_when_over_quota(): void { add_action( 'wu_disk_space_downgrade_exceeded', - function($blog_id, $used_mb, $quota_mb, $membership_id) use (&$action_fired, &$fired_args) { + function ($blog_id, $used_mb, $quota_mb, $membership_id) use (&$action_fired, &$fired_args) { $action_fired = true; $fired_args = compact('blog_id', 'used_mb', 'quota_mb', 'membership_id'); }, @@ -127,7 +127,7 @@ function($blog_id, $used_mb, $quota_mb, $membership_id) use (&$action_fired, &$f // Mock get_space_used to return a value above the quota. add_filter( 'pre_option_upload_space_check_disabled', - function() { + function () { return '0'; } ); @@ -155,7 +155,7 @@ public function test_handle_downgrade_skips_unlimited_quota(): void { add_action( 'wu_disk_space_downgrade_exceeded', - function() use (&$action_fired) { + function () use (&$action_fired) { $action_fired = true; } ); diff --git a/tests/WP_Ultimo/Limits/Plugin_Limits_Test.php b/tests/WP_Ultimo/Limits/Plugin_Limits_Test.php index 63a82bb66..d6b85acce 100644 --- a/tests/WP_Ultimo/Limits/Plugin_Limits_Test.php +++ b/tests/WP_Ultimo/Limits/Plugin_Limits_Test.php @@ -14,7 +14,7 @@ class Plugin_Limits_Test extends \WP_UnitTestCase { */ private function get_instance() { - $ref = new \ReflectionClass(Plugin_Limits::class); + $ref = new \ReflectionClass(Plugin_Limits::class); $instance = $ref->newInstanceWithoutConstructor(); return $instance; @@ -56,8 +56,14 @@ public function test_clear_plugin_list_main_site() { $instance = $this->get_instance(); $plugins = [ - 'plugin1/plugin1.php' => ['Name' => 'Plugin 1', 'Network' => false], - 'plugin2/plugin2.php' => ['Name' => 'Plugin 2', 'Network' => false], + 'plugin1/plugin1.php' => [ + 'Name' => 'Plugin 1', + 'Network' => false, + ], + 'plugin2/plugin2.php' => [ + 'Name' => 'Plugin 2', + 'Network' => false, + ], ]; $result = $instance->clear_plugin_list($plugins); @@ -170,7 +176,10 @@ public function test_clear_actions_returns_actions() { $instance = $this->get_instance(); - $actions = ['activate' => 'Activate', 'deactivate' => 'Deactivate']; + $actions = [ + 'activate' => 'Activate', + 'deactivate' => 'Deactivate', + ]; $result = $instance->clear_actions($actions, 'plugin/plugin.php'); diff --git a/tests/WP_Ultimo/Limits/Post_Type_Limits_Test.php b/tests/WP_Ultimo/Limits/Post_Type_Limits_Test.php index 724b62c67..db6f686a2 100644 --- a/tests/WP_Ultimo/Limits/Post_Type_Limits_Test.php +++ b/tests/WP_Ultimo/Limits/Post_Type_Limits_Test.php @@ -14,7 +14,7 @@ class Post_Type_Limits_Test extends \WP_UnitTestCase { */ private function get_instance() { - $ref = new \ReflectionClass(Post_Type_Limits::class); + $ref = new \ReflectionClass(Post_Type_Limits::class); $instance = $ref->newInstanceWithoutConstructor(); return $instance; @@ -59,7 +59,10 @@ public function test_register_emulated_post_types_cleans_data() { // Set corrupted data wu_save_setting('emulated_post_types', [ 'not_an_array', - ['post_type' => 'test', 'label' => 'Test'], + [ + 'post_type' => 'test', + 'label' => 'Test', + ], ['invalid_key' => 'value'], ]); @@ -300,7 +303,7 @@ public function test_handle_downgrade_fires_demoted_action() { add_action( 'wu_post_type_downgrade_demoted', - function($post_id) use (&$demoted_post_ids) { + function ($post_id) use (&$demoted_post_ids) { $demoted_post_ids[] = $post_id; } ); @@ -365,8 +368,14 @@ function($post_id) use (&$demoted_post_ids) { switch_to_blog($site->get_id()); // Create 2 published posts (limit is 1, so 1 should be demoted). - self::factory()->post->create(['post_status' => 'publish', 'post_type' => 'post']); - self::factory()->post->create(['post_status' => 'publish', 'post_type' => 'post']); + self::factory()->post->create([ + 'post_status' => 'publish', + 'post_type' => 'post', + ]); + self::factory()->post->create([ + 'post_status' => 'publish', + 'post_type' => 'post', + ]); restore_current_blog(); @@ -442,8 +451,14 @@ public function test_handle_downgrade_no_demotion_within_quota() { switch_to_blog($site->get_id()); - $post_id_1 = self::factory()->post->create(['post_status' => 'publish', 'post_type' => 'post']); - $post_id_2 = self::factory()->post->create(['post_status' => 'publish', 'post_type' => 'post']); + $post_id_1 = self::factory()->post->create([ + 'post_status' => 'publish', + 'post_type' => 'post', + ]); + $post_id_2 = self::factory()->post->create([ + 'post_status' => 'publish', + 'post_type' => 'post', + ]); restore_current_blog(); diff --git a/tests/WP_Ultimo/Limits/Theme_Limits_Test.php b/tests/WP_Ultimo/Limits/Theme_Limits_Test.php index 875088a16..120c11922 100644 --- a/tests/WP_Ultimo/Limits/Theme_Limits_Test.php +++ b/tests/WP_Ultimo/Limits/Theme_Limits_Test.php @@ -16,7 +16,7 @@ class Theme_Limits_Test extends \WP_UnitTestCase { private function get_instance() { // Create instance directly to bypass Singleton init() - $ref = new \ReflectionClass(Theme_Limits::class); + $ref = new \ReflectionClass(Theme_Limits::class); $instance = $ref->newInstanceWithoutConstructor(); return $instance; @@ -106,7 +106,7 @@ public function test_prevent_theme_activation_on_customizer_no_limitations() { $instance = $this->get_instance(); - $data = ['key' => 'value']; + $data = ['key' => 'value']; $context = []; $result = $instance->prevent_theme_activation_on_customizer($data, $context); diff --git a/tests/WP_Ultimo/Limits/Trial_Limits_Test.php b/tests/WP_Ultimo/Limits/Trial_Limits_Test.php index 04c938150..841e3d6bc 100644 --- a/tests/WP_Ultimo/Limits/Trial_Limits_Test.php +++ b/tests/WP_Ultimo/Limits/Trial_Limits_Test.php @@ -16,7 +16,7 @@ class Trial_Limits_Test extends \WP_UnitTestCase { private function get_instance() { // Create instance directly to bypass Singleton init() - $ref = new \ReflectionClass(Trial_Limits::class); + $ref = new \ReflectionClass(Trial_Limits::class); $instance = $ref->newInstanceWithoutConstructor(); return $instance; @@ -57,7 +57,7 @@ public function test_get_instance_returns_correct_class() { */ public function test_get_instance_returns_same_instance() { - $first = Trial_Limits::get_instance(); + $first = Trial_Limits::get_instance(); $second = Trial_Limits::get_instance(); $this->assertSame($first, $second); diff --git a/tests/WP_Ultimo/List_Tables/Base_List_Table_Test.php b/tests/WP_Ultimo/List_Tables/Base_List_Table_Test.php index fe4b3fdb5..78f97bece 100644 --- a/tests/WP_Ultimo/List_Tables/Base_List_Table_Test.php +++ b/tests/WP_Ultimo/List_Tables/Base_List_Table_Test.php @@ -30,7 +30,7 @@ class Test_Concrete_List_Table extends Base_List_Table { * * @param array $args Table attributes. */ - public function __construct( $args = [] ) { + public function __construct($args = []) { $args = wp_parse_args( $args, @@ -76,7 +76,7 @@ class Test_Active_List_Table extends Base_List_Table { * * @param array $args Table attributes. */ - public function __construct( $args = [] ) { + public function __construct($args = []) { $args = wp_parse_args( $args, @@ -133,7 +133,7 @@ public function set_up(): void { public function tear_down(): void { // Clean up request globals. - foreach ( [ 'orderby', 'order', 's', 'status', 'type', 'mode', 'page', 'id' ] as $key ) { + foreach ( ['orderby', 'order', 's', 'status', 'type', 'mode', 'page', 'id'] as $key ) { unset( $_REQUEST[ $key ], $_GET[ $key ], $_POST[ $key ] ); } @@ -203,7 +203,7 @@ public function test_constructor_registers_enqueue_scripts_action(): void { $this->assertGreaterThan( 0, - has_action( 'admin_enqueue_scripts', [ $this->table, 'register_scripts' ] ) + has_action( 'admin_enqueue_scripts', [$this->table, 'register_scripts'] ) ); } @@ -214,7 +214,7 @@ public function test_constructor_registers_admin_header_action(): void { $this->assertGreaterThan( 0, - has_action( 'in_admin_header', [ $this->table, 'add_default_screen_options' ] ) + has_action( 'in_admin_header', [$this->table, 'add_default_screen_options'] ) ); } @@ -578,7 +578,7 @@ public function test_get_bulk_actions_applies_filter(): void { add_filter( 'wu_bulk_actions', - function ( $actions, $id ) { + function ($actions, $id) { $actions['custom_action'] = 'Custom Action'; return $actions; }, @@ -603,7 +603,7 @@ function ( $actions, $id ) { public function test_column_cb_returns_checkbox_html(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_id' ] ) + ->addMethods( ['get_id'] ) ->getMock(); $item->method( 'get_id' )->willReturn( 42 ); @@ -624,7 +624,7 @@ public function test_column_cb_returns_checkbox_html(): void { public function test_column_default_calls_getter_on_item(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_name' ] ) + ->addMethods( ['get_name'] ) ->getMock(); $item->method( 'get_name' )->willReturn( 'Test Name' ); @@ -721,7 +721,7 @@ public function test_column_datetime_includes_in_for_future_dates(): void { public function test_column_featured_image_id_returns_placeholder_when_no_image(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_featured_image' ] ) + ->addMethods( ['get_featured_image'] ) ->getMock(); $item->method( 'get_featured_image' )->willReturn( null ); @@ -737,11 +737,11 @@ public function test_column_featured_image_id_returns_placeholder_when_no_image( public function test_column_featured_image_id_returns_img_when_image_exists(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_featured_image' ] ) + ->addMethods( ['get_featured_image'] ) ->getMock(); $item->method( 'get_featured_image' ) ->willReturnCallback( - function ( $size ) { + function ($size) { if ( 'thumbnail' === $size ) { return 'https://example.com/thumb.jpg'; } @@ -765,7 +765,7 @@ function ( $size ) { public function test_column_membership_outputs_not_found_when_no_membership(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_membership' ] ) + ->addMethods( ['get_membership'] ) ->getMock(); $item->method( 'get_membership' )->willReturn( null ); @@ -782,7 +782,7 @@ public function test_column_membership_outputs_not_found_when_no_membership(): v public function test_column_membership_outputs_link_when_membership_exists(): void { $membership = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_id', 'get_hash', 'get_price_description', 'get_status_class' ] ) + ->addMethods( ['get_id', 'get_hash', 'get_price_description', 'get_status_class'] ) ->getMock(); $membership->method( 'get_id' )->willReturn( 5 ); $membership->method( 'get_hash' )->willReturn( 'HASH123' ); @@ -790,7 +790,7 @@ public function test_column_membership_outputs_link_when_membership_exists(): vo $membership->method( 'get_status_class' )->willReturn( 'wu-bg-green-500' ); $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_membership' ] ) + ->addMethods( ['get_membership'] ) ->getMock(); $item->method( 'get_membership' )->willReturn( $membership ); @@ -812,7 +812,7 @@ public function test_column_membership_outputs_link_when_membership_exists(): vo public function test_column_customer_returns_not_found_when_no_customer(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_customer' ] ) + ->addMethods( ['get_customer'] ) ->getMock(); $item->method( 'get_customer' )->willReturn( null ); @@ -827,7 +827,7 @@ public function test_column_customer_returns_not_found_when_no_customer(): void public function test_column_customer_returns_link_when_customer_exists(): void { $customer = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_id', 'get_user_id', 'get_display_name', 'get_email_address' ] ) + ->addMethods( ['get_id', 'get_user_id', 'get_display_name', 'get_email_address'] ) ->getMock(); $customer->method( 'get_id' )->willReturn( 3 ); $customer->method( 'get_user_id' )->willReturn( 1 ); @@ -835,7 +835,7 @@ public function test_column_customer_returns_link_when_customer_exists(): void { $customer->method( 'get_email_address' )->willReturn( 'john@example.com' ); $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_customer' ] ) + ->addMethods( ['get_customer'] ) ->getMock(); $item->method( 'get_customer' )->willReturn( $customer ); @@ -855,7 +855,7 @@ public function test_column_customer_returns_link_when_customer_exists(): void { public function test_column_product_returns_not_found_when_no_product(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_plan' ] ) + ->addMethods( ['get_plan'] ) ->getMock(); $item->method( 'get_plan' )->willReturn( null ); @@ -870,7 +870,7 @@ public function test_column_product_returns_not_found_when_no_product(): void { public function test_column_product_returns_link_when_product_exists(): void { $product = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_id', 'get_name', 'get_type', 'get_featured_image' ] ) + ->addMethods( ['get_id', 'get_name', 'get_type', 'get_featured_image'] ) ->getMock(); $product->method( 'get_id' )->willReturn( 7 ); $product->method( 'get_name' )->willReturn( 'Pro Plan' ); @@ -878,7 +878,7 @@ public function test_column_product_returns_link_when_product_exists(): void { $product->method( 'get_featured_image' )->willReturn( null ); $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_plan' ] ) + ->addMethods( ['get_plan'] ) ->getMock(); $item->method( 'get_plan' )->willReturn( $product ); @@ -894,7 +894,7 @@ public function test_column_product_returns_link_when_product_exists(): void { public function test_column_product_renders_image_when_product_has_image(): void { $product = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_id', 'get_name', 'get_type', 'get_featured_image' ] ) + ->addMethods( ['get_id', 'get_name', 'get_type', 'get_featured_image'] ) ->getMock(); $product->method( 'get_id' )->willReturn( 8 ); $product->method( 'get_name' )->willReturn( 'Premium Plan' ); @@ -902,7 +902,7 @@ public function test_column_product_renders_image_when_product_has_image(): void $product->method( 'get_featured_image' )->willReturn( 'https://example.com/image.jpg' ); $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_plan' ] ) + ->addMethods( ['get_plan'] ) ->getMock(); $item->method( 'get_plan' )->willReturn( $product ); @@ -922,7 +922,7 @@ public function test_column_product_renders_image_when_product_has_image(): void public function test_column_blog_id_returns_not_found_when_no_site(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_site' ] ) + ->addMethods( ['get_site'] ) ->getMock(); $item->method( 'get_site' )->willReturn( null ); @@ -937,7 +937,7 @@ public function test_column_blog_id_returns_not_found_when_no_site(): void { public function test_column_blog_id_returns_link_when_site_exists(): void { $site = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_id', 'get_title', 'get_featured_image', 'get_active_site_url' ] ) + ->addMethods( ['get_id', 'get_title', 'get_featured_image', 'get_active_site_url'] ) ->getMock(); $site->method( 'get_id' )->willReturn( 2 ); $site->method( 'get_title' )->willReturn( 'My Site' ); @@ -945,7 +945,7 @@ public function test_column_blog_id_returns_link_when_site_exists(): void { $site->method( 'get_active_site_url' )->willReturn( 'https://mysite.example.com' ); $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_site' ] ) + ->addMethods( ['get_site'] ) ->getMock(); $item->method( 'get_site' )->willReturn( $site ); @@ -969,7 +969,7 @@ public function test_column_blog_id_returns_link_when_site_exists(): void { public function test_column_payment_outputs_not_found_when_no_payment(): void { $payment = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_id', 'get_hash', 'get_total', 'get_currency', 'get_status_class' ] ) + ->addMethods( ['get_id', 'get_hash', 'get_total', 'get_currency', 'get_status_class'] ) ->getMock(); $payment->method( 'get_id' )->willReturn( null ); $payment->method( 'get_hash' )->willReturn( '' ); @@ -978,7 +978,7 @@ public function test_column_payment_outputs_not_found_when_no_payment(): void { $payment->method( 'get_status_class' )->willReturn( '' ); $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_payment' ] ) + ->addMethods( ['get_payment'] ) ->getMock(); // Return a mock payment that simulates the "not found" display path // by returning a payment with null ID (to avoid the null dereference bug). @@ -998,7 +998,7 @@ public function test_column_payment_outputs_not_found_when_no_payment(): void { public function test_column_payment_outputs_link_when_payment_exists(): void { $payment = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_id', 'get_hash', 'get_total', 'get_currency', 'get_status_class' ] ) + ->addMethods( ['get_id', 'get_hash', 'get_total', 'get_currency', 'get_status_class'] ) ->getMock(); $payment->method( 'get_id' )->willReturn( 10 ); $payment->method( 'get_hash' )->willReturn( 'PAY123' ); @@ -1007,7 +1007,7 @@ public function test_column_payment_outputs_link_when_payment_exists(): void { $payment->method( 'get_status_class' )->willReturn( 'wu-bg-green-500' ); $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_payment' ] ) + ->addMethods( ['get_payment'] ) ->getMock(); $item->method( 'get_payment' )->willReturn( $payment ); @@ -1132,7 +1132,7 @@ public function test_get_default_date_filter_options_returns_expected_keys(): vo $this->assertIsArray( $options ); - $expected_keys = [ 'all', 'today', 'yesterday', 'last_week', 'last_month', 'current_month', 'last_year', 'year_to_date', 'custom' ]; + $expected_keys = ['all', 'today', 'yesterday', 'last_week', 'last_month', 'current_month', 'last_year', 'year_to_date', 'custom']; foreach ( $expected_keys as $key ) { $this->assertArrayHasKey( $key, $options, "Missing key: {$key}" ); @@ -1321,7 +1321,7 @@ public function test_has_items_returns_boolean(): void { */ public function test_has_items_returns_true_when_items_set(): void { - $this->table->items = [ new \stdClass() ]; + $this->table->items = [new \stdClass()]; $result = $this->table->has_items(); @@ -1339,7 +1339,7 @@ public function test_row_actions_applies_filter(): void { add_filter( 'wu_list_row_actions', - function ( $actions, $id ) { + function ($actions, $id) { $actions['custom'] = 'Custom'; return $actions; }, @@ -1353,7 +1353,7 @@ function ( $actions, $id ) { $result = $method->invoke( $this->table, - [ 'edit' => 'Edit' ] + ['edit' => 'Edit'] ); // The filter was applied (custom action added), then parent::row_actions renders HTML. @@ -1480,7 +1480,7 @@ public function test_get_schema_columns_with_searchable_filter(): void { $method = $reflection->getMethod( 'get_schema_columns' ); $method->setAccessible( true ); - $columns = $method->invoke( $this->table, [ 'searchable' => true ] ); + $columns = $method->invoke( $this->table, ['searchable' => true] ); $this->assertIsArray( $columns ); @@ -1498,7 +1498,7 @@ public function test_get_schema_columns_with_sortable_filter(): void { $method = $reflection->getMethod( 'get_schema_columns' ); $method->setAccessible( true ); - $columns = $method->invoke( $this->table, [ 'sortable' => true ] ); + $columns = $method->invoke( $this->table, ['sortable' => true] ); $this->assertIsArray( $columns ); } @@ -1596,7 +1596,7 @@ public function test_prepare_items_sets_items(): void { public function test_display_calls_display_view_when_items_exist(): void { $table = $this->getMockBuilder( Test_Concrete_List_Table::class ) - ->onlyMethods( [ 'has_items', 'display_view_list' ] ) + ->onlyMethods( ['has_items', 'display_view_list'] ) ->getMock(); $table->method( 'has_items' )->willReturn( true ); $table->expects( $this->once() )->method( 'display_view_list' ); @@ -1611,7 +1611,7 @@ public function test_display_calls_display_view_when_items_exist(): void { public function test_display_calls_display_view_list_in_list_mode(): void { $table = $this->getMockBuilder( Test_Concrete_List_Table::class ) - ->onlyMethods( [ 'has_items', 'display_view_list' ] ) + ->onlyMethods( ['has_items', 'display_view_list'] ) ->getMock(); $table->method( 'has_items' )->willReturn( true ); $table->expects( $this->once() )->method( 'display_view_list' ); diff --git a/tests/WP_Ultimo/List_Tables/Broadcast_List_Table_Test.php b/tests/WP_Ultimo/List_Tables/Broadcast_List_Table_Test.php index 6d519962a..3fb39f522 100644 --- a/tests/WP_Ultimo/List_Tables/Broadcast_List_Table_Test.php +++ b/tests/WP_Ultimo/List_Tables/Broadcast_List_Table_Test.php @@ -116,7 +116,7 @@ public function test_get_sortable_columns_returns_array(): void { public function test_column_cb_returns_disabled_for_broadcast_email(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_type', 'get_id' ] ) + ->addMethods( ['get_type', 'get_id'] ) ->getMock(); $item->method( 'get_type' )->willReturn( 'broadcast_email' ); $item->method( 'get_id' )->willReturn( 1 ); @@ -132,7 +132,7 @@ public function test_column_cb_returns_disabled_for_broadcast_email(): void { public function test_column_cb_returns_normal_for_broadcast_notice(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_type', 'get_id' ] ) + ->addMethods( ['get_type', 'get_id'] ) ->getMock(); $item->method( 'get_type' )->willReturn( 'broadcast_notice' ); $item->method( 'get_id' )->willReturn( 5 ); @@ -154,7 +154,7 @@ public function test_column_cb_returns_normal_for_broadcast_notice(): void { public function test_column_type_returns_email_label_for_broadcast_email(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_type', 'get_notice_type' ] ) + ->addMethods( ['get_type', 'get_notice_type'] ) ->getMock(); $item->method( 'get_type' )->willReturn( 'broadcast_email' ); @@ -169,7 +169,7 @@ public function test_column_type_returns_email_label_for_broadcast_email(): void public function test_column_type_returns_notice_label_for_broadcast_notice(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_type', 'get_notice_type' ] ) + ->addMethods( ['get_type', 'get_notice_type'] ) ->getMock(); $item->method( 'get_type' )->willReturn( 'broadcast_notice' ); $item->method( 'get_notice_type' )->willReturn( 'info' ); @@ -185,7 +185,7 @@ public function test_column_type_returns_notice_label_for_broadcast_notice(): vo public function test_column_type_applies_blue_class_for_info_notice(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_type', 'get_notice_type' ] ) + ->addMethods( ['get_type', 'get_notice_type'] ) ->getMock(); $item->method( 'get_type' )->willReturn( 'broadcast_notice' ); $item->method( 'get_notice_type' )->willReturn( 'info' ); @@ -201,7 +201,7 @@ public function test_column_type_applies_blue_class_for_info_notice(): void { public function test_column_type_applies_green_class_for_success_notice(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_type', 'get_notice_type' ] ) + ->addMethods( ['get_type', 'get_notice_type'] ) ->getMock(); $item->method( 'get_type' )->willReturn( 'broadcast_notice' ); $item->method( 'get_notice_type' )->willReturn( 'success' ); @@ -217,7 +217,7 @@ public function test_column_type_applies_green_class_for_success_notice(): void public function test_column_type_applies_orange_class_for_warning_notice(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_type', 'get_notice_type' ] ) + ->addMethods( ['get_type', 'get_notice_type'] ) ->getMock(); $item->method( 'get_type' )->willReturn( 'broadcast_notice' ); $item->method( 'get_notice_type' )->willReturn( 'warning' ); @@ -233,7 +233,7 @@ public function test_column_type_applies_orange_class_for_warning_notice(): void public function test_column_type_applies_red_class_for_error_notice(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_type', 'get_notice_type' ] ) + ->addMethods( ['get_type', 'get_notice_type'] ) ->getMock(); $item->method( 'get_type' )->willReturn( 'broadcast_notice' ); $item->method( 'get_notice_type' )->willReturn( 'error' ); @@ -321,7 +321,7 @@ public function test_get_views_entries_have_required_keys(): void { public function test_column_the_content_returns_string_with_title(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_id', 'get_slug', 'get_title', 'get_content' ] ) + ->addMethods( ['get_id', 'get_slug', 'get_title', 'get_content'] ) ->getMock(); $item->method( 'get_id' )->willReturn( 1 ); $item->method( 'get_slug' )->willReturn( 'test-broadcast' ); diff --git a/tests/WP_Ultimo/List_Tables/Checkout_Form_List_Table_Test.php b/tests/WP_Ultimo/List_Tables/Checkout_Form_List_Table_Test.php index f82e3b0e7..0615a382b 100644 --- a/tests/WP_Ultimo/List_Tables/Checkout_Form_List_Table_Test.php +++ b/tests/WP_Ultimo/List_Tables/Checkout_Form_List_Table_Test.php @@ -105,7 +105,7 @@ public function test_get_sortable_columns_returns_array(): void { public function test_column_slug_returns_slug_in_span(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_slug' ] ) + ->addMethods( ['get_slug'] ) ->getMock(); $item->method( 'get_slug' )->willReturn( 'my-checkout-form' ); @@ -126,7 +126,7 @@ public function test_column_slug_returns_slug_in_span(): void { public function test_column_steps_returns_step_and_field_count(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_step_count', 'get_field_count' ] ) + ->addMethods( ['get_step_count', 'get_field_count'] ) ->getMock(); $item->method( 'get_step_count' )->willReturn( 3 ); $item->method( 'get_field_count' )->willReturn( 12 ); @@ -147,7 +147,7 @@ public function test_column_steps_returns_step_and_field_count(): void { public function test_column_shortcode_returns_input_with_shortcode(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_shortcode' ] ) + ->addMethods( ['get_shortcode'] ) ->getMock(); $item->method( 'get_shortcode' )->willReturn( '[wu_checkout slug="my-form"]' ); @@ -167,7 +167,7 @@ public function test_column_shortcode_returns_input_with_shortcode(): void { public function test_column_name_returns_string_with_form_name(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_id', 'get_slug', 'get_name' ] ) + ->addMethods( ['get_id', 'get_slug', 'get_name'] ) ->getMock(); $item->method( 'get_id' )->willReturn( 1 ); $item->method( 'get_slug' )->willReturn( 'my-form' ); diff --git a/tests/WP_Ultimo/List_Tables/Customer_List_Table_Test.php b/tests/WP_Ultimo/List_Tables/Customer_List_Table_Test.php index ca2bf3068..9137db77a 100644 --- a/tests/WP_Ultimo/List_Tables/Customer_List_Table_Test.php +++ b/tests/WP_Ultimo/List_Tables/Customer_List_Table_Test.php @@ -215,7 +215,7 @@ public function test_get_extra_query_fields_adds_last_login_for_online(): void { public function test_column_customer_status_returns_html(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'is_vip', 'get_user_id' ] ) + ->addMethods( ['is_vip', 'get_user_id'] ) ->getMock(); $item->method( 'is_vip' )->willReturn( false ); $item->method( 'get_user_id' )->willReturn( 1 ); @@ -232,7 +232,7 @@ public function test_column_customer_status_returns_html(): void { public function test_column_customer_status_includes_vip_tag(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'is_vip', 'get_user_id' ] ) + ->addMethods( ['is_vip', 'get_user_id'] ) ->getMock(); $item->method( 'is_vip' )->willReturn( true ); $item->method( 'get_user_id' )->willReturn( 1 ); @@ -252,7 +252,7 @@ public function test_column_customer_status_includes_vip_tag(): void { public function test_column_last_login_returns_online_for_online_customer(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'is_online', 'get_last_login' ] ) + ->addMethods( ['is_online', 'get_last_login'] ) ->getMock(); $item->method( 'is_online' )->willReturn( true ); @@ -267,7 +267,7 @@ public function test_column_last_login_returns_online_for_online_customer(): voi public function test_column_last_login_returns_datetime_for_offline_customer(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'is_online', 'get_last_login' ] ) + ->addMethods( ['is_online', 'get_last_login'] ) ->getMock(); $item->method( 'is_online' )->willReturn( false ); $item->method( 'get_last_login' )->willReturn( '2024-01-15 10:00:00' ); diff --git a/tests/WP_Ultimo/List_Tables/Discount_Code_List_Table_Test.php b/tests/WP_Ultimo/List_Tables/Discount_Code_List_Table_Test.php index cabf5b757..073096b25 100644 --- a/tests/WP_Ultimo/List_Tables/Discount_Code_List_Table_Test.php +++ b/tests/WP_Ultimo/List_Tables/Discount_Code_List_Table_Test.php @@ -106,7 +106,7 @@ public function test_get_sortable_columns_returns_array(): void { public function test_column_default_returns_value_from_getter(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_name' ] ) + ->addMethods( ['get_name'] ) ->getMock(); $item->method( 'get_name' )->willReturn( 'Summer Sale' ); @@ -125,7 +125,7 @@ public function test_column_default_returns_value_from_getter(): void { public function test_column_value_returns_no_discount_when_zero(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_value', 'get_type' ] ) + ->addMethods( ['get_value', 'get_type'] ) ->getMock(); $item->method( 'get_value' )->willReturn( 0 ); @@ -140,7 +140,7 @@ public function test_column_value_returns_no_discount_when_zero(): void { public function test_column_value_returns_percentage_for_percentage_type(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_value', 'get_type' ] ) + ->addMethods( ['get_value', 'get_type'] ) ->getMock(); $item->method( 'get_value' )->willReturn( 20 ); $item->method( 'get_type' )->willReturn( 'percentage' ); @@ -157,7 +157,7 @@ public function test_column_value_returns_percentage_for_percentage_type(): void public function test_column_value_returns_currency_for_flat_type(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_value', 'get_type' ] ) + ->addMethods( ['get_value', 'get_type'] ) ->getMock(); $item->method( 'get_value' )->willReturn( 10 ); $item->method( 'get_type' )->willReturn( 'flat' ); @@ -177,7 +177,7 @@ public function test_column_value_returns_currency_for_flat_type(): void { public function test_column_setup_fee_value_returns_no_discount_when_zero(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_setup_fee_value', 'get_setup_fee_type' ] ) + ->addMethods( ['get_setup_fee_value', 'get_setup_fee_type'] ) ->getMock(); $item->method( 'get_setup_fee_value' )->willReturn( 0 ); @@ -192,7 +192,7 @@ public function test_column_setup_fee_value_returns_no_discount_when_zero(): voi public function test_column_setup_fee_value_returns_percentage_for_percentage_type(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_setup_fee_value', 'get_setup_fee_type' ] ) + ->addMethods( ['get_setup_fee_value', 'get_setup_fee_type'] ) ->getMock(); $item->method( 'get_setup_fee_value' )->willReturn( 15 ); $item->method( 'get_setup_fee_type' )->willReturn( 'percentage' ); @@ -212,7 +212,7 @@ public function test_column_setup_fee_value_returns_percentage_for_percentage_ty public function test_column_uses_returns_usage_count(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_uses', 'get_max_uses' ] ) + ->addMethods( ['get_uses', 'get_max_uses'] ) ->getMock(); $item->method( 'get_uses' )->willReturn( 5 ); $item->method( 'get_max_uses' )->willReturn( 0 ); @@ -229,7 +229,7 @@ public function test_column_uses_returns_usage_count(): void { public function test_column_uses_shows_max_uses_when_set(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_uses', 'get_max_uses' ] ) + ->addMethods( ['get_uses', 'get_max_uses'] ) ->getMock(); $item->method( 'get_uses' )->willReturn( 3 ); $item->method( 'get_max_uses' )->willReturn( 10 ); @@ -251,7 +251,7 @@ public function test_column_coupon_code_returns_uppercase_code(): void { $valid_mock = true; // not a WP_Error $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_code', 'is_valid' ] ) + ->addMethods( ['get_code', 'is_valid'] ) ->getMock(); $item->method( 'get_code' )->willReturn( 'summer20' ); $item->method( 'is_valid' )->willReturn( true ); diff --git a/tests/WP_Ultimo/List_Tables/Domain_List_Table_Test.php b/tests/WP_Ultimo/List_Tables/Domain_List_Table_Test.php index 51aebb660..39ac5f405 100644 --- a/tests/WP_Ultimo/List_Tables/Domain_List_Table_Test.php +++ b/tests/WP_Ultimo/List_Tables/Domain_List_Table_Test.php @@ -177,7 +177,7 @@ public function test_get_extra_query_fields_empty_without_blog_id(): void { public function test_column_active_returns_yes_for_active(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'is_active' ] ) + ->addMethods( ['is_active'] ) ->getMock(); $item->method( 'is_active' )->willReturn( true ); @@ -192,7 +192,7 @@ public function test_column_active_returns_yes_for_active(): void { public function test_column_active_returns_no_for_inactive(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'is_active' ] ) + ->addMethods( ['is_active'] ) ->getMock(); $item->method( 'is_active' )->willReturn( false ); @@ -211,7 +211,7 @@ public function test_column_active_returns_no_for_inactive(): void { public function test_column_primary_domain_returns_yes_for_primary(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'is_primary_domain' ] ) + ->addMethods( ['is_primary_domain'] ) ->getMock(); $item->method( 'is_primary_domain' )->willReturn( true ); @@ -226,7 +226,7 @@ public function test_column_primary_domain_returns_yes_for_primary(): void { public function test_column_primary_domain_returns_no_for_non_primary(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'is_primary_domain' ] ) + ->addMethods( ['is_primary_domain'] ) ->getMock(); $item->method( 'is_primary_domain' )->willReturn( false ); @@ -245,7 +245,7 @@ public function test_column_primary_domain_returns_no_for_non_primary(): void { public function test_column_secure_returns_yes_for_secure(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'is_secure' ] ) + ->addMethods( ['is_secure'] ) ->getMock(); $item->method( 'is_secure' )->willReturn( true ); @@ -260,7 +260,7 @@ public function test_column_secure_returns_yes_for_secure(): void { public function test_column_secure_returns_no_for_non_secure(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'is_secure' ] ) + ->addMethods( ['is_secure'] ) ->getMock(); $item->method( 'is_secure' )->willReturn( false ); @@ -279,7 +279,7 @@ public function test_column_secure_returns_no_for_non_secure(): void { public function test_column_stage_returns_span_with_label(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_stage_label', 'get_stage_class' ] ) + ->addMethods( ['get_stage_label', 'get_stage_class'] ) ->getMock(); $item->method( 'get_stage_label' )->willReturn( 'Verified' ); $item->method( 'get_stage_class' )->willReturn( 'wu-bg-green-200' ); diff --git a/tests/WP_Ultimo/List_Tables/Email_List_Table_Test.php b/tests/WP_Ultimo/List_Tables/Email_List_Table_Test.php index 214b50e3f..7b2c1a12c 100644 --- a/tests/WP_Ultimo/List_Tables/Email_List_Table_Test.php +++ b/tests/WP_Ultimo/List_Tables/Email_List_Table_Test.php @@ -182,7 +182,7 @@ public function test_get_views_entries_have_required_keys(): void { public function test_column_event_returns_event_in_span(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_event' ] ) + ->addMethods( ['get_event'] ) ->getMock(); $item->method( 'get_event' )->willReturn( 'membership_created' ); @@ -203,7 +203,7 @@ public function test_column_event_returns_event_in_span(): void { public function test_column_slug_returns_slug_in_span(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_slug' ] ) + ->addMethods( ['get_slug'] ) ->getMock(); $item->method( 'get_slug' )->willReturn( 'welcome-email' ); @@ -223,7 +223,7 @@ public function test_column_slug_returns_slug_in_span(): void { public function test_column_schedule_returns_immediate_when_no_schedule(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'has_schedule', 'get_schedule_type', 'get_send_hours', 'get_send_days' ] ) + ->addMethods( ['has_schedule', 'get_schedule_type', 'get_send_hours', 'get_send_days'] ) ->getMock(); $item->method( 'has_schedule' )->willReturn( false ); @@ -238,7 +238,7 @@ public function test_column_schedule_returns_immediate_when_no_schedule(): void public function test_column_schedule_returns_hours_text_for_hours_type(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'has_schedule', 'get_schedule_type', 'get_send_hours', 'get_send_days' ] ) + ->addMethods( ['has_schedule', 'get_schedule_type', 'get_send_hours', 'get_send_days'] ) ->getMock(); $item->method( 'has_schedule' )->willReturn( true ); $item->method( 'get_schedule_type' )->willReturn( 'hours' ); @@ -255,7 +255,7 @@ public function test_column_schedule_returns_hours_text_for_hours_type(): void { public function test_column_schedule_returns_days_text_for_days_type(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'has_schedule', 'get_schedule_type', 'get_send_hours', 'get_send_days' ] ) + ->addMethods( ['has_schedule', 'get_schedule_type', 'get_send_hours', 'get_send_days'] ) ->getMock(); $item->method( 'has_schedule' )->willReturn( true ); $item->method( 'get_schedule_type' )->willReturn( 'days' ); diff --git a/tests/WP_Ultimo/List_Tables/Event_List_Table_Test.php b/tests/WP_Ultimo/List_Tables/Event_List_Table_Test.php index 4b1106be5..3107bc86a 100644 --- a/tests/WP_Ultimo/List_Tables/Event_List_Table_Test.php +++ b/tests/WP_Ultimo/List_Tables/Event_List_Table_Test.php @@ -79,7 +79,7 @@ public function test_get_columns_applies_filter(): void { add_filter( 'wu_events_list_table_get_columns', - function ( $columns ) { + function ($columns) { $columns['custom_col'] = 'Custom'; return $columns; } @@ -152,7 +152,7 @@ public function test_get_filters_has_date_created_date_filter(): void { public function test_column_object_type_returns_type_in_span(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_object_type' ] ) + ->addMethods( ['get_object_type'] ) ->getMock(); $item->method( 'get_object_type' )->willReturn( 'membership' ); @@ -173,7 +173,7 @@ public function test_column_object_type_returns_type_in_span(): void { public function test_column_slug_returns_slug_in_span(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_slug' ] ) + ->addMethods( ['get_slug'] ) ->getMock(); $item->method( 'get_slug' )->willReturn( 'membership.created' ); @@ -246,7 +246,7 @@ public function test_column_initiator_returns_not_found_for_unknown_initiator(): public function test_column_message_returns_trimmed_message(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_id', 'get_message' ] ) + ->addMethods( ['get_id', 'get_message'] ) ->getMock(); $item->method( 'get_id' )->willReturn( 1 ); $item->method( 'get_message' )->willReturn( 'A membership was created for the customer.' ); diff --git a/tests/WP_Ultimo/List_Tables/Membership_List_Table_Test.php b/tests/WP_Ultimo/List_Tables/Membership_List_Table_Test.php index c1f243e3e..86658f377 100644 --- a/tests/WP_Ultimo/List_Tables/Membership_List_Table_Test.php +++ b/tests/WP_Ultimo/List_Tables/Membership_List_Table_Test.php @@ -92,7 +92,7 @@ public function test_get_columns_applies_filter(): void { add_filter( 'wu_memberships_list_table_columns', - function ( $columns ) { + function ($columns) { $columns['extra_col'] = 'Extra'; return $columns; } @@ -206,7 +206,7 @@ public function test_get_extra_query_fields_includes_customer_id(): void { public function test_column_status_returns_span_with_label(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_status_label', 'get_status_class' ] ) + ->addMethods( ['get_status_label', 'get_status_class'] ) ->getMock(); $item->method( 'get_status_label' )->willReturn( 'Active' ); $item->method( 'get_status_class' )->willReturn( 'wu-bg-green-500' ); @@ -228,7 +228,7 @@ public function test_column_status_returns_span_with_label(): void { public function test_column_amount_returns_free_for_zero_amount(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_amount', 'get_initial_amount', 'is_recurring' ] ) + ->addMethods( ['get_amount', 'get_initial_amount', 'is_recurring'] ) ->getMock(); $item->method( 'get_amount' )->willReturn( 0 ); $item->method( 'get_initial_amount' )->willReturn( 0 ); @@ -271,7 +271,7 @@ public function test_column_amount_returns_one_time_for_non_recurring(): void { public function test_column_date_expiration_returns_lifetime_for_empty_date(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_date_expiration' ] ) + ->addMethods( ['get_date_expiration'] ) ->getMock(); $item->method( 'get_date_expiration' )->willReturn( '' ); @@ -286,7 +286,7 @@ public function test_column_date_expiration_returns_lifetime_for_empty_date(): v public function test_column_date_expiration_returns_lifetime_for_zero_date(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_date_expiration' ] ) + ->addMethods( ['get_date_expiration'] ) ->getMock(); $item->method( 'get_date_expiration' )->willReturn( '0000-00-00 00:00:00' ); @@ -301,7 +301,7 @@ public function test_column_date_expiration_returns_lifetime_for_zero_date(): vo public function test_column_date_expiration_returns_datetime_for_valid_date(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_date_expiration' ] ) + ->addMethods( ['get_date_expiration'] ) ->getMock(); $item->method( 'get_date_expiration' )->willReturn( '2099-12-31 00:00:00' ); diff --git a/tests/WP_Ultimo/List_Tables/Payment_List_Table_Test.php b/tests/WP_Ultimo/List_Tables/Payment_List_Table_Test.php index 86285a475..4a0a37eac 100644 --- a/tests/WP_Ultimo/List_Tables/Payment_List_Table_Test.php +++ b/tests/WP_Ultimo/List_Tables/Payment_List_Table_Test.php @@ -92,7 +92,7 @@ public function test_get_columns_applies_filter(): void { add_filter( 'wu_payments_list_table_columns', - function ( $columns ) { + function ($columns) { $columns['extra_col'] = 'Extra'; return $columns; } @@ -210,7 +210,7 @@ public function test_get_extra_query_fields_includes_parent_id_in(): void { public function test_column_status_returns_span_with_label(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_status_label', 'get_status_class' ] ) + ->addMethods( ['get_status_label', 'get_status_class'] ) ->getMock(); $item->method( 'get_status_label' )->willReturn( 'Completed' ); $item->method( 'get_status_class' )->willReturn( 'wu-bg-green-500' ); @@ -232,7 +232,7 @@ public function test_column_status_returns_span_with_label(): void { public function test_column_total_returns_currency_with_gateway(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_total', 'get_gateway' ] ) + ->addMethods( ['get_total', 'get_gateway'] ) ->getMock(); $item->method( 'get_total' )->willReturn( 99.99 ); $item->method( 'get_gateway' )->willReturn( 'stripe' ); @@ -253,7 +253,7 @@ public function test_column_total_returns_currency_with_gateway(): void { public function test_column_product_returns_no_product_when_null(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_product' ] ) + ->addMethods( ['get_product'] ) ->getMock(); $item->method( 'get_product' )->willReturn( null ); @@ -268,13 +268,13 @@ public function test_column_product_returns_no_product_when_null(): void { public function test_column_product_returns_product_name_when_exists(): void { $product = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_id', 'get_name' ] ) + ->addMethods( ['get_id', 'get_name'] ) ->getMock(); $product->method( 'get_id' )->willReturn( 1 ); $product->method( 'get_name' )->willReturn( 'Pro Plan' ); $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_product' ] ) + ->addMethods( ['get_product'] ) ->getMock(); $item->method( 'get_product' )->willReturn( $product ); diff --git a/tests/WP_Ultimo/List_Tables/Site_List_Table_Test.php b/tests/WP_Ultimo/List_Tables/Site_List_Table_Test.php index 25a3a1081..1e122cd46 100644 --- a/tests/WP_Ultimo/List_Tables/Site_List_Table_Test.php +++ b/tests/WP_Ultimo/List_Tables/Site_List_Table_Test.php @@ -183,7 +183,7 @@ public function test_get_bulk_actions_applies_filter(): void { add_filter( 'wu_site_list_get_bulk_actions', - function ( $actions ) { + function ($actions) { $actions['custom_action'] = 'Custom'; return $actions; } @@ -206,7 +206,7 @@ function ( $actions ) { public function test_column_cb_returns_checkbox_with_blog_id(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_type', 'get_id', 'get_membership_id' ] ) + ->addMethods( ['get_type', 'get_id', 'get_membership_id'] ) ->getMock(); $item->method( 'get_type' )->willReturn( 'customer_owned' ); $item->method( 'get_id' )->willReturn( 3 ); @@ -226,7 +226,7 @@ public function test_column_cb_returns_membership_id_for_pending_site_in_pending $_REQUEST['type'] = 'pending'; $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_type', 'get_id', 'get_membership_id' ] ) + ->addMethods( ['get_type', 'get_id', 'get_membership_id'] ) ->getMock(); $item->method( 'get_type' )->willReturn( 'pending' ); $item->method( 'get_id' )->willReturn( 3 ); @@ -247,7 +247,7 @@ public function test_column_cb_returns_empty_for_pending_site_in_all_view(): voi $_REQUEST['type'] = 'all'; $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_type', 'get_id', 'get_membership_id' ] ) + ->addMethods( ['get_type', 'get_id', 'get_membership_id'] ) ->getMock(); $item->method( 'get_type' )->willReturn( 'pending' ); $item->method( 'get_id' )->willReturn( 3 ); @@ -267,7 +267,7 @@ public function test_column_cb_returns_empty_for_pending_site_with_no_type(): vo unset( $_REQUEST['type'] ); $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_type', 'get_id', 'get_membership_id' ] ) + ->addMethods( ['get_type', 'get_id', 'get_membership_id'] ) ->getMock(); $item->method( 'get_type' )->willReturn( 'pending' ); $item->method( 'get_id' )->willReturn( 3 ); @@ -287,7 +287,7 @@ public function test_column_cb_returns_empty_for_pending_site_with_no_type(): vo public function test_column_type_returns_span_with_label(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_type_label', 'get_type_class' ] ) + ->addMethods( ['get_type_label', 'get_type_class'] ) ->getMock(); $item->method( 'get_type_label' )->willReturn( 'Customer Owned' ); $item->method( 'get_type_class' )->willReturn( 'wu-bg-blue-200' ); @@ -309,7 +309,7 @@ public function test_column_type_returns_span_with_label(): void { public function test_column_blog_id_returns_dash_for_pending(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_type', 'get_blog_id' ] ) + ->addMethods( ['get_type', 'get_blog_id'] ) ->getMock(); $item->method( 'get_type' )->willReturn( \WP_Ultimo\Database\Sites\Site_Type::PENDING ); @@ -324,7 +324,7 @@ public function test_column_blog_id_returns_dash_for_pending(): void { public function test_column_blog_id_returns_blog_id_for_non_pending(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_type', 'get_blog_id' ] ) + ->addMethods( ['get_type', 'get_blog_id'] ) ->getMock(); $item->method( 'get_type' )->willReturn( 'customer_owned' ); $item->method( 'get_blog_id' )->willReturn( 5 ); diff --git a/tests/WP_Ultimo/List_Tables/Webhook_List_Table_Test.php b/tests/WP_Ultimo/List_Tables/Webhook_List_Table_Test.php index e8d1601aa..b0c45026d 100644 --- a/tests/WP_Ultimo/List_Tables/Webhook_List_Table_Test.php +++ b/tests/WP_Ultimo/List_Tables/Webhook_List_Table_Test.php @@ -107,7 +107,7 @@ public function test_get_sortable_columns_returns_array(): void { public function test_column_default_returns_value_from_getter(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_name' ] ) + ->addMethods( ['get_name'] ) ->getMock(); $item->method( 'get_name' )->willReturn( 'My Webhook' ); @@ -126,7 +126,7 @@ public function test_column_default_returns_value_from_getter(): void { public function test_column_webhook_url_returns_truncated_url_in_span(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_webhook_url' ] ) + ->addMethods( ['get_webhook_url'] ) ->getMock(); $item->method( 'get_webhook_url' )->willReturn( 'https://example.com/webhook/endpoint' ); @@ -145,7 +145,7 @@ public function test_column_webhook_url_truncates_long_urls(): void { $long_url = 'https://example.com/webhook/endpoint/with/a/very/long/path/that/exceeds/fifty/characters/limit'; $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_webhook_url' ] ) + ->addMethods( ['get_webhook_url'] ) ->getMock(); $item->method( 'get_webhook_url' )->willReturn( $long_url ); @@ -164,7 +164,7 @@ public function test_column_webhook_url_truncates_long_urls(): void { public function test_column_event_returns_event_in_span(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_event' ] ) + ->addMethods( ['get_event'] ) ->getMock(); $item->method( 'get_event' )->willReturn( 'membership.created' ); @@ -185,7 +185,7 @@ public function test_column_event_returns_event_in_span(): void { public function test_column_active_returns_yes_for_active(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'is_active' ] ) + ->addMethods( ['is_active'] ) ->getMock(); $item->method( 'is_active' )->willReturn( true ); @@ -200,7 +200,7 @@ public function test_column_active_returns_yes_for_active(): void { public function test_column_active_returns_no_for_inactive(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'is_active' ] ) + ->addMethods( ['is_active'] ) ->getMock(); $item->method( 'is_active' )->willReturn( false ); @@ -219,7 +219,7 @@ public function test_column_active_returns_no_for_inactive(): void { public function test_column_integration_returns_formatted_name(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_integration' ] ) + ->addMethods( ['get_integration'] ) ->getMock(); $item->method( 'get_integration' )->willReturn( 'zapier_integration' ); @@ -239,7 +239,7 @@ public function test_column_integration_returns_formatted_name(): void { public function test_column_count_returns_count_value(): void { $item = $this->getMockBuilder( \stdClass::class ) - ->addMethods( [ 'get_count' ] ) + ->addMethods( ['get_count'] ) ->getMock(); $item->method( 'get_count' )->willReturn( 42 ); diff --git a/tests/WP_Ultimo/Logger_Test.php b/tests/WP_Ultimo/Logger_Test.php index 52143b5ce..be8343a96 100644 --- a/tests/WP_Ultimo/Logger_Test.php +++ b/tests/WP_Ultimo/Logger_Test.php @@ -298,7 +298,7 @@ public function test_add_fires_action(): void { public function test_add_disabled_logging(): void { // Directly manipulate the settings array to avoid the is_callable bug - $settings = \WP_Ultimo()->settings->get_all(); + $settings = \WP_Ultimo()->settings->get_all(); $settings['error_logging_level'] = 'disabled'; wu_save_option('wp-ultimo_settings', $settings); diff --git a/tests/WP_Ultimo/MCP_Adapter_Test.php b/tests/WP_Ultimo/MCP_Adapter_Test.php index 03b4d32a6..f6cd8e13a 100644 --- a/tests/WP_Ultimo/MCP_Adapter_Test.php +++ b/tests/WP_Ultimo/MCP_Adapter_Test.php @@ -38,7 +38,7 @@ public function test_init_registers_hooks() { $instance->init(); // The MCP adapter core class exists in this env, so hooks get registered - $has_adapter_hook = has_action('init', [$instance, 'initialize_adapter']); + $has_adapter_hook = has_action('init', [$instance, 'initialize_adapter']); $has_settings_hook = has_action('init', [$instance, 'add_settings']); // Both should be registered (truthy priority) or both not (false) diff --git a/tests/WP_Ultimo/Managers/Broadcast_Manager_Test.php b/tests/WP_Ultimo/Managers/Broadcast_Manager_Test.php index 72149d87c..d2f1363b8 100644 --- a/tests/WP_Ultimo/Managers/Broadcast_Manager_Test.php +++ b/tests/WP_Ultimo/Managers/Broadcast_Manager_Test.php @@ -24,5 +24,4 @@ protected function get_expected_slug(): ?string { protected function get_expected_model_class(): ?string { return \WP_Ultimo\Models\Broadcast::class; } - } diff --git a/tests/WP_Ultimo/Managers/DNS_Record_Manager_Test.php b/tests/WP_Ultimo/Managers/DNS_Record_Manager_Test.php index 241836052..c1a4734f3 100644 --- a/tests/WP_Ultimo/Managers/DNS_Record_Manager_Test.php +++ b/tests/WP_Ultimo/Managers/DNS_Record_Manager_Test.php @@ -757,8 +757,8 @@ public function test_export_to_bind_empty_records(): void { * Test parse_bind_format with standard records. */ public function test_parse_bind_format_standard_records(): void { - $bind_content = <<manager->export_to_bind('example.com', $original_records); - $parsed = $this->manager->parse_bind_format($bind, 'example.com'); + $bind = $this->manager->export_to_bind('example.com', $original_records); + $parsed = $this->manager->parse_bind_format($bind, 'example.com'); $this->assertIsArray($parsed); $this->assertGreaterThanOrEqual(2, count($parsed)); diff --git a/tests/WP_Ultimo/Managers/Event_Manager_Test.php b/tests/WP_Ultimo/Managers/Event_Manager_Test.php index 108037148..e1795c919 100644 --- a/tests/WP_Ultimo/Managers/Event_Manager_Test.php +++ b/tests/WP_Ultimo/Managers/Event_Manager_Test.php @@ -36,14 +36,14 @@ protected function get_expected_model_class(): ?string { * @param array $overrides Optional field overrides. * @return Event */ - private function create_event( array $overrides = [] ): Event { + private function create_event(array $overrides = []): Event { $defaults = [ 'object_id' => 0, 'object_type' => 'network', 'severity' => Event::SEVERITY_INFO, 'slug' => 'test-event-' . wp_rand(), - 'payload' => [ 'key' => 'value' ], + 'payload' => ['key' => 'value'], 'initiator' => 'system', 'date_created' => wu_get_current_time( 'mysql', true ), ]; @@ -67,7 +67,7 @@ public function test_register_and_get_event(): void { $result = $manager->register_event( 'test_event', [ 'name' => 'Test Event', - 'payload' => [ 'key' => 'value' ], + 'payload' => ['key' => 'value'], ] ); $this->assertTrue( $result ); @@ -107,8 +107,14 @@ public function test_register_multiple_events_accumulates(): void { $manager = $this->get_manager_instance(); - $manager->register_event( 'multi_a', [ 'name' => 'A', 'payload' => [] ] ); - $manager->register_event( 'multi_b', [ 'name' => 'B', 'payload' => [] ] ); + $manager->register_event( 'multi_a', [ + 'name' => 'A', + 'payload' => [], + ] ); + $manager->register_event( 'multi_b', [ + 'name' => 'B', + 'payload' => [], + ] ); $this->assertIsArray( $manager->get_event( 'multi_a' ) ); $this->assertIsArray( $manager->get_event( 'multi_b' ) ); @@ -123,7 +129,7 @@ public function test_register_event_with_callable_payload(): void { $manager->register_event( 'callable_event', [ 'name' => 'Callable', - 'payload' => fn() => [ 'lazy' => 'loaded' ], + 'payload' => fn() => ['lazy' => 'loaded'], ] ); $event = $manager->get_event( 'callable_event' ); @@ -156,22 +162,22 @@ public function test_do_event_fires_actions(): void { $manager->register_event( 'test_fire', [ 'name' => 'Fire Test', - 'payload' => [ 'sample' => 'data' ], + 'payload' => ['sample' => 'data'], ] ); $generic_fired = false; $specific_fired = false; - add_action( 'wu_event', function () use ( &$generic_fired ) { + add_action( 'wu_event', function () use (&$generic_fired) { $generic_fired = true; } ); - add_action( 'wu_event_test_fire', function () use ( &$specific_fired ) { + add_action( 'wu_event_test_fire', function () use (&$specific_fired) { $specific_fired = true; } ); // Actions fire before save_event; save may fail validation (no initiator). - $manager->do_event( 'test_fire', [ 'sample' => 'data' ] ); + $manager->do_event( 'test_fire', ['sample' => 'data'] ); $this->assertTrue( $generic_fired, 'wu_event action should have fired.' ); $this->assertTrue( $specific_fired, 'wu_event_test_fire action should have fired.' ); @@ -186,18 +192,18 @@ public function test_do_event_passes_slug_and_payload_to_action(): void { $manager->register_event( 'slug_check', [ 'name' => 'Slug Check', - 'payload' => [ 'foo' => 'bar' ], + 'payload' => ['foo' => 'bar'], ] ); $captured_slug = null; $captured_payload = null; - add_action( 'wu_event', function ( $slug, $payload ) use ( &$captured_slug, &$captured_payload ) { + add_action( 'wu_event', function ($slug, $payload) use (&$captured_slug, &$captured_payload) { $captured_slug = $slug; $captured_payload = $payload; }, 10, 2 ); - $manager->do_event( 'slug_check', [ 'foo' => 'bar' ] ); + $manager->do_event( 'slug_check', ['foo' => 'bar'] ); $this->assertEquals( 'slug_check', $captured_slug ); $this->assertArrayHasKey( 'foo', $captured_payload ); @@ -212,16 +218,16 @@ public function test_do_event_appends_wu_version(): void { $manager->register_event( 'version_check', [ 'name' => 'Version Check', - 'payload' => [ 'item' => 'val' ], + 'payload' => ['item' => 'val'], ] ); $captured_payload = null; - add_action( 'wu_event_version_check', function ( $payload ) use ( &$captured_payload ) { + add_action( 'wu_event_version_check', function ($payload) use (&$captured_payload) { $captured_payload = $payload; } ); - $manager->do_event( 'version_check', [ 'item' => 'val' ] ); + $manager->do_event( 'version_check', ['item' => 'val'] ); $this->assertNotNull( $captured_payload ); $this->assertArrayHasKey( 'wu_version', $captured_payload ); @@ -237,7 +243,7 @@ public function test_do_event_returns_false_for_missing_payload_keys(): void { // Register event with a required payload key (non-callable array with index 0). $manager->register_event( 'strict_payload', [ 'name' => 'Strict', - 'payload' => [ [ 'required_key' => 'placeholder' ] ], + 'payload' => [['required_key' => 'placeholder']], ] ); // Pass empty payload — missing required_key. @@ -263,7 +269,7 @@ public function test_save_event_with_valid_payload(): void { 'object_type' => 'test', 'severity' => Event::SEVERITY_INFO, 'slug' => 'test_direct_save', - 'payload' => [ 'key' => 'value' ], + 'payload' => ['key' => 'value'], 'initiator' => 'system', 'date_created' => wu_get_current_time( 'mysql', true ), ] @@ -317,7 +323,7 @@ public function test_save_event_with_invalid_data_returns_false(): void { */ public function test_register_model_events(): void { - Event_Manager::register_model_events( 'test_model', 'Test Model', [ 'created', 'updated' ] ); + Event_Manager::register_model_events( 'test_model', 'Test Model', ['created', 'updated'] ); $manager = $this->get_manager_instance(); $models_events = $this->get_protected_property( $manager, 'models_events' ); @@ -332,8 +338,8 @@ public function test_register_model_events(): void { */ public function test_register_model_events_overwrites_existing(): void { - Event_Manager::register_model_events( 'overwrite_model', 'Old Label', [ 'created' ] ); - Event_Manager::register_model_events( 'overwrite_model', 'New Label', [ 'created', 'updated' ] ); + Event_Manager::register_model_events( 'overwrite_model', 'Old Label', ['created'] ); + Event_Manager::register_model_events( 'overwrite_model', 'New Label', ['created', 'updated'] ); $manager = $this->get_manager_instance(); $models_events = $this->get_protected_property( $manager, 'models_events' ); @@ -363,7 +369,7 @@ public function test_dispatch_base_model_event_skips_unregistered_model(): void */ public function test_dispatch_base_model_event_skips_unregistered_type(): void { - Event_Manager::register_model_events( 'dispatch_model', 'Dispatch Model', [ 'created' ] ); + Event_Manager::register_model_events( 'dispatch_model', 'Dispatch Model', ['created'] ); $manager = $this->get_manager_instance(); @@ -400,9 +406,11 @@ public function test_log_transitions_creates_event_for_new_object(): void { $manager = $this->get_manager_instance(); - $obj = new class extends \WP_Ultimo\Models\Base_Model { - public function get_id(): int { return 1; } - public function validation_rules(): array { return []; } + $obj = new class() extends \WP_Ultimo\Models\Base_Model { + public function get_id(): int { + return 1; } + public function validation_rules(): array { + return []; } }; // No 'id' key in data_unserialized → treated as new object. @@ -419,16 +427,24 @@ public function test_log_transitions_skips_empty_diff(): void { $manager = $this->get_manager_instance(); // Build a minimal object that has an id and identical original data. - $obj = new class extends \WP_Ultimo\Models\Base_Model { - public function get_id(): int { return 42; } - public function validation_rules(): array { return []; } + $obj = new class() extends \WP_Ultimo\Models\Base_Model { + public function get_id(): int { + return 42; } + public function validation_rules(): array { + return []; } public function _get_original(): array { - return [ 'id' => 42, 'status' => 'active' ]; + return [ + 'id' => 42, + 'status' => 'active', + ]; } }; // data_unserialized matches original → diff is empty → early return. - $manager->log_transitions( 'membership', [], [ 'id' => 42, 'status' => 'active' ], $obj ); + $manager->log_transitions( 'membership', [], [ + 'id' => 42, + 'status' => 'active', + ], $obj ); $this->assertTrue( true ); } @@ -440,16 +456,18 @@ public function test_log_transitions_skips_when_old_id_is_zero(): void { $manager = $this->get_manager_instance(); - $obj = new class extends \WP_Ultimo\Models\Base_Model { - public function get_id(): int { return 1; } - public function validation_rules(): array { return []; } + $obj = new class() extends \WP_Ultimo\Models\Base_Model { + public function get_id(): int { + return 1; } + public function validation_rules(): array { + return []; } public function _get_original(): array { - return [ 'id' => 0 ]; + return ['id' => 0]; } }; // data_unserialized has 'id' key, original id is 0 → early return. - $manager->log_transitions( 'membership', [], [ 'id' => 1 ], $obj ); + $manager->log_transitions( 'membership', [], ['id' => 1], $obj ); $this->assertTrue( true ); } @@ -482,7 +500,7 @@ public function test_register_all_events_fires_action(): void { $fired = false; - add_action( 'wu_register_all_events', function () use ( &$fired ) { + add_action( 'wu_register_all_events', function () use (&$fired) { $fired = true; } ); @@ -497,7 +515,7 @@ public function test_register_all_events_fires_action(): void { */ public function test_register_all_events_registers_model_events(): void { - Event_Manager::register_model_events( 'site', 'Site', [ 'created', 'updated' ] ); + Event_Manager::register_model_events( 'site', 'Site', ['created', 'updated'] ); $manager = $this->get_manager_instance(); $manager->register_all_events(); @@ -606,7 +624,7 @@ public function test_hooks_endpoint_registers_route_when_api_enabled(): void { * @param array $events The events to set. * @return array The original events array (for restoration). */ - private function set_manager_events( object $manager, array $events ): array { + private function set_manager_events(object $manager, array $events): array { $reflection = new \ReflectionClass( $manager ); $prop = $reflection->getProperty( 'events' ); @@ -630,7 +648,7 @@ public function test_get_hooks_rest_returns_response(): void { $original = $this->set_manager_events( $manager, [ 'rest_test_event' => [ 'name' => 'REST Test', - 'payload' => [ 'foo' => 'bar' ], + 'payload' => ['foo' => 'bar'], ], ] ); @@ -651,7 +669,7 @@ public function test_get_hooks_rest_resolves_callable_payloads(): void { $original = $this->set_manager_events( $manager, [ 'lazy_rest_event' => [ 'name' => 'Lazy REST', - 'payload' => fn() => [ 'resolved' => true ], + 'payload' => fn() => ['resolved' => true], ], ] ); @@ -677,7 +695,7 @@ public function test_get_hooks_rest_leaves_non_callable_payload(): void { $original = $this->set_manager_events( $manager, [ 'static_rest_event' => [ 'name' => 'Static REST', - 'payload' => [ 'static' => 'value' ], + 'payload' => ['static' => 'value'], ], ] ); @@ -689,7 +707,7 @@ public function test_get_hooks_rest_leaves_non_callable_payload(): void { $data = $response->get_data(); $this->assertArrayHasKey( 'static_rest_event', $data ); - $this->assertEquals( [ 'static' => 'value' ], $data['static_rest_event']['payload'] ); + $this->assertEquals( ['static' => 'value'], $data['static_rest_event']['payload'] ); } // ------------------------------------------------------------------------- diff --git a/tests/WP_Ultimo/Managers/Form_Manager_Test.php b/tests/WP_Ultimo/Managers/Form_Manager_Test.php index 4a46a2545..9052cd67d 100644 --- a/tests/WP_Ultimo/Managers/Form_Manager_Test.php +++ b/tests/WP_Ultimo/Managers/Form_Manager_Test.php @@ -56,7 +56,7 @@ private function install_ajax_die_handler(): callable { add_filter('wp_doing_ajax', '__return_true'); $handler = function () { - return function ( $message ) { + return function ($message) { throw new \WPAjaxDieContinueException( (string) $message ); }; }; @@ -72,7 +72,7 @@ private function install_ajax_die_handler(): callable { * @param callable $handler The handler returned by install_ajax_die_handler(). * @return void */ - private function remove_ajax_die_handler( callable $handler ): void { + private function remove_ajax_die_handler(callable $handler): void { remove_filter('wp_doing_ajax', '__return_true'); remove_filter('wp_die_ajax_handler', $handler, 1); @@ -84,7 +84,7 @@ private function remove_ajax_die_handler( callable $handler ): void { * @param callable $callable The callable to invoke. * @return array{output: string, exception: bool} */ - private function call_in_ajax_context( callable $callable ): array { + private function call_in_ajax_context(callable $callable): array { if (defined('REST_REQUEST') && REST_REQUEST) { $this->setExpectedIncorrectUsage('wp_send_json'); @@ -800,9 +800,9 @@ public function test_render_bulk_action_form_renders_html(): void { $manager = $this->get_manager_instance(); - $_REQUEST['bulk_action'] = 'delete'; - $_REQUEST['model'] = 'customer'; - $_REQUEST['bulk-delete'] = ['1', '2', '3']; + $_REQUEST['bulk_action'] = 'delete'; + $_REQUEST['model'] = 'customer'; + $_REQUEST['bulk-delete'] = ['1', '2', '3']; ob_start(); $manager->render_bulk_action_form(); @@ -821,9 +821,9 @@ public function test_render_bulk_action_form_with_custom_action(): void { $manager = $this->get_manager_instance(); - $_REQUEST['bulk_action'] = 'activate'; - $_REQUEST['model'] = 'membership'; - $_REQUEST['bulk-delete'] = []; + $_REQUEST['bulk_action'] = 'activate'; + $_REQUEST['model'] = 'membership'; + $_REQUEST['bulk-delete'] = []; ob_start(); $manager->render_bulk_action_form(); @@ -859,7 +859,7 @@ public function test_handle_bulk_action_form_fires_generic_action(): void { add_action( 'wu_handle_bulk_action_form', - function ( $action, $model, $ids ) use ( &$generic_fired ) { + function ($action, $model, $ids) use (&$generic_fired) { $generic_fired = true; }, 10, @@ -890,7 +890,7 @@ public function test_handle_bulk_action_form_fires_specific_action(): void { add_action( 'wu_handle_bulk_action_form_customer_delete', - function ( $action, $model, $ids ) use ( &$specific_fired ) { + function ($action, $model, $ids) use (&$specific_fired) { $specific_fired = true; }, 10, @@ -922,7 +922,7 @@ public function test_handle_bulk_action_form_passes_ids_array(): void { add_action( 'wu_handle_bulk_action_form', - function ( $action, $model, $ids ) use ( &$received_ids ) { + function ($action, $model, $ids) use (&$received_ids) { $received_ids = $ids; }, 10, @@ -955,7 +955,7 @@ public function test_handle_bulk_action_form_passes_action_and_model(): void { add_action( 'wu_handle_bulk_action_form', - function ( $action, $model, $ids ) use ( &$received_action, &$received_model ) { + function ($action, $model, $ids) use (&$received_action, &$received_model) { $received_action = $action; $received_model = $model; }, @@ -984,7 +984,7 @@ function ( $action, $model, $ids ) use ( &$received_action, &$received_model ) { * @param callable $callable The callable to invoke. * @return array{output: string, exception: bool} */ - private function run_in_ajax_context( callable $callable ): array { + private function run_in_ajax_context(callable $callable): array { return $this->call_in_ajax_context($callable); } @@ -1007,7 +1007,7 @@ public function test_default_bulk_action_handler_sends_success(): void { $_REQUEST['ids'] = '1,2,3'; $result = $this->run_in_ajax_context( - function () use ( $manager ) { + function () use ($manager) { $manager->default_bulk_action_handler('delete', 'customer', ['1', '2', '3']); } ); @@ -1037,7 +1037,7 @@ public function test_default_bulk_action_handler_redirect_url_includes_count(): $ids = ['1', '2', '3']; $result = $this->run_in_ajax_context( - function () use ( $manager, $ids ) { + function () use ($manager, $ids) { $manager->default_bulk_action_handler('delete', 'customer', $ids); } ); @@ -1063,7 +1063,7 @@ public function test_default_bulk_action_handler_empty_ids(): void { $_REQUEST['ids'] = ''; $result = $this->run_in_ajax_context( - function () use ( $manager ) { + function () use ($manager) { $manager->default_bulk_action_handler('delete', 'customer', []); } ); @@ -1118,7 +1118,7 @@ public function test_security_checks_dies_for_non_ajax_request(): void { unset($_SERVER['HTTP_X_REQUESTED_WITH']); $die_handler = function () { - return function ( $message ) { + return function ($message) { throw new \WPDieException( (string) $message ); }; }; @@ -1200,7 +1200,7 @@ public function test_default_bulk_action_handler_sends_error_when_process_fails( $_REQUEST['ids'] = '1,2,3'; $result = $this->run_in_ajax_context( - function () use ( $manager ) { + function () use ($manager) { $manager->default_bulk_action_handler('delete', 'nonexistent_model_xyz', ['1', '2', '3']); } ); diff --git a/tests/WP_Ultimo/Managers/Limitation_Manager_Test.php b/tests/WP_Ultimo/Managers/Limitation_Manager_Test.php index 5f9f1af7e..149e799e0 100644 --- a/tests/WP_Ultimo/Managers/Limitation_Manager_Test.php +++ b/tests/WP_Ultimo/Managers/Limitation_Manager_Test.php @@ -240,7 +240,7 @@ public function test_limitations_exists_method(): void { public function test_limitations_is_module_enabled(): void { $limitations = new Limitations([ - 'sites' => [ + 'sites' => [ 'enabled' => true, 'limit' => 5, ], @@ -345,7 +345,7 @@ public function test_users_limit_module_access(): void { 'enabled' => true, 'number' => 1, ], - 'editor' => [ + 'editor' => [ 'enabled' => true, 'number' => 5, ], @@ -804,7 +804,7 @@ public function test_themes_get_forced_active_theme(): void { 'themes' => [ 'enabled' => true, 'limit' => [ - 'twentytwentyfour' => [ + 'twentytwentyfour' => [ 'visibility' => 'visible', 'behavior' => 'force_active', ], @@ -852,7 +852,7 @@ public function test_themes_get_available_themes(): void { 'themes' => [ 'enabled' => true, 'limit' => [ - 'twentytwentyfour' => [ + 'twentytwentyfour' => [ 'visibility' => 'visible', 'behavior' => 'available', ], @@ -860,7 +860,7 @@ public function test_themes_get_available_themes(): void { 'visibility' => 'visible', 'behavior' => 'not_available', ], - 'twentytwentytwo' => [ + 'twentytwentytwo' => [ 'visibility' => 'visible', 'behavior' => 'available', ], @@ -1404,7 +1404,7 @@ public function test_site_templates_get_available(): void { 'behavior' => 'pre_selected', ], ], - 'mode' => 'choose_available_templates', + 'mode' => 'choose_available_templates', ], ]); @@ -1431,7 +1431,7 @@ public function test_site_templates_get_pre_selected(): void { 'behavior' => 'pre_selected', ], ], - 'mode' => 'choose_available_templates', + 'mode' => 'choose_available_templates', ], ]); @@ -1453,7 +1453,7 @@ public function test_site_templates_get_pre_selected_returns_false(): void { 'behavior' => 'available', ], ], - 'mode' => 'choose_available_templates', + 'mode' => 'choose_available_templates', ], ]); @@ -1710,8 +1710,8 @@ public function test_merge_plugin_behavior_priorities(): void { ], ]; - $base = new Limitations($base_data); - $merged = $base->merge($override_data); + $base = new Limitations($base_data); + $merged = $base->merge($override_data); // force_active has higher priority than default, so it should win $plugin = $merged->plugins->{'akismet/akismet.php'}; @@ -1805,7 +1805,7 @@ public function test_merge_visibility_priorities(): void { public function test_limitations_serialization(): void { $data = [ - 'sites' => [ + 'sites' => [ 'enabled' => true, 'limit' => 5, ], @@ -2623,7 +2623,7 @@ public function test_limitations_all_disabled(): void { public function test_limitations_mixed_enabled_disabled(): void { $limitations = new Limitations([ - 'sites' => [ + 'sites' => [ 'enabled' => true, 'limit' => 5, ], diff --git a/tests/WP_Ultimo/Managers/Notes_Manager_Test.php b/tests/WP_Ultimo/Managers/Notes_Manager_Test.php index 7c9c6b56c..009b3cb3c 100644 --- a/tests/WP_Ultimo/Managers/Notes_Manager_Test.php +++ b/tests/WP_Ultimo/Managers/Notes_Manager_Test.php @@ -106,7 +106,7 @@ private function install_ajax_die_handler(): callable { add_filter('wp_doing_ajax', '__return_true'); $handler = function () { - return function ( $message ) { + return function ($message) { throw new \WPAjaxDieContinueException((string) $message); }; }; @@ -121,7 +121,7 @@ private function install_ajax_die_handler(): callable { * * @param callable $handler The handler returned by install_ajax_die_handler(). */ - private function remove_ajax_die_handler( callable $handler ): void { + private function remove_ajax_die_handler(callable $handler): void { remove_filter('wp_doing_ajax', '__return_true'); remove_filter('wp_die_ajax_handler', $handler, 1); } @@ -132,7 +132,7 @@ private function remove_ajax_die_handler( callable $handler ): void { * @param callable $callable The callable to invoke. * @return array */ - private function capture_json_response( callable $callable ): array { + private function capture_json_response(callable $callable): array { $handler = $this->install_ajax_die_handler(); $exception = null; @@ -453,7 +453,7 @@ public function test_render_add_note_modal_applies_filter(): void { add_filter( 'wu_notes_options_section_fields', - function ( $fields ) use ( &$filter_fired ) { + function ($fields) use (&$filter_fired) { $filter_fired = true; return $fields; } diff --git a/tests/WP_Ultimo/Managers/Site_Manager_Test.php b/tests/WP_Ultimo/Managers/Site_Manager_Test.php index 1b8c14c65..155b9168d 100644 --- a/tests/WP_Ultimo/Managers/Site_Manager_Test.php +++ b/tests/WP_Ultimo/Managers/Site_Manager_Test.php @@ -79,10 +79,10 @@ public function test_filter_illegal_search_keys(): void { $manager = $this->get_manager_instance(); $input = [ - 'good_key' => 'value1', - '' => 'value2', - 'another' => 'value3', - false => 'value4', + 'good_key' => 'value1', + '' => 'value2', + 'another' => 'value3', + false => 'value4', ]; $result = $manager->filter_illegal_search_keys($input); @@ -100,9 +100,18 @@ public function test_get_search_and_replace_settings(): void { wu_save_setting( 'search_and_replace', [ - ['search' => 'foo', 'replace' => 'bar'], - ['search' => '', 'replace' => 'baz'], - ['search' => 'hello', 'replace' => 'world'], + [ + 'search' => 'foo', + 'replace' => 'bar', + ], + [ + 'search' => '', + 'replace' => 'baz', + ], + [ + 'search' => 'hello', + 'replace' => 'world', + ], ] ); @@ -366,9 +375,9 @@ public function test_filter_illegal_search_keys_numeric_keys(): void { $manager = $this->get_manager_instance(); $input = [ - '0' => 'zero-string', - 1 => 'one-int', - 'key' => 'value', + '0' => 'zero-string', + 1 => 'one-int', + 'key' => 'value', ]; // Note: PHP treats '0' and 0 as the same array key, but both should be filtered as empty/false-like @@ -406,7 +415,10 @@ public function test_get_search_and_replace_settings_skips_missing_search(): voi 'search_and_replace', [ ['replace' => 'bar'], - ['search' => 'hello', 'replace' => 'world'], + [ + 'search' => 'hello', + 'replace' => 'world', + ], ] ); @@ -425,7 +437,10 @@ public function test_get_search_and_replace_settings_allows_empty_replace(): voi wu_save_setting( 'search_and_replace', [ - ['search' => 'remove-me', 'replace' => ''], + [ + 'search' => 'remove-me', + 'replace' => '', + ], ] ); @@ -448,7 +463,10 @@ public function test_search_and_replace_on_duplication_merges(): void { wu_save_setting( 'search_and_replace', [ - ['search' => 'old-domain', 'replace' => 'new-domain'], + [ + 'search' => 'old-domain', + 'replace' => 'new-domain', + ], ] ); @@ -545,7 +563,10 @@ public function test_hide_super_admin_preserves_existing_args(): void { $user_id = $this->factory()->user->create(['role' => 'subscriber']); wp_set_current_user($user_id); - $args = ['role' => 'editor', 'number' => 10]; + $args = [ + 'role' => 'editor', + 'number' => 10, + ]; $result = $manager->hide_super_admin_from_list($args); $this->assertArrayHasKey('login__not_in', $result); @@ -1452,7 +1473,10 @@ public function test_site_signup_options(): void { $site = new \WP_Ultimo\Models\Site(); - $options = ['option1' => 'value1', 'option2' => 'value2']; + $options = [ + 'option1' => 'value1', + 'option2' => 'value2', + ]; $site->set_signup_options($options); @@ -1776,7 +1800,10 @@ public function test_site_transient(): void { $site = new \WP_Ultimo\Models\Site(); - $data = ['key1' => 'value1', 'key2' => 'value2']; + $data = [ + 'key1' => 'value1', + 'key2' => 'value2', + ]; $site->set_transient($data); diff --git a/tests/WP_Ultimo/Models/Base_Model_Test.php b/tests/WP_Ultimo/Models/Base_Model_Test.php index 1a613ecae..0fdf48ced 100644 --- a/tests/WP_Ultimo/Models/Base_Model_Test.php +++ b/tests/WP_Ultimo/Models/Base_Model_Test.php @@ -59,8 +59,8 @@ public function test_constructor_accepts_array(): void { */ public function test_constructor_accepts_stdclass(): void { - $user_id = self::factory()->user->create(); - $obj = new \stdClass(); + $user_id = self::factory()->user->create(); + $obj = new \stdClass(); $obj->user_id = $user_id; $customer = new Customer($obj); diff --git a/tests/WP_Ultimo/Models/Checkout_Form_Test.php b/tests/WP_Ultimo/Models/Checkout_Form_Test.php index 1b47a0ff1..f94c6ba0a 100644 --- a/tests/WP_Ultimo/Models/Checkout_Form_Test.php +++ b/tests/WP_Ultimo/Models/Checkout_Form_Test.php @@ -967,7 +967,12 @@ public function test_use_template_blank(): void { $checkout_form->set_settings([ [ 'id' => 'step1', - 'fields' => [['id' => 'field1', 'type' => 'text']], + 'fields' => [ + [ + 'id' => 'field1', + 'type' => 'text', + ], + ], ], ]); @@ -1199,22 +1204,40 @@ public function test_field_count_across_multiple_steps(): void { [ 'id' => 'step1', 'fields' => [ - ['id' => 'f1', 'type' => 'email'], - ['id' => 'f2', 'type' => 'text'], + [ + 'id' => 'f1', + 'type' => 'email', + ], + [ + 'id' => 'f2', + 'type' => 'text', + ], ], ], [ 'id' => 'step2', 'fields' => [ - ['id' => 'f3', 'type' => 'password'], - ['id' => 'f4', 'type' => 'site_title'], - ['id' => 'f5', 'type' => 'submit_button'], + [ + 'id' => 'f3', + 'type' => 'password', + ], + [ + 'id' => 'f4', + 'type' => 'site_title', + ], + [ + 'id' => 'f5', + 'type' => 'submit_button', + ], ], ], [ 'id' => 'step3', 'fields' => [ - ['id' => 'f6', 'type' => 'payment'], + [ + 'id' => 'f6', + 'type' => 'payment', + ], ], ], ]; @@ -1235,14 +1258,26 @@ public function test_get_field_from_specific_step_in_multi_step(): void { [ 'id' => 'step1', 'fields' => [ - ['id' => 'email', 'type' => 'email', 'name' => 'Email'], + [ + 'id' => 'email', + 'type' => 'email', + 'name' => 'Email', + ], ], ], [ 'id' => 'step2', 'fields' => [ - ['id' => 'site_title', 'type' => 'site_title', 'name' => 'Title'], - ['id' => 'site_url', 'type' => 'site_url', 'name' => 'URL'], + [ + 'id' => 'site_title', + 'type' => 'site_title', + 'name' => 'Title', + ], + [ + 'id' => 'site_url', + 'type' => 'site_url', + 'name' => 'URL', + ], ], ], ]; @@ -1265,7 +1300,7 @@ public function test_get_field_from_specific_step_in_multi_step(): void { */ public function test_convert_steps_to_v2_basic(): void { $old_steps = [ - 'begin-signup' => [ + 'begin-signup' => [ 'name' => 'Begin Signup', 'fields' => [], ], @@ -1273,7 +1308,7 @@ public function test_convert_steps_to_v2_basic(): void { 'name' => 'Create Account', 'fields' => [], ], - 'account' => [ + 'account' => [ 'name' => 'Account Info', 'fields' => [ 'submit' => [ @@ -1308,15 +1343,15 @@ public function test_convert_steps_to_v2_field_conversions(): void { 'account' => [ 'name' => 'Account', 'fields' => [ - 'user_name' => [ + 'user_name' => [ 'name' => 'Username', 'type' => 'text', ], - 'user_email' => [ + 'user_email' => [ 'name' => 'Email', 'type' => 'email', ], - 'user_pass' => [ + 'user_pass' => [ 'name' => 'Password', 'type' => 'password', ], @@ -1324,11 +1359,11 @@ public function test_convert_steps_to_v2_field_conversions(): void { 'name' => 'Confirm Password', 'type' => 'password', ], - 'blog_title' => [ + 'blog_title' => [ 'name' => 'Blog Title', 'type' => 'text', ], - 'blogname' => [ + 'blogname' => [ 'name' => 'Blog URL', 'type' => 'text', ], @@ -1396,11 +1431,11 @@ public function test_convert_steps_to_v2_skips_special_fields(): void { 'name' => 'URL Preview', 'type' => 'text', ], - 'site_url' => [ + 'site_url' => [ 'name' => 'Site URL', 'type' => 'text', ], - 'user_name' => [ + 'user_name' => [ 'name' => 'Username', 'type' => 'text', ], @@ -1679,7 +1714,10 @@ public function test_get_all_fields_single_step_single_field(): void { [ 'id' => 'step1', 'fields' => [ - ['id' => 'email', 'type' => 'email'], + [ + 'id' => 'email', + 'type' => 'email', + ], ], ], ]; @@ -1719,15 +1757,42 @@ public function test_get_all_fields_by_type_empty_fields(): void { */ private function get_valid_settings(array $extra_fields = []): array { $fields = [ - ['id' => 'username', 'type' => 'username'], - ['id' => 'password', 'type' => 'password'], - ['id' => 'email_address', 'type' => 'email'], - ['id' => 'site_title', 'type' => 'site_title'], - ['id' => 'site_url', 'type' => 'site_url'], - ['id' => 'billing_address', 'type' => 'billing_address'], - ['id' => 'order_summary', 'type' => 'order_summary'], - ['id' => 'payment', 'type' => 'payment'], - ['id' => 'submit', 'type' => 'submit_button'], + [ + 'id' => 'username', + 'type' => 'username', + ], + [ + 'id' => 'password', + 'type' => 'password', + ], + [ + 'id' => 'email_address', + 'type' => 'email', + ], + [ + 'id' => 'site_title', + 'type' => 'site_title', + ], + [ + 'id' => 'site_url', + 'type' => 'site_url', + ], + [ + 'id' => 'billing_address', + 'type' => 'billing_address', + ], + [ + 'id' => 'order_summary', + 'type' => 'order_summary', + ], + [ + 'id' => 'payment', + 'type' => 'payment', + ], + [ + 'id' => 'submit', + 'type' => 'submit_button', + ], ]; $fields = array_merge($fields, $extra_fields); @@ -1746,7 +1811,10 @@ private function get_valid_settings(array $extra_fields = []): array { */ public function test_create_checkout_form_via_helper_function(): void { $settings = $this->get_valid_settings([ - ['id' => 'email', 'type' => 'email'], + [ + 'id' => 'email', + 'type' => 'email', + ], ]); $checkout_form = wu_create_checkout_form([ @@ -1802,8 +1870,14 @@ public function test_get_checkout_form_by_slug(): void { */ public function test_settings_persist_after_save(): void { $settings = $this->get_valid_settings([ - ['id' => 'field1', 'type' => 'email'], - ['id' => 'field2', 'type' => 'text'], + [ + 'id' => 'field1', + 'type' => 'email', + ], + [ + 'id' => 'field2', + 'type' => 'text', + ], ]); $checkout_form = wu_create_checkout_form([ @@ -1927,7 +2001,10 @@ public function test_get_steps_to_show_defaults_logged_to_always(): void { [ 'id' => 'no_logged_key', 'fields' => [ - ['id' => 'email', 'type' => 'email'], + [ + 'id' => 'email', + 'type' => 'email', + ], ], ], ]; @@ -2045,11 +2122,26 @@ public function test_get_all_fields_by_type_with_array_input(): void { [ 'id' => 'checkout', 'fields' => [ - ['id' => 'email', 'type' => 'email'], - ['id' => 'pass', 'type' => 'password'], - ['id' => 'user', 'type' => 'username'], - ['id' => 'title', 'type' => 'site_title'], - ['id' => 'url', 'type' => 'site_url'], + [ + 'id' => 'email', + 'type' => 'email', + ], + [ + 'id' => 'pass', + 'type' => 'password', + ], + [ + 'id' => 'user', + 'type' => 'username', + ], + [ + 'id' => 'title', + 'type' => 'site_title', + ], + [ + 'id' => 'url', + 'type' => 'site_url', + ], ], ], ]; @@ -2361,7 +2453,7 @@ public function test_save_with_template_applies_template(): void { $this->assertInstanceOf(Checkout_Form::class, $form); // After save with template='single-step', settings should be populated. - $fetched = wu_get_checkout_form($form->get_id()); + $fetched = wu_get_checkout_form($form->get_id()); $settings = $fetched->get_settings(); $this->assertNotEmpty($settings); @@ -2382,7 +2474,7 @@ public function test_save_with_multi_step_template_applies_template(): void { $this->assertNotWPError($form); - $fetched = wu_get_checkout_form($form->get_id()); + $fetched = wu_get_checkout_form($form->get_id()); $settings = $fetched->get_settings(); $this->assertNotEmpty($settings); diff --git a/tests/WP_Ultimo/Models/Membership_Test.php b/tests/WP_Ultimo/Models/Membership_Test.php index 10761df60..7080a49d6 100644 --- a/tests/WP_Ultimo/Models/Membership_Test.php +++ b/tests/WP_Ultimo/Models/Membership_Test.php @@ -58,17 +58,17 @@ public function setUp(): void { // Create product directly. $this->product = new Product( [ - 'name' => 'Test Plan', - 'slug' => 'test-plan-' . wp_generate_password(6, false), - 'description' => 'A test plan', - 'pricing_type' => 'paid', - 'amount' => 29.99, - 'currency' => 'USD', - 'duration' => 1, + 'name' => 'Test Plan', + 'slug' => 'test-plan-' . wp_generate_password(6, false), + 'description' => 'A test plan', + 'pricing_type' => 'paid', + 'amount' => 29.99, + 'currency' => 'USD', + 'duration' => 1, 'duration_unit' => 'month', - 'type' => 'plan', - 'recurring' => true, - 'active' => true, + 'type' => 'plan', + 'recurring' => true, + 'active' => true, ] ); $this->product->set_skip_validation(true); @@ -77,20 +77,20 @@ public function setUp(): void { // Create a membership tied to the customer and product. $this->membership = new Membership( [ - 'customer_id' => $this->customer->get_id(), - 'user_id' => $user_id, - 'plan_id' => $this->product->get_id(), - 'status' => Membership_Status::ACTIVE, - 'amount' => 29.99, - 'initial_amount' => 29.99, - 'duration' => 1, - 'duration_unit' => 'month', - 'recurring' => true, - 'auto_renew' => true, - 'currency' => 'USD', - 'gateway' => '', - 'date_created' => gmdate('Y-m-d H:i:s'), - 'date_modified' => gmdate('Y-m-d H:i:s'), + 'customer_id' => $this->customer->get_id(), + 'user_id' => $user_id, + 'plan_id' => $this->product->get_id(), + 'status' => Membership_Status::ACTIVE, + 'amount' => 29.99, + 'initial_amount' => 29.99, + 'duration' => 1, + 'duration_unit' => 'month', + 'recurring' => true, + 'auto_renew' => true, + 'currency' => 'USD', + 'gateway' => '', + 'date_created' => gmdate('Y-m-d H:i:s'), + 'date_modified' => gmdate('Y-m-d H:i:s'), 'date_expiration' => gmdate('Y-m-d H:i:s', strtotime('+30 days')), ] ); @@ -546,10 +546,10 @@ public function test_has_gateway_changes(): void { // Create a fresh membership to have clean gateway_info state. $m = new Membership( [ - 'customer_id' => $this->customer->get_id(), - 'plan_id' => $this->product->get_id(), - 'status' => Membership_Status::ACTIVE, - 'gateway' => 'stripe', + 'customer_id' => $this->customer->get_id(), + 'plan_id' => $this->product->get_id(), + 'status' => Membership_Status::ACTIVE, + 'gateway' => 'stripe', 'gateway_customer_id' => 'cus_old', 'gateway_subscription_id' => 'sub_old', ] @@ -578,15 +578,15 @@ public function test_add_product(): void { // Create an addon product. $addon = new Product( [ - 'name' => 'Addon Product', - 'slug' => 'addon-product-' . wp_generate_password(6, false), - 'pricing_type' => 'paid', - 'amount' => 9.99, - 'currency' => 'USD', - 'duration' => 1, + 'name' => 'Addon Product', + 'slug' => 'addon-product-' . wp_generate_password(6, false), + 'pricing_type' => 'paid', + 'amount' => 9.99, + 'currency' => 'USD', + 'duration' => 1, 'duration_unit' => 'month', - 'type' => 'package', - 'active' => true, + 'type' => 'package', + 'active' => true, ] ); $addon->set_skip_validation(true); @@ -599,7 +599,7 @@ public function test_add_product(): void { $this->assertContains($product_id, $addon_ids); $addon_products = $this->membership->get_addon_products(); - $found = false; + $found = false; foreach ($addon_products as $item) { if ($item['product']->get_id() === $product_id) { $this->assertEquals(2, $item['quantity']); @@ -624,15 +624,15 @@ public function test_add_product(): void { public function test_remove_product(): void { $addon = new Product( [ - 'name' => 'Removable Addon', - 'slug' => 'removable-addon-' . wp_generate_password(6, false), - 'pricing_type' => 'paid', - 'amount' => 4.99, - 'currency' => 'USD', - 'duration' => 1, + 'name' => 'Removable Addon', + 'slug' => 'removable-addon-' . wp_generate_password(6, false), + 'pricing_type' => 'paid', + 'amount' => 4.99, + 'currency' => 'USD', + 'duration' => 1, 'duration_unit' => 'month', - 'type' => 'package', - 'active' => true, + 'type' => 'package', + 'active' => true, ] ); $addon->set_skip_validation(true); @@ -661,15 +661,15 @@ public function test_remove_product(): void { public function test_get_all_products(): void { $addon = new Product( [ - 'name' => 'All Products Addon', - 'slug' => 'all-prod-addon-' . wp_generate_password(6, false), - 'pricing_type' => 'paid', - 'amount' => 9.99, - 'currency' => 'USD', - 'duration' => 1, + 'name' => 'All Products Addon', + 'slug' => 'all-prod-addon-' . wp_generate_password(6, false), + 'pricing_type' => 'paid', + 'amount' => 9.99, + 'currency' => 'USD', + 'duration' => 1, 'duration_unit' => 'month', - 'type' => 'package', - 'active' => true, + 'type' => 'package', + 'active' => true, ] ); $addon->set_skip_validation(true); @@ -745,15 +745,15 @@ public function test_has_plan_false_for_invalid_id(): void { public function test_set_addon_products(): void { $addon = new Product( [ - 'name' => 'Set Addon Prod', - 'slug' => 'set-addon-prod-' . wp_generate_password(6, false), - 'pricing_type' => 'paid', - 'amount' => 5.00, - 'currency' => 'USD', - 'duration' => 1, + 'name' => 'Set Addon Prod', + 'slug' => 'set-addon-prod-' . wp_generate_password(6, false), + 'pricing_type' => 'paid', + 'amount' => 5.00, + 'currency' => 'USD', + 'duration' => 1, 'duration_unit' => 'month', - 'type' => 'package', - 'active' => true, + 'type' => 'package', + 'active' => true, ] ); $addon->set_skip_validation(true); @@ -1107,7 +1107,7 @@ public function test_schedule_swap_invalid_order(): void { * Test schedule_swap with invalid date returns WP_Error. */ public function test_schedule_swap_invalid_date(): void { - $cart = new \WP_Ultimo\Checkout\Cart([]); + $cart = new \WP_Ultimo\Checkout\Cart([]); $result = $this->membership->schedule_swap($cart, 'bogus-date'); $this->assertInstanceOf(\WP_Error::class, $result); } @@ -1453,7 +1453,7 @@ public function test_reactivate_fires_pre_reactivate_hook(): void { add_action( 'wu_membership_pre_reactivate', - function($id) use (&$pre_fired, &$captured_id) { + function ($id) use (&$pre_fired, &$captured_id) { $pre_fired = true; $captured_id = $id; } @@ -1479,7 +1479,7 @@ public function test_reactivate_fires_post_reactivate_hook_on_success(): void { add_action( 'wu_membership_post_reactivate', - function($id) use (&$post_fired, &$captured_id) { + function ($id) use (&$post_fired, &$captured_id) { $post_fired = true; $captured_id = $id; } @@ -1510,7 +1510,7 @@ public function test_reactivate_does_not_fire_post_hook_on_failure(): void { add_action( 'wu_membership_post_reactivate', - function() use (&$post_fired) { + function () use (&$post_fired) { $post_fired = true; } ); diff --git a/tests/WP_Ultimo/Models/Payment_Test.php b/tests/WP_Ultimo/Models/Payment_Test.php index a68abf643..403b25bec 100644 --- a/tests/WP_Ultimo/Models/Payment_Test.php +++ b/tests/WP_Ultimo/Models/Payment_Test.php @@ -388,13 +388,13 @@ public function test_cancel_pending_payment(): void { wp_set_current_user($customer->get_user_id(), $customer->get_username()); $product = wu_create_product([ - 'name' => 'Test Plan', - 'slug' => 'test-plan', + 'name' => 'Test Plan', + 'slug' => 'test-plan', 'pricing_type' => 'paid', - 'amount' => 10, - 'currency' => 'USD', - 'recurring' => false, - 'type' => 'plan', + 'amount' => 10, + 'currency' => 'USD', + 'recurring' => false, + 'type' => 'plan', ]); if (is_wp_error($product)) { @@ -403,8 +403,8 @@ public function test_cancel_pending_payment(): void { $membership = wu_create_membership([ 'customer_id' => $customer->get_id(), - 'plan_id' => $product->get_id(), - 'status' => Membership_Status::ACTIVE, + 'plan_id' => $product->get_id(), + 'status' => Membership_Status::ACTIVE, ]); if (is_wp_error($membership)) { @@ -412,13 +412,13 @@ public function test_cancel_pending_payment(): void { } $payment = wu_create_payment([ - 'customer_id' => $customer->get_id(), + 'customer_id' => $customer->get_id(), 'membership_id' => $membership->get_id(), - 'currency' => 'USD', - 'subtotal' => 100.00, - 'total' => 100.00, - 'status' => Payment_Status::PENDING, - 'gateway' => 'manual', + 'currency' => 'USD', + 'subtotal' => 100.00, + 'total' => 100.00, + 'status' => Payment_Status::PENDING, + 'gateway' => 'manual', ]); $this->assertInstanceOf(Payment::class, $payment, 'Payment creation failed'); @@ -1075,7 +1075,7 @@ public function test_refund_full_amount(): void { $this->assertEquals(Payment_Status::REFUND, $payment->get_status()); // Verify refund line item was added - $items = $payment->get_line_items(); + $items = $payment->get_line_items(); $refund_items = array_filter($items, fn($item) => $item->get_type() === 'refund'); $this->assertNotEmpty($refund_items); @@ -1117,7 +1117,7 @@ public function test_refund_partial_amount(): void { $this->assertEquals(Payment_Status::PARTIAL_REFUND, $payment->get_status()); // Verify the refund line item - $items = $payment->get_line_items(); + $items = $payment->get_line_items(); $refund_items = array_filter($items, fn($item) => $item->get_type() === 'refund'); $this->assertNotEmpty($refund_items); diff --git a/tests/WP_Ultimo/Models/Post_Base_Model_Test.php b/tests/WP_Ultimo/Models/Post_Base_Model_Test.php index 4264c6b97..b5602b467 100644 --- a/tests/WP_Ultimo/Models/Post_Base_Model_Test.php +++ b/tests/WP_Ultimo/Models/Post_Base_Model_Test.php @@ -160,5 +160,4 @@ public function tearDown(): void { parent::tearDown(); } - } diff --git a/tests/WP_Ultimo/Models/Webhook_Test.php b/tests/WP_Ultimo/Models/Webhook_Test.php index 672d23f91..5e0cb8b99 100644 --- a/tests/WP_Ultimo/Models/Webhook_Test.php +++ b/tests/WP_Ultimo/Models/Webhook_Test.php @@ -102,7 +102,6 @@ public function test_webhook_status_and_counting(): void { // Test event counting $this->webhook->set_event_count(5); $this->assertEquals(5, $this->webhook->get_event_count(), 'Event count should be set and retrieved correctly.'); - } /** @@ -213,7 +212,6 @@ public function test_hash_generation(): void { $this->assertIsString($hash, 'Hash should be a string.'); $this->assertNotEmpty($hash, 'Hash should not be empty.'); - } /** @@ -226,7 +224,6 @@ public function test_meta_data_handling(): void { // Test meta update $result = $this->webhook->update_meta($meta_key, $meta_value); $this->assertFalse($result || is_numeric($result), 'Web hooks don\'t do meta '); - } /** @@ -245,5 +242,4 @@ public function tearDown(): void { parent::tearDown(); } - } diff --git a/tests/WP_Ultimo/MpdfPsrHttpMessageShim_Test.php b/tests/WP_Ultimo/MpdfPsrHttpMessageShim_Test.php index a46ce3171..694070a89 100644 --- a/tests/WP_Ultimo/MpdfPsrHttpMessageShim_Test.php +++ b/tests/WP_Ultimo/MpdfPsrHttpMessageShim_Test.php @@ -223,42 +223,42 @@ public function test_uri_get_fragment_has_string_return_type() { // ------------------------------------------------------------------ public function test_request_get_method_returns_string() { - $uri = new \Mpdf\PsrHttpMessageShim\Uri('http://example.com/'); + $uri = new \Mpdf\PsrHttpMessageShim\Uri('http://example.com/'); $request = new \Mpdf\PsrHttpMessageShim\Request('GET', $uri); - $result = $request->getMethod(); + $result = $request->getMethod(); $this->assertIsString($result); $this->assertSame('GET', $result); } public function test_request_get_request_target_returns_string() { - $uri = new \Mpdf\PsrHttpMessageShim\Uri('http://example.com/path'); + $uri = new \Mpdf\PsrHttpMessageShim\Uri('http://example.com/path'); $request = new \Mpdf\PsrHttpMessageShim\Request('GET', $uri); $this->assertIsString($request->getRequestTarget()); } public function test_response_get_status_code_returns_int() { $response = new \Mpdf\PsrHttpMessageShim\Response(201); - $code = $response->getStatusCode(); + $code = $response->getStatusCode(); $this->assertIsInt($code); $this->assertSame(201, $code); } public function test_stream_get_size_returns_int_or_null() { $stream = \Mpdf\PsrHttpMessageShim\Stream::create('hello world'); - $size = $stream->getSize(); + $size = $stream->getSize(); // getSize() returns ?int — both int and null are valid. $this->assertTrue(null === $size || is_int($size), 'Stream::getSize() must return int or null'); } public function test_uri_get_port_returns_int_or_null() { // http uses default port 80 — getPort() should return null for default ports. - $uri = new \Mpdf\PsrHttpMessageShim\Uri('http://example.com/'); + $uri = new \Mpdf\PsrHttpMessageShim\Uri('http://example.com/'); $port = $uri->getPort(); $this->assertTrue(null === $port || is_int($port), 'Uri::getPort() must return int or null'); } public function test_uri_get_port_returns_int_for_non_standard_port() { - $uri = new \Mpdf\PsrHttpMessageShim\Uri('http://example.com:8080/'); + $uri = new \Mpdf\PsrHttpMessageShim\Uri('http://example.com:8080/'); $port = $uri->getPort(); $this->assertIsInt($port); $this->assertSame(8080, $port); @@ -276,10 +276,10 @@ public function test_uri_get_port_returns_int_for_non_standard_port() { * @param string $expected_type Expected type name (primitive or FQCN). */ private function assert_method_return_type(string $class_name, string $method_name, string $expected_type): void { - $ref = new \ReflectionClass($class_name); - $method = $ref->getMethod($method_name); + $ref = new \ReflectionClass($class_name); + $method = $ref->getMethod($method_name); $return_type = $method->getReturnType(); - $short_name = $ref->getShortName(); + $short_name = $ref->getShortName(); $this->assertNotNull( $return_type, @@ -299,10 +299,10 @@ private function assert_method_return_type(string $class_name, string $method_na * @param string $method_name Method to inspect. */ private function assert_method_nullable_int_return_type(string $class_name, string $method_name): void { - $ref = new \ReflectionClass($class_name); - $method = $ref->getMethod($method_name); + $ref = new \ReflectionClass($class_name); + $method = $ref->getMethod($method_name); $return_type = $method->getReturnType(); - $short_name = $ref->getShortName(); + $short_name = $ref->getShortName(); $this->assertNotNull( $return_type, diff --git a/tests/WP_Ultimo/Newsletter_Test.php b/tests/WP_Ultimo/Newsletter_Test.php index bb31d14f0..fa6d5e79c 100644 --- a/tests/WP_Ultimo/Newsletter_Test.php +++ b/tests/WP_Ultimo/Newsletter_Test.php @@ -39,7 +39,11 @@ public function test_maybe_update_newsletter_subscription_no_change(): void { $newsletter = \WP_Ultimo\Newsletter::get_instance(); - $settings = ['company_email' => 'test@example.com', 'company_name' => 'Test', 'company_country' => 'US']; + $settings = [ + 'company_email' => 'test@example.com', + 'company_name' => 'Test', + 'company_country' => 'US', + ]; $settings_to_save = []; $saved_settings = []; @@ -55,7 +59,11 @@ public function test_maybe_update_newsletter_subscription_same_value(): void { $newsletter = \WP_Ultimo\Newsletter::get_instance(); - $settings = ['company_email' => 'test@example.com', 'company_name' => 'Test', 'company_country' => 'US']; + $settings = [ + 'company_email' => 'test@example.com', + 'company_name' => 'Test', + 'company_country' => 'US', + ]; $settings_to_save = ['newsletter_optin' => '1']; $saved_settings = ['newsletter_optin' => '1']; diff --git a/tests/WP_Ultimo/Site_Exporter/Network_Exporter_Test.php b/tests/WP_Ultimo/Site_Exporter/Network_Exporter_Test.php index e437fe1dc..669079a9a 100644 --- a/tests/WP_Ultimo/Site_Exporter/Network_Exporter_Test.php +++ b/tests/WP_Ultimo/Site_Exporter/Network_Exporter_Test.php @@ -186,5 +186,3 @@ private function delete_directory($dir): void { rmdir($dir); } } - - diff --git a/tests/WP_Ultimo/Site_Exporter_Import_Move_Test.php b/tests/WP_Ultimo/Site_Exporter_Import_Move_Test.php index 736cbc9b0..0a77e6785 100644 --- a/tests/WP_Ultimo/Site_Exporter_Import_Move_Test.php +++ b/tests/WP_Ultimo/Site_Exporter_Import_Move_Test.php @@ -201,9 +201,9 @@ public function test_move_themes_relocates_theme_directories(): void { public function test_runcommand_theme_enable_invokes_switch_theme(): void { // Find an installed theme other than the current one to switch to. - $themes = wp_get_themes(); - $current = get_stylesheet(); - $candidate = ''; + $themes = wp_get_themes(); + $current = get_stylesheet(); + $candidate = ''; foreach ($themes as $slug => $theme) { if ($slug !== $current && $theme->exists()) { diff --git a/tests/WP_Ultimo/Site_Exporter_Zip_Contents_Test.php b/tests/WP_Ultimo/Site_Exporter_Zip_Contents_Test.php index 07a4717ff..0a2747ccc 100644 --- a/tests/WP_Ultimo/Site_Exporter_Zip_Contents_Test.php +++ b/tests/WP_Ultimo/Site_Exporter_Zip_Contents_Test.php @@ -272,7 +272,7 @@ private function list_zip_entries(string $zip_path): array { */ private function run_export(array $assoc_args): string { - $zip_path = $this->tmp_dir . '/export-' . uniqid() . '.zip'; + $zip_path = $this->tmp_dir . '/export-' . uniqid() . '.zip'; $assoc_args['blog_id'] = $assoc_args['blog_id'] ?? 1; $command = new ExportCommand(); @@ -297,13 +297,13 @@ public function test_database_only_export_contains_required_files(): void { $has_json = false; foreach ($entries as $entry) { - $has_csv = $has_csv || (substr($entry, -4) === '.csv'); - $has_sql = $has_sql || (substr($entry, -4) === '.sql'); + $has_csv = $has_csv || (substr($entry, -4) === '.csv'); + $has_sql = $has_sql || (substr($entry, -4) === '.sql'); $has_json = $has_json || (substr($entry, -5) === '.json'); } - $this->assertTrue($has_csv, 'Export must include the users CSV'); - $this->assertTrue($has_sql, 'Export must include the SQL dump'); + $this->assertTrue($has_csv, 'Export must include the users CSV'); + $this->assertTrue($has_sql, 'Export must include the SQL dump'); $this->assertTrue($has_json, 'Export must include the meta JSON'); } @@ -444,21 +444,21 @@ public function test_export_with_all_options_includes_everything(): void { $entries = $this->list_zip_entries($zip_path); - $has_plugin = false; - $has_theme = false; - $has_upload = false; - $has_sql = false; + $has_plugin = false; + $has_theme = false; + $has_upload = false; + $has_sql = false; foreach ($entries as $entry) { $has_plugin = $has_plugin || (0 === strpos($entry, 'wp-content/plugins/')); - $has_theme = $has_theme || (0 === strpos($entry, 'wp-content/themes/')); + $has_theme = $has_theme || (0 === strpos($entry, 'wp-content/themes/')); $has_upload = $has_upload || (0 === strpos($entry, 'wp-content/uploads/')); - $has_sql = $has_sql || (substr($entry, -4) === '.sql'); + $has_sql = $has_sql || (substr($entry, -4) === '.sql'); } $this->assertTrue($has_plugin, 'Combined export must contain plugins'); - $this->assertTrue($has_theme, 'Combined export must contain themes'); + $this->assertTrue($has_theme, 'Combined export must contain themes'); $this->assertTrue($has_upload, 'Combined export must contain uploads'); - $this->assertTrue($has_sql, 'Combined export must contain the SQL dump'); + $this->assertTrue($has_sql, 'Combined export must contain the SQL dump'); } } diff --git a/tests/WP_Ultimo/Tax/Tax_Test.php b/tests/WP_Ultimo/Tax/Tax_Test.php index cede42c9b..2ee44db03 100644 --- a/tests/WP_Ultimo/Tax/Tax_Test.php +++ b/tests/WP_Ultimo/Tax/Tax_Test.php @@ -309,7 +309,7 @@ public function test_get_tax_rates_merges_defaults(): void { wu_save_option('tax_rates', $tax_rates); - $rates = $this->tax->get_tax_rates(); + $rates = $this->tax->get_tax_rates(); $first_rate = $rates['default']['rates'][0]; // These should come from defaults. @@ -344,7 +344,7 @@ public function test_get_tax_rates_handles_non_numeric_tax_rate(): void { wu_save_option('tax_rates', $tax_rates); - $rates = $this->tax->get_tax_rates(); + $rates = $this->tax->get_tax_rates(); $first_rate = $rates['default']['rates'][0]; $this->assertEquals(0, $first_rate['tax_rate']); @@ -372,7 +372,7 @@ public function test_get_tax_rates_keeps_numeric_tax_rate(): void { wu_save_option('tax_rates', $tax_rates); - $rates = $this->tax->get_tax_rates(); + $rates = $this->tax->get_tax_rates(); $first_rate = $rates['default']['rates'][0]; $this->assertEquals(15.5, $first_rate['tax_rate']); @@ -396,7 +396,7 @@ public function test_get_tax_rates_with_multiple_categories(): void { ], ], ], - 'eu' => [ + 'eu' => [ 'name' => 'EU', 'rates' => [ [ @@ -427,7 +427,7 @@ public function test_get_tax_rates_ensures_default_first(): void { // Store rates without a 'default' key explicitly - use a different key name. $tax_rates = [ - 'first_category' => [ + 'first_category' => [ 'name' => 'First Category', 'rates' => [ [ @@ -601,7 +601,7 @@ public function test_get_tax_rates_with_zero_tax_rate(): void { wu_save_option('tax_rates', $tax_rates); - $rates = $this->tax->get_tax_rates(); + $rates = $this->tax->get_tax_rates(); $first_rate = $rates['default']['rates'][0]; $this->assertEquals(0, $first_rate['tax_rate']); @@ -629,7 +629,7 @@ public function test_get_tax_rates_with_string_numeric_tax_rate(): void { wu_save_option('tax_rates', $tax_rates); - $rates = $this->tax->get_tax_rates(); + $rates = $this->tax->get_tax_rates(); $first_rate = $rates['default']['rates'][0]; // String '10' is numeric, so it should be kept. @@ -658,7 +658,7 @@ public function test_get_tax_rates_with_empty_string_tax_rate(): void { wu_save_option('tax_rates', $tax_rates); - $rates = $this->tax->get_tax_rates(); + $rates = $this->tax->get_tax_rates(); $first_rate = $rates['default']['rates'][0]; // Empty string is not numeric, so should be converted to 0. @@ -740,7 +740,7 @@ public function test_get_tax_rates_defaults_fill_missing_keys(): void { wu_save_option('tax_rates', $tax_rates); - $rates = $this->tax->get_tax_rates(); + $rates = $this->tax->get_tax_rates(); $first_rate = $rates['default']['rates'][0]; // Keys from defaults that were not set. @@ -801,7 +801,7 @@ public function test_get_tax_rates_with_negative_tax_rate(): void { wu_save_option('tax_rates', $tax_rates); - $rates = $this->tax->get_tax_rates(); + $rates = $this->tax->get_tax_rates(); $first_rate = $rates['default']['rates'][0]; // Negative numbers are numeric, so they should be kept. @@ -861,7 +861,7 @@ public function test_get_tax_rates_with_null_tax_rate(): void { wu_save_option('tax_rates', $tax_rates); - $rates = $this->tax->get_tax_rates(); + $rates = $this->tax->get_tax_rates(); $first_rate = $rates['default']['rates'][0]; // null is not numeric, should be set to 0. diff --git a/tests/WP_Ultimo/WP_Ultimo_Main_Test.php b/tests/WP_Ultimo/WP_Ultimo_Main_Test.php index ef664edc3..363ded94a 100644 --- a/tests/WP_Ultimo/WP_Ultimo_Main_Test.php +++ b/tests/WP_Ultimo/WP_Ultimo_Main_Test.php @@ -256,5 +256,4 @@ public function test_get_addon_repository_returns_same_instance(): void { $this->assertSame($repo1, $repo2); } - } diff --git a/tests/WP_Ultimo/Whitelabel_Test.php b/tests/WP_Ultimo/Whitelabel_Test.php index ed962e34e..1434550a2 100644 --- a/tests/WP_Ultimo/Whitelabel_Test.php +++ b/tests/WP_Ultimo/Whitelabel_Test.php @@ -284,6 +284,7 @@ public function test_replace_text_replaces_wordpress(): void { } /** + * phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledInComment -- Intentional lowercase fixture spelling. * Test replace_text replaces lowercase wordpress variant. */ public function test_replace_text_replaces_lowercase_wordpress(): void { @@ -294,6 +295,7 @@ public function test_replace_text_replaces_lowercase_wordpress(): void { $this->whitelabel->hooks(); + // phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledInText -- Intentional lowercase fixture spelling. $result = $this->whitelabel->replace_text('powered by wordpress', 'powered by wordpress', 'default'); $this->assertEquals('powered by myplatform', $result); @@ -316,6 +318,7 @@ public function test_replace_text_replaces_capitalized_wordpress(): void { } /** + * phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledInComment -- Intentional misspelling fixture. * Test replace_text replaces "Wordpress" variant (common misspelling). */ public function test_replace_text_replaces_wordpress_misspelling(): void { @@ -326,12 +329,14 @@ public function test_replace_text_replaces_wordpress_misspelling(): void { $this->whitelabel->hooks(); + // phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledInText -- Intentional misspelling fixture. $result = $this->whitelabel->replace_text('Wordpress dashboard', 'Wordpress dashboard', 'default'); $this->assertEquals('MyPlatform dashboard', $result); } /** + * phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledInComment -- Intentional camelcase fixture spelling. * Test replace_text replaces "wordPress" variant. */ public function test_replace_text_replaces_wordpress_camelcase(): void { @@ -342,6 +347,7 @@ public function test_replace_text_replaces_wordpress_camelcase(): void { $this->whitelabel->hooks(); + // phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledInText -- Intentional camelcase fixture spelling. $result = $this->whitelabel->replace_text('wordPress setup', 'wordPress setup', 'default'); $this->assertEquals('MyPlatform setup', $result); diff --git a/tests/WP_Ultimo_Test.php b/tests/WP_Ultimo_Test.php index c85d2b867..aef86ab6b 100644 --- a/tests/WP_Ultimo_Test.php +++ b/tests/WP_Ultimo_Test.php @@ -267,7 +267,10 @@ public function test_register_addon_headers_adds_two_headers(): void { */ public function test_grant_customer_capabilities_no_op_when_cap_not_checked(): void { - $allcaps = ['read' => true, 'edit_posts' => true]; + $allcaps = [ + 'read' => true, + 'edit_posts' => true, + ]; $caps = ['edit_posts']; $args = []; $user = new \WP_User(self::factory()->user->create()); @@ -325,7 +328,7 @@ public function test_grant_customer_capabilities_grants_for_admin_customer(): vo 'user_email' => 'admin-customer-test@example.com', 'user_login' => 'admin_customer_test_' . wp_rand(1000, 9999), ]); - $user = new \WP_User($user_id); + $user = new \WP_User($user_id); // Create a customer record for this user. $customer = wu_create_customer([ diff --git a/tests/e2e/cypress/fixtures/process-stripe-renewal.php b/tests/e2e/cypress/fixtures/process-stripe-renewal.php index cfa8b3fe0..8671f9cc4 100644 --- a/tests/e2e/cypress/fixtures/process-stripe-renewal.php +++ b/tests/e2e/cypress/fixtures/process-stripe-renewal.php @@ -40,9 +40,9 @@ if (! $renewal_invoice) { echo wp_json_encode([ - 'error' => 'No renewal invoice found.', - 'invoice_count' => count($invoices->data), - 'billing_reasons' => array_map(function($inv) { + 'error' => 'No renewal invoice found.', + 'invoice_count' => count($invoices->data), + 'billing_reasons' => array_map(function ($inv) { return $inv->billing_reason; }, $invoices->data), ]); @@ -126,15 +126,15 @@ $membership->renew($membership->is_recurring(), 'active', $expiration); echo wp_json_encode([ - 'success' => true, - 'renewal_invoice_id' => $renewal_invoice->id, - 'charge_id' => $charge_id, - 'renewal_payment_id' => $payment->get_id(), - 'renewal_total' => $total, - 'new_expiration' => $expiration, - 'new_times_billed' => $membership->get_times_billed(), - 'membership_status' => $membership->get_status(), - 'current_period_end' => $end_timestamp, + 'success' => true, + 'renewal_invoice_id' => $renewal_invoice->id, + 'charge_id' => $charge_id, + 'renewal_payment_id' => $payment->get_id(), + 'renewal_total' => $total, + 'new_expiration' => $expiration, + 'new_times_billed' => $membership->get_times_billed(), + 'membership_status' => $membership->get_status(), + 'current_period_end' => $end_timestamp, ]); } catch (\Exception $e) { echo wp_json_encode([ diff --git a/tests/e2e/cypress/fixtures/set-password-strength.php b/tests/e2e/cypress/fixtures/set-password-strength.php index 232a0480b..368cac8db 100644 --- a/tests/e2e/cypress/fixtures/set-password-strength.php +++ b/tests/e2e/cypress/fixtures/set-password-strength.php @@ -27,6 +27,6 @@ wu_save_setting('minimum_password_strength', $strength); echo wp_json_encode([ - 'success' => true, - 'setting' => wu_get_setting('minimum_password_strength'), + 'success' => true, + 'setting' => wu_get_setting('minimum_password_strength'), ]); diff --git a/tests/e2e/cypress/fixtures/setup-gateway.php b/tests/e2e/cypress/fixtures/setup-gateway.php index be02b22a6..5118282eb 100644 --- a/tests/e2e/cypress/fixtures/setup-gateway.php +++ b/tests/e2e/cypress/fixtures/setup-gateway.php @@ -5,7 +5,7 @@ * Using a fixture file instead of inline wp eval to avoid shell-quoting * issues through the npx -> wp-env -> docker exec -> wp eval chain. */ -wu_save_setting( 'active_gateways', array( 'manual' ) ); +wu_save_setting( 'active_gateways', array('manual') ); $active = wu_get_setting( 'active_gateways', array() ); diff --git a/tests/e2e/cypress/fixtures/setup-sso-bootstrap-race.php b/tests/e2e/cypress/fixtures/setup-sso-bootstrap-race.php index 412d1a313..76da53224 100644 --- a/tests/e2e/cypress/fixtures/setup-sso-bootstrap-race.php +++ b/tests/e2e/cypress/fixtures/setup-sso-bootstrap-race.php @@ -55,7 +55,7 @@ // It must return a deterministic hash (same call -> same hash). // ----------------------------------------------------------------------- try { - $main = function_exists('get_main_site_id') ? get_site(get_main_site_id()) : get_site(1); + $main = function_exists('get_main_site_id') ? get_site(get_main_site_id()) : get_site(1); $result['main_secret'] = $sso->calculate_secret_from_date($main->registered); } catch (\Throwable $e) { $result['main_secret'] = 'THREW:' . $e->getMessage(); @@ -64,7 +64,7 @@ try { $result['empty_secret_1'] = $sso->calculate_secret_from_date(''); } catch (\Throwable $e) { - $result['secret_threw'] = true; + $result['secret_threw'] = true; $result['empty_secret_1'] = 'THREW:' . $e->getMessage(); } diff --git a/tests/e2e/cypress/fixtures/setup-sso-test.php b/tests/e2e/cypress/fixtures/setup-sso-test.php index a59bab6e6..e77e56265 100644 --- a/tests/e2e/cypress/fixtures/setup-sso-test.php +++ b/tests/e2e/cypress/fixtures/setup-sso-test.php @@ -54,8 +54,8 @@ } // 2. Insert domain mapping for sso-test.ultimate-multisite.test:PORT directly -// into the DB. The Domain model's validation rejects domains with ports, so -// we bypass it. +// into the DB. The Domain model's validation rejects domains with ports, so +// we bypass it. $table = $wpdb->base_prefix . 'wu_domain_mappings'; $now = current_time('mysql'); @@ -75,7 +75,11 @@ // Update existing record to ensure domain includes port. $wpdb->update( $table, - ['domain' => $mapped_domain, 'active' => 1, 'stage' => 'done'], + [ + 'domain' => $mapped_domain, + 'active' => 1, + 'stage' => 'done', + ], ['id' => $existing_domain], ['%s', '%d', '%s'], ['%d'] @@ -120,9 +124,9 @@ wp_cache_delete('domain:127.0.0.1', 'domain_mappings'); // 3. Enable domain mapping, enable SSO, and disable the loading overlay -// (avoids flicker in tests). Domain mapping must be enabled before the -// next mapped-host request so sunrise registers the mapped site instead of -// falling back to WordPress' main-site redirect. +// (avoids flicker in tests). Domain mapping must be enabled before the +// next mapped-host request so sunrise registers the mapped site instead of +// falling back to WordPress' main-site redirect. wu_save_setting('enable_domain_mapping', true); wu_save_setting('enable_sso', true); wu_save_setting('enable_sso_loading_overlay', false); diff --git a/tests/e2e/cypress/fixtures/setup-stripe-gateway.php b/tests/e2e/cypress/fixtures/setup-stripe-gateway.php index 2fdc4e9d3..0abcfff46 100644 --- a/tests/e2e/cypress/fixtures/setup-stripe-gateway.php +++ b/tests/e2e/cypress/fixtures/setup-stripe-gateway.php @@ -25,7 +25,7 @@ // Add stripe to active gateways while keeping existing ones $active_gateways = (array) wu_get_setting('active_gateways', []); -if (!in_array('stripe', $active_gateways, true)) { +if (! in_array('stripe', $active_gateways, true)) { $active_gateways[] = 'stripe'; } @@ -36,7 +36,7 @@ 'success' => true, 'active_gateways' => wu_get_setting('active_gateways', []), 'sandbox_mode' => wu_get_setting('stripe_sandbox_mode', false), - 'pk_key_set' => !empty(wu_get_setting('stripe_test_pk_key')), - 'sk_key_set' => !empty(wu_get_setting('stripe_test_sk_key')), + 'pk_key_set' => ! empty(wu_get_setting('stripe_test_pk_key')), + 'sk_key_set' => ! empty(wu_get_setting('stripe_test_sk_key')), ] ); diff --git a/tests/e2e/cypress/fixtures/setup-stripe-renewal-test.php b/tests/e2e/cypress/fixtures/setup-stripe-renewal-test.php index dabcdbabd..4869e752e 100644 --- a/tests/e2e/cypress/fixtures/setup-stripe-renewal-test.php +++ b/tests/e2e/cypress/fixtures/setup-stripe-renewal-test.php @@ -146,10 +146,10 @@ $initial_invoice = $subscription->latest_invoice; if (is_string($initial_invoice)) { - $invoice_obj = $stripe->invoices->retrieve($initial_invoice); - $gateway_pay_id = $invoice_obj->charge ?? $invoice_obj->payment_intent ?? $initial_invoice; + $invoice_obj = $stripe->invoices->retrieve($initial_invoice); + $gateway_pay_id = $invoice_obj->charge ?? $invoice_obj->payment_intent ?? $initial_invoice; } else { - $gateway_pay_id = $initial_invoice->charge ?? $initial_invoice->payment_intent ?? ''; + $gateway_pay_id = $initial_invoice->charge ?? $initial_invoice->payment_intent ?? ''; } $payment = wu_create_payment([ @@ -184,7 +184,7 @@ ]); } catch (\Exception $e) { echo wp_json_encode([ - 'error' => $e->getMessage(), - 'code' => $e->getCode(), + 'error' => $e->getMessage(), + 'code' => $e->getCode(), ]); } diff --git a/tests/e2e/cypress/fixtures/verify-stripe-checkout-results.php b/tests/e2e/cypress/fixtures/verify-stripe-checkout-results.php index cd9c25e24..abe085515 100644 --- a/tests/e2e/cypress/fixtures/verify-stripe-checkout-results.php +++ b/tests/e2e/cypress/fixtures/verify-stripe-checkout-results.php @@ -18,21 +18,21 @@ $gateway_payment_id = $payments ? $payments[0]->get_gateway_payment_id() : ''; // UM membership (most recent) -$memberships = WP_Ultimo\Models\Membership::query( +$memberships = WP_Ultimo\Models\Membership::query( [ 'number' => 1, 'orderby' => 'id', 'order' => 'DESC', ] ); -$um_membership_status = $memberships ? $memberships[0]->get_status() : 'no-memberships'; -$gateway_customer_id = $memberships ? $memberships[0]->get_gateway_customer_id() : ''; -$gateway_subscription_id = $memberships ? $memberships[0]->get_gateway_subscription_id() : ''; +$um_membership_status = $memberships ? $memberships[0]->get_status() : 'no-memberships'; +$gateway_customer_id = $memberships ? $memberships[0]->get_gateway_customer_id() : ''; +$gateway_subscription_id = $memberships ? $memberships[0]->get_gateway_subscription_id() : ''; // UM sites -$sites = WP_Ultimo\Models\Site::query(['type__in' => ['customer_owned']]); +$sites = WP_Ultimo\Models\Site::query(['type__in' => ['customer_owned']]); $um_site_count = count($sites); -$um_site_type = $sites ? $sites[0]->get_type() : 'no-sites'; +$um_site_type = $sites ? $sites[0]->get_type() : 'no-sites'; echo wp_json_encode( [ diff --git a/tests/performance-benchmark.php b/tests/performance-benchmark.php index c69e370bc..bf8585b5b 100755 --- a/tests/performance-benchmark.php +++ b/tests/performance-benchmark.php @@ -2,212 +2,211 @@ /** * Performance Benchmark Test Suite for Ultimate Multisite - * + * * This script measures performance of critical plugin operations * and outputs results in JSON format for CI/CD processing. */ // Ensure we're running in CLI mode if (php_sapi_name() !== 'cli') { - die("This script must be run from the command line.\n"); + die("This script must be run from the command line.\n"); } // Load WordPress test environment require_once dirname(__DIR__) . '/tests/bootstrap.php'; class Performance_Benchmark { - - private $results = []; - private $start_time; - private $start_memory; - - public function __construct() { - $this->results['test_run'] = date('Y-m-d H:i:s'); - $this->results['php_version'] = PHP_VERSION; - $this->results['wordpress_version'] = get_bloginfo('version'); - $this->results['plugin_version'] = $this->get_plugin_version(); - } - - private function get_plugin_version() { - $plugin_data = get_plugin_data(ULTIMATE_MULTISITE_PLUGIN); - return $plugin_data['Version'] ?? 'unknown'; - } - - private function start_measurement() { - $this->start_time = microtime(true); - $this->start_memory = memory_get_usage(true); - - // Reset WordPress query count - global $wpdb; - $wpdb->num_queries = 0; - } - - private function end_measurement($operation_name) { - $end_time = microtime(true); - $end_memory = memory_get_usage(true); - - global $wpdb; - - $this->results[$operation_name] = [ - 'execution_time_ms' => round(($end_time - $this->start_time) * 1000, 2), - 'memory_usage_mb' => round(($end_memory - $this->start_memory) / 1024 / 1024, 2), - 'peak_memory_mb' => round(memory_get_peak_usage(true) / 1024 / 1024, 2), - 'database_queries' => $wpdb->num_queries, - ]; - } - - public function benchmark_dashboard_loading() { - $this->start_measurement(); - - // Simulate dashboard loading - $dashboard = new \WP_Ultimo\Admin_Pages\Dashboard_Admin_Page(); - $dashboard->register(); - - // Test dashboard data loading - $stats = wu_get_dashboard_statistics(); - - $this->end_measurement('dashboard_loading'); - } - - public function benchmark_checkout_process() { - $this->start_measurement(); - - // Simulate checkout initialization - $checkout = \WP_Ultimo\Checkout\Checkout::get_instance(); - - // Test pricing plans loading - $plans = wu_get_plans(['number' => 10]); - - // Test form rendering preparation - $fields = wu_get_signup_fields(); - - $this->end_measurement('checkout_process'); - } - - public function benchmark_site_creation() { - $this->start_measurement(); - - // Test site creation data preparation - $site_data = [ - 'domain' => 'test-' . time() . '.example.com', - 'title' => 'Test Site ' . time(), - 'user_id' => 1, - 'plan_id' => 1, - ]; - - // Validate site data (without actually creating) - $validator = new \WP_Ultimo\Validators\Site_Validator(); - $is_valid = $validator->validate($site_data); - - $this->end_measurement('site_creation_validation'); - } - - public function benchmark_membership_operations() { - $this->start_measurement(); - - // Test membership queries - $memberships = wu_get_memberships(['number' => 10]); - - // Test membership status calculations - foreach ($memberships as $membership) { - $membership->get_status(); - $membership->is_active(); - } - - $this->end_measurement('membership_operations'); - } - - public function benchmark_api_endpoints() { - $this->start_measurement(); - - // Test API endpoint registration - $api = new \WP_Ultimo\API(); - $api->register(); - - // Test API data preparation - $sites = wu_get_sites(['number' => 5]); - $api_data = []; - - foreach ($sites as $site) { - $api_data[] = [ - 'id' => $site->get_id(), - 'domain' => $site->get_domain(), - 'title' => $site->get_title(), - ]; - } - - $this->end_measurement('api_endpoints'); - } - - public function benchmark_database_queries() { - global $wpdb; - - $this->start_measurement(); - - // Test common database operations - $tables = [ - 'wu_memberships', - 'wu_sites', - 'wu_plans', - 'wu_customers' - ]; - - foreach ($tables as $table) { - $wpdb->get_var("SELECT COUNT(*) FROM $table LIMIT 1"); - } - - $this->end_measurement('database_queries'); - } - - public function run_all_benchmarks() { - echo "Starting performance benchmarks...\n"; - - try { - $this->benchmark_dashboard_loading(); - echo "✓ Dashboard loading benchmark completed\n"; - - $this->benchmark_checkout_process(); - echo "✓ Checkout process benchmark completed\n"; - - $this->benchmark_site_creation(); - echo "✓ Site creation validation benchmark completed\n"; - - $this->benchmark_membership_operations(); - echo "✓ Membership operations benchmark completed\n"; - - $this->benchmark_api_endpoints(); - echo "✓ API endpoints benchmark completed\n"; - - $this->benchmark_database_queries(); - echo "✓ Database queries benchmark completed\n"; - - } catch (Exception $e) { - $this->results['error'] = $e->getMessage(); - echo "✗ Benchmark failed: " . $e->getMessage() . "\n"; - } - - return $this->results; - } - - public function save_results($filename = null) { - $filename = $filename ?: 'performance-results-' . date('Y-m-d-H-i-s') . '.json'; - $filepath = dirname(__FILE__) . '/' . $filename; - - file_put_contents($filepath, json_encode($this->results, JSON_PRETTY_PRINT)); - echo "Results saved to: $filepath\n"; - - return $filepath; - } + + private $results = []; + private $start_time; + private $start_memory; + + public function __construct() { + $this->results['test_run'] = date('Y-m-d H:i:s'); + $this->results['php_version'] = PHP_VERSION; + $this->results['wordpress_version'] = get_bloginfo('version'); + $this->results['plugin_version'] = $this->get_plugin_version(); + } + + private function get_plugin_version() { + $plugin_data = get_plugin_data(ULTIMATE_MULTISITE_PLUGIN); + return $plugin_data['Version'] ?? 'unknown'; + } + + private function start_measurement() { + $this->start_time = microtime(true); + $this->start_memory = memory_get_usage(true); + + // Reset WordPress query count + global $wpdb; + $wpdb->num_queries = 0; + } + + private function end_measurement($operation_name) { + $end_time = microtime(true); + $end_memory = memory_get_usage(true); + + global $wpdb; + + $this->results[$operation_name] = [ + 'execution_time_ms' => round(($end_time - $this->start_time) * 1000, 2), + 'memory_usage_mb' => round(($end_memory - $this->start_memory) / 1024 / 1024, 2), + 'peak_memory_mb' => round(memory_get_peak_usage(true) / 1024 / 1024, 2), + 'database_queries' => $wpdb->num_queries, + ]; + } + + public function benchmark_dashboard_loading() { + $this->start_measurement(); + + // Simulate dashboard loading + $dashboard = new \WP_Ultimo\Admin_Pages\Dashboard_Admin_Page(); + $dashboard->register(); + + // Test dashboard data loading + $stats = wu_get_dashboard_statistics(); + + $this->end_measurement('dashboard_loading'); + } + + public function benchmark_checkout_process() { + $this->start_measurement(); + + // Simulate checkout initialization + $checkout = \WP_Ultimo\Checkout\Checkout::get_instance(); + + // Test pricing plans loading + $plans = wu_get_plans(['number' => 10]); + + // Test form rendering preparation + $fields = wu_get_signup_fields(); + + $this->end_measurement('checkout_process'); + } + + public function benchmark_site_creation() { + $this->start_measurement(); + + // Test site creation data preparation + $site_data = [ + 'domain' => 'test-' . time() . '.example.com', + 'title' => 'Test Site ' . time(), + 'user_id' => 1, + 'plan_id' => 1, + ]; + + // Validate site data (without actually creating) + $validator = new \WP_Ultimo\Validators\Site_Validator(); + $is_valid = $validator->validate($site_data); + + $this->end_measurement('site_creation_validation'); + } + + public function benchmark_membership_operations() { + $this->start_measurement(); + + // Test membership queries + $memberships = wu_get_memberships(['number' => 10]); + + // Test membership status calculations + foreach ($memberships as $membership) { + $membership->get_status(); + $membership->is_active(); + } + + $this->end_measurement('membership_operations'); + } + + public function benchmark_api_endpoints() { + $this->start_measurement(); + + // Test API endpoint registration + $api = new \WP_Ultimo\API(); + $api->register(); + + // Test API data preparation + $sites = wu_get_sites(['number' => 5]); + $api_data = []; + + foreach ($sites as $site) { + $api_data[] = [ + 'id' => $site->get_id(), + 'domain' => $site->get_domain(), + 'title' => $site->get_title(), + ]; + } + + $this->end_measurement('api_endpoints'); + } + + public function benchmark_database_queries() { + global $wpdb; + + $this->start_measurement(); + + // Test common database operations + $tables = [ + 'wu_memberships', + 'wu_sites', + 'wu_plans', + 'wu_customers', + ]; + + foreach ($tables as $table) { + $wpdb->get_var("SELECT COUNT(*) FROM $table LIMIT 1"); + } + + $this->end_measurement('database_queries'); + } + + public function run_all_benchmarks() { + echo "Starting performance benchmarks...\n"; + + try { + $this->benchmark_dashboard_loading(); + echo "✓ Dashboard loading benchmark completed\n"; + + $this->benchmark_checkout_process(); + echo "✓ Checkout process benchmark completed\n"; + + $this->benchmark_site_creation(); + echo "✓ Site creation validation benchmark completed\n"; + + $this->benchmark_membership_operations(); + echo "✓ Membership operations benchmark completed\n"; + + $this->benchmark_api_endpoints(); + echo "✓ API endpoints benchmark completed\n"; + + $this->benchmark_database_queries(); + echo "✓ Database queries benchmark completed\n"; + } catch (Exception $e) { + $this->results['error'] = $e->getMessage(); + echo '✗ Benchmark failed: ' . $e->getMessage() . "\n"; + } + + return $this->results; + } + + public function save_results($filename = null) { + $filename = $filename ?: 'performance-results-' . date('Y-m-d-H-i-s') . '.json'; + $filepath = __DIR__ . '/' . $filename; + + file_put_contents($filepath, json_encode($this->results, JSON_PRETTY_PRINT)); + echo "Results saved to: $filepath\n"; + + return $filepath; + } } // Run benchmarks if this script is executed directly if (basename(__FILE__) === basename($_SERVER['SCRIPT_NAME'])) { - $benchmark = new Performance_Benchmark(); - $results = $benchmark->run_all_benchmarks(); - - // Output JSON for CI/CD consumption - echo json_encode($results, JSON_PRETTY_PRINT); - - // Also save to file - $benchmark->save_results(); -} \ No newline at end of file + $benchmark = new Performance_Benchmark(); + $results = $benchmark->run_all_benchmarks(); + + // Output JSON for CI/CD consumption + echo json_encode($results, JSON_PRETTY_PRINT); + + // Also save to file + $benchmark->save_results(); +} diff --git a/tests/performance-comparator.php b/tests/performance-comparator.php index deae90dd9..1c28ddeec 100755 --- a/tests/performance-comparator.php +++ b/tests/performance-comparator.php @@ -2,269 +2,268 @@ /** * Performance Comparison Utility - * + * * Compares performance results between baseline and current branch * and detects regressions based on configurable thresholds. */ class Performance_Comparator { - - private $baseline_results; - private $current_results; - private $thresholds = [ - 'execution_time_ms' => 15, // 15% increase threshold - 'memory_usage_mb' => 20, // 20% increase threshold - 'database_queries' => 10, // 10% increase threshold - ]; - - private $critical_thresholds = [ - 'execution_time_ms' => 30, // 30% increase for critical - 'memory_usage_mb' => 40, // 40% increase for critical - 'database_queries' => 25, // 25% increase for critical - ]; - - /** - * Minimum absolute change required before a percentage threshold is applied. - * Prevents false positives on sub-millisecond measurements where CI runner - * noise (scheduler jitter, CPU load) dominates over real regressions. - * A 42% change on 0.26ms is only 0.11ms — well within normal system noise. - */ - private $minimum_absolute_change = [ - 'execution_time_ms' => 1.0, // Ignore changes smaller than 1ms - 'memory_usage_mb' => 0.5, // Ignore changes smaller than 0.5MB - 'database_queries' => 1, // Ignore changes smaller than 1 query - ]; - - public function __construct($baseline_file, $current_file) { - $this->baseline_results = $this->load_results($baseline_file); - $this->current_results = $this->load_results($current_file); - } - - private function load_results($file) { - if (!file_exists($file)) { - throw new Exception("Performance results file not found: $file"); - } - - $content = file_get_contents($file); - $results = json_decode($content, true); - - if (json_last_error() !== JSON_ERROR_NONE) { - throw new Exception("Invalid JSON in results file: $file"); - } - - return $results; - } - - public function compare() { - $comparison = [ - 'summary' => [ - 'total_tests' => 0, - 'regressions' => 0, - 'critical_regressions' => 0, - 'improvements' => 0, - 'no_change' => 0, - ], - 'details' => [], - 'status' => 'pass' - ]; - - // Compare each benchmark - $benchmarks = [ - 'dashboard_loading', - 'checkout_process', - 'site_creation_validation', - 'membership_operations', - 'api_endpoints', - 'database_queries' - ]; - - foreach ($benchmarks as $benchmark) { - if (!isset($this->baseline_results[$benchmark]) || !isset($this->current_results[$benchmark])) { - continue; - } - - $comparison['summary']['total_tests']++; - - $result = $this->compare_benchmark($benchmark); - $comparison['details'][$benchmark] = $result; - - // Update summary counters - if ($result['status'] === 'critical_regression') { - $comparison['summary']['critical_regressions']++; - $comparison['status'] = 'fail'; - } elseif ($result['status'] === 'regression') { - $comparison['summary']['regressions']++; - } elseif ($result['status'] === 'improvement') { - $comparison['summary']['improvements']++; - } else { - $comparison['summary']['no_change']++; - } - } - - return $comparison; - } - - private function compare_benchmark($benchmark) { - $baseline = $this->baseline_results[$benchmark]; - $current = $this->current_results[$benchmark]; - - $result = [ - 'baseline' => $baseline, - 'current' => $current, - 'changes' => [], - 'status' => 'no_change', - 'issues' => [] - ]; - - foreach ($this->thresholds as $metric => $threshold) { - if (!isset($baseline[$metric]) || !isset($current[$metric])) { - continue; - } - - $baseline_value = $baseline[$metric]; - $current_value = $current[$metric]; - - if ($baseline_value == 0) { - continue; // Avoid division by zero - } - - $change_percent = (($current_value - $baseline_value) / $baseline_value) * 100; - - $absolute_change = $current_value - $baseline_value; - - $result['changes'][$metric] = [ - 'baseline' => $baseline_value, - 'current' => $current_value, - 'change_percent' => round($change_percent, 2), - 'change_absolute' => $absolute_change - ]; - - // Skip threshold checks when the absolute change is below the noise floor. - // Sub-millisecond timing differences are dominated by CI runner jitter and - // do not represent real regressions. - $min_absolute = $this->minimum_absolute_change[$metric] ?? 0; - if (abs($absolute_change) < $min_absolute) { - // Treat as no_change — noise floor not exceeded - continue; - } - - // Check for critical regression - if ($change_percent > $this->critical_thresholds[$metric]) { - $result['status'] = 'critical_regression'; - $result['issues'][] = "Critical: {$metric} increased by {$change_percent}% (threshold: {$this->critical_thresholds[$metric]}%)"; - } - // Check for normal regression - elseif ($change_percent > $this->thresholds[$metric]) { - if ($result['status'] !== 'critical_regression') { - $result['status'] = 'regression'; - } - $result['issues'][] = "Warning: {$metric} increased by {$change_percent}% (threshold: {$this->thresholds[$metric]}%)"; - } - // Check for improvement - elseif ($change_percent < -5) { // 5% improvement threshold - if ($result['status'] === 'no_change') { - $result['status'] = 'improvement'; - } - } - } - - return $result; - } - - public function generate_markdown_report() { - $comparison = $this->compare(); - - $markdown = "# Performance Test Results\n\n"; - - // Summary section - $markdown .= "## Summary\n\n"; - $markdown .= "| Metric | Count |\n"; - $markdown .= "|--------|-------|\n"; - $markdown .= "| Total Tests | {$comparison['summary']['total_tests']} |\n"; - $markdown .= "| Critical Regressions | {$comparison['summary']['critical_regressions']} |\n"; - $markdown .= "| Regressions | {$comparison['summary']['regressions']} |\n"; - $markdown .= "| Improvements | {$comparison['summary']['improvements']} |\n"; - $markdown .= "| No Change | {$comparison['summary']['no_change']} |\n\n"; - - // Overall status - $status_emoji = $comparison['status'] === 'pass' ? '✅' : '❌'; - $markdown .= "**Overall Status: {$status_emoji} {$comparison['status']}**\n\n"; - - // Detailed results - $markdown .= "## Detailed Results\n\n"; - - foreach ($comparison['details'] as $benchmark => $result) { - $status_emoji = $this->get_status_emoji($result['status']); - $markdown .= "### {$benchmark} {$status_emoji}\n\n"; - - if (!empty($result['issues'])) { - $markdown .= "**Issues:**\n"; - foreach ($result['issues'] as $issue) { - $markdown .= "- {$issue}\n"; - } - $markdown .= "\n"; - } - - $markdown .= "| Metric | Baseline | Current | Change |\n"; - $markdown .= "|--------|----------|---------|--------|\n"; - - foreach ($result['changes'] as $metric => $change) { - $change_display = $change['change_percent'] > 0 - ? "+{$change['change_percent']}%" - : "{$change['change_percent']}%"; - - $markdown .= "| {$metric} | {$change['baseline']} | {$change['current']} | {$change_display} |\n"; - } - - $markdown .= "\n"; - } - - return $markdown; - } - - private function get_status_emoji($status) { - switch ($status) { - case 'critical_regression': - return '🚨'; - case 'regression': - return '⚠️'; - case 'improvement': - return '✨'; - default: - return '✅'; - } - } - - public function save_comparison_report($filename = null) { - $comparison = $this->compare(); - $filename = $filename ?: 'performance-comparison-' . date('Y-m-d-H-i-s') . '.json'; - $filepath = dirname(__FILE__) . '/' . $filename; - - file_put_contents($filepath, json_encode($comparison, JSON_PRETTY_PRINT)); - return $filepath; - } + + private $baseline_results; + private $current_results; + private $thresholds = [ + 'execution_time_ms' => 15, // 15% increase threshold + 'memory_usage_mb' => 20, // 20% increase threshold + 'database_queries' => 10, // 10% increase threshold + ]; + + private $critical_thresholds = [ + 'execution_time_ms' => 30, // 30% increase for critical + 'memory_usage_mb' => 40, // 40% increase for critical + 'database_queries' => 25, // 25% increase for critical + ]; + + /** + * Minimum absolute change required before a percentage threshold is applied. + * Prevents false positives on sub-millisecond measurements where CI runner + * noise (scheduler jitter, CPU load) dominates over real regressions. + * A 42% change on 0.26ms is only 0.11ms — well within normal system noise. + */ + private $minimum_absolute_change = [ + 'execution_time_ms' => 1.0, // Ignore changes smaller than 1ms + 'memory_usage_mb' => 0.5, // Ignore changes smaller than 0.5MB + 'database_queries' => 1, // Ignore changes smaller than 1 query + ]; + + public function __construct($baseline_file, $current_file) { + $this->baseline_results = $this->load_results($baseline_file); + $this->current_results = $this->load_results($current_file); + } + + private function load_results($file) { + if (! file_exists($file)) { + throw new Exception("Performance results file not found: $file"); + } + + $content = file_get_contents($file); + $results = json_decode($content, true); + + if (json_last_error() !== JSON_ERROR_NONE) { + throw new Exception("Invalid JSON in results file: $file"); + } + + return $results; + } + + public function compare() { + $comparison = [ + 'summary' => [ + 'total_tests' => 0, + 'regressions' => 0, + 'critical_regressions' => 0, + 'improvements' => 0, + 'no_change' => 0, + ], + 'details' => [], + 'status' => 'pass', + ]; + + // Compare each benchmark + $benchmarks = [ + 'dashboard_loading', + 'checkout_process', + 'site_creation_validation', + 'membership_operations', + 'api_endpoints', + 'database_queries', + ]; + + foreach ($benchmarks as $benchmark) { + if (! isset($this->baseline_results[$benchmark]) || ! isset($this->current_results[$benchmark])) { + continue; + } + + ++$comparison['summary']['total_tests']; + + $result = $this->compare_benchmark($benchmark); + $comparison['details'][$benchmark] = $result; + + // Update summary counters + if ($result['status'] === 'critical_regression') { + ++$comparison['summary']['critical_regressions']; + $comparison['status'] = 'fail'; + } elseif ($result['status'] === 'regression') { + ++$comparison['summary']['regressions']; + } elseif ($result['status'] === 'improvement') { + ++$comparison['summary']['improvements']; + } else { + ++$comparison['summary']['no_change']; + } + } + + return $comparison; + } + + private function compare_benchmark($benchmark) { + $baseline = $this->baseline_results[$benchmark]; + $current = $this->current_results[$benchmark]; + + $result = [ + 'baseline' => $baseline, + 'current' => $current, + 'changes' => [], + 'status' => 'no_change', + 'issues' => [], + ]; + + foreach ($this->thresholds as $metric => $threshold) { + if (! isset($baseline[$metric]) || ! isset($current[$metric])) { + continue; + } + + $baseline_value = $baseline[$metric]; + $current_value = $current[$metric]; + + if ($baseline_value == 0) { + continue; // Avoid division by zero + } + + $change_percent = (($current_value - $baseline_value) / $baseline_value) * 100; + + $absolute_change = $current_value - $baseline_value; + + $result['changes'][$metric] = [ + 'baseline' => $baseline_value, + 'current' => $current_value, + 'change_percent' => round($change_percent, 2), + 'change_absolute' => $absolute_change, + ]; + + // Skip threshold checks when the absolute change is below the noise floor. + // Sub-millisecond timing differences are dominated by CI runner jitter and + // do not represent real regressions. + $min_absolute = $this->minimum_absolute_change[$metric] ?? 0; + if (abs($absolute_change) < $min_absolute) { + // Treat as no_change — noise floor not exceeded + continue; + } + + // Check for critical regression + if ($change_percent > $this->critical_thresholds[$metric]) { + $result['status'] = 'critical_regression'; + $result['issues'][] = "Critical: {$metric} increased by {$change_percent}% (threshold: {$this->critical_thresholds[$metric]}%)"; + } + // Check for normal regression + elseif ($change_percent > $this->thresholds[$metric]) { + if ($result['status'] !== 'critical_regression') { + $result['status'] = 'regression'; + } + $result['issues'][] = "Warning: {$metric} increased by {$change_percent}% (threshold: {$this->thresholds[$metric]}%)"; + } + // Check for improvement + elseif ($change_percent < -5) { // 5% improvement threshold + if ($result['status'] === 'no_change') { + $result['status'] = 'improvement'; + } + } + } + + return $result; + } + + public function generate_markdown_report() { + $comparison = $this->compare(); + + $markdown = "# Performance Test Results\n\n"; + + // Summary section + $markdown .= "## Summary\n\n"; + $markdown .= "| Metric | Count |\n"; + $markdown .= "|--------|-------|\n"; + $markdown .= "| Total Tests | {$comparison['summary']['total_tests']} |\n"; + $markdown .= "| Critical Regressions | {$comparison['summary']['critical_regressions']} |\n"; + $markdown .= "| Regressions | {$comparison['summary']['regressions']} |\n"; + $markdown .= "| Improvements | {$comparison['summary']['improvements']} |\n"; + $markdown .= "| No Change | {$comparison['summary']['no_change']} |\n\n"; + + // Overall status + $status_emoji = $comparison['status'] === 'pass' ? '✅' : '❌'; + $markdown .= "**Overall Status: {$status_emoji} {$comparison['status']}**\n\n"; + + // Detailed results + $markdown .= "## Detailed Results\n\n"; + + foreach ($comparison['details'] as $benchmark => $result) { + $status_emoji = $this->get_status_emoji($result['status']); + $markdown .= "### {$benchmark} {$status_emoji}\n\n"; + + if (! empty($result['issues'])) { + $markdown .= "**Issues:**\n"; + foreach ($result['issues'] as $issue) { + $markdown .= "- {$issue}\n"; + } + $markdown .= "\n"; + } + + $markdown .= "| Metric | Baseline | Current | Change |\n"; + $markdown .= "|--------|----------|---------|--------|\n"; + + foreach ($result['changes'] as $metric => $change) { + $change_display = $change['change_percent'] > 0 + ? "+{$change['change_percent']}%" + : "{$change['change_percent']}%"; + + $markdown .= "| {$metric} | {$change['baseline']} | {$change['current']} | {$change_display} |\n"; + } + + $markdown .= "\n"; + } + + return $markdown; + } + + private function get_status_emoji($status) { + switch ($status) { + case 'critical_regression': + return '🚨'; + case 'regression': + return '⚠️'; + case 'improvement': + return '✨'; + default: + return '✅'; + } + } + + public function save_comparison_report($filename = null) { + $comparison = $this->compare(); + $filename = $filename ?: 'performance-comparison-' . date('Y-m-d-H-i-s') . '.json'; + $filepath = __DIR__ . '/' . $filename; + + file_put_contents($filepath, json_encode($comparison, JSON_PRETTY_PRINT)); + return $filepath; + } } // Run comparison if this script is executed directly if (basename(__FILE__) === basename($_SERVER['SCRIPT_NAME'])) { - $baseline_file = $argv[1] ?? null; - $current_file = $argv[2] ?? null; - - if (!$baseline_file || !$current_file) { - die("Usage: php performance-comparator.php \n"); - } - - try { - $comparator = new Performance_Comparator($baseline_file, $current_file); - - // Save detailed comparison - $comparator->save_comparison_report(); - - // Output markdown report for PR comment - echo $comparator->generate_markdown_report(); - - } catch (Exception $e) { - echo "Error: " . $e->getMessage() . "\n"; - exit(1); - } -} \ No newline at end of file + $baseline_file = $argv[1] ?? null; + $current_file = $argv[2] ?? null; + + if (! $baseline_file || ! $current_file) { + die("Usage: php performance-comparator.php \n"); + } + + try { + $comparator = new Performance_Comparator($baseline_file, $current_file); + + // Save detailed comparison + $comparator->save_comparison_report(); + + // Output markdown report for PR comment + echo $comparator->generate_markdown_report(); + } catch (Exception $e) { + echo 'Error: ' . $e->getMessage() . "\n"; + exit(1); + } +} diff --git a/tests/simple-performance-test.php b/tests/simple-performance-test.php index 1433e42f2..29841bd6d 100644 --- a/tests/simple-performance-test.php +++ b/tests/simple-performance-test.php @@ -2,221 +2,235 @@ /** * Simple Performance Test for Validation - * + * * This is a minimal version that doesn't require WordPress test environment * just to validate that our performance testing framework works. */ // Mock WordPress functions function get_plugin_data($plugin_file) { - return ['Version' => '2.4.7']; + return ['Version' => '2.4.7']; } function get_bloginfo($show) { - return $show === 'version' ? '6.4.3' : 'Test Site'; + return $show === 'version' ? '6.4.3' : 'Test Site'; } function wu_get_dashboard_statistics() { - return ['sites' => 10, 'users' => 50]; + return [ + 'sites' => 10, + 'users' => 50, + ]; } function wu_get_plans($args = []) { - return array_fill(0, $args['number'] ?? 5, ['id' => 1, 'name' => 'Test Plan']); + return array_fill(0, $args['number'] ?? 5, [ + 'id' => 1, + 'name' => 'Test Plan', + ]); } function wu_get_signup_fields() { - return array_fill(0, 10, ['id' => 1, 'type' => 'text']); + return array_fill(0, 10, [ + 'id' => 1, + 'type' => 'text', + ]); } function wu_get_memberships($args = []) { - return array_fill(0, $args['number'] ?? 5, ['id' => 1, 'status' => 'active']); + return array_fill(0, $args['number'] ?? 5, [ + 'id' => 1, + 'status' => 'active', + ]); } function wu_get_sites($args = []) { - return array_fill(0, $args['number'] ?? 5, ['id' => 1, 'domain' => 'test.com']); + return array_fill(0, $args['number'] ?? 5, [ + 'id' => 1, + 'domain' => 'test.com', + ]); } // Mock global $wpdb $GLOBALS['wpdb'] = (object) ['num_queries' => 0]; class Simple_Performance_Benchmark { - - private $results = []; - private $start_time; - private $start_memory; - - public function __construct() { - $this->results['test_run'] = date('Y-m-d H:i:s'); - $this->results['php_version'] = PHP_VERSION; - $this->results['wordpress_version'] = get_bloginfo('version'); - $this->results['plugin_version'] = '2.4.7'; - } - - private function start_measurement() { - $this->start_time = microtime(true); - $this->start_memory = memory_get_usage(true); - - // Reset WordPress query count - global $wpdb; - $wpdb->num_queries = 0; - } - - private function end_measurement($operation_name) { - $end_time = microtime(true); - $end_memory = memory_get_usage(true); - - global $wpdb; - - $this->results[$operation_name] = [ - 'execution_time_ms' => round(($end_time - $this->start_time) * 1000, 2), - 'memory_usage_mb' => round(($end_memory - $this->start_memory) / 1024 / 1024, 2), - 'peak_memory_mb' => round(memory_get_peak_usage(true) / 1024 / 1024, 2), - 'database_queries' => $wpdb->num_queries, - ]; - } - - public function benchmark_dashboard_loading() { - $this->start_measurement(); - - // Simulate dashboard loading - usleep(1000); // Simulate dashboard registration - - // Test dashboard data loading - $stats = wu_get_dashboard_statistics(); - - $this->end_measurement('dashboard_loading'); - } - - public function benchmark_checkout_process() { - $this->start_measurement(); - - // Simulate checkout initialization - usleep(500); // Simulate checkout setup - - // Test pricing plans loading - $plans = wu_get_plans(['number' => 10]); - - // Test form rendering preparation - $fields = wu_get_signup_fields(); - - $this->end_measurement('checkout_process'); - } - - public function benchmark_site_creation() { - $this->start_measurement(); - - // Test site creation data preparation - $site_data = [ - 'domain' => 'test-' . time() . '.example.com', - 'title' => 'Test Site ' . time(), - 'user_id' => 1, - 'plan_id' => 1, - ]; - - // Validate site data (without actually creating) - usleep(500); // Simulate validation - $is_valid = true; - - $this->end_measurement('site_creation_validation'); - } - - public function benchmark_membership_operations() { - $this->start_measurement(); - - // Test membership queries - $memberships = wu_get_memberships(['number' => 10]); - - // Test membership status calculations - foreach ($memberships as $membership) { - $membership['status']; // Access status - } - - $this->end_measurement('membership_operations'); - } - - public function benchmark_api_endpoints() { - $this->start_measurement(); - - // Test API endpoint registration - usleep(800); // Simulate API registration - - // Test API data preparation - $sites = wu_get_sites(['number' => 5]); - $api_data = []; - - foreach ($sites as $site) { - $api_data[] = [ - 'id' => $site['id'], - 'domain' => $site['domain'], - 'title' => $site['domain'], - ]; - } - - $this->end_measurement('api_endpoints'); - } - - public function benchmark_database_queries() { - global $wpdb; - - $this->start_measurement(); - - // Simulate database operations - $wpdb->num_queries = 5; // Simulate 5 queries - - usleep(200); // Simulate query time - - $this->end_measurement('database_queries'); - } - - public function run_all_benchmarks() { - fwrite(STDERR, "Starting simplified performance benchmarks...\n"); - - try { - $this->benchmark_dashboard_loading(); - fwrite(STDERR, "✓ Dashboard loading benchmark completed\n"); - - $this->benchmark_checkout_process(); - fwrite(STDERR, "✓ Checkout process benchmark completed\n"); - - $this->benchmark_site_creation(); - fwrite(STDERR, "✓ Site creation validation benchmark completed\n"); - - $this->benchmark_membership_operations(); - fwrite(STDERR, "✓ Membership operations benchmark completed\n"); - - $this->benchmark_api_endpoints(); - fwrite(STDERR, "✓ API endpoints benchmark completed\n"); - - $this->benchmark_database_queries(); - fwrite(STDERR, "✓ Database queries benchmark completed\n"); - - } catch (Exception $e) { - $this->results['error'] = $e->getMessage(); - fwrite(STDERR, "✗ Benchmark failed: " . $e->getMessage() . "\n"); - } - - return $this->results; - } - - public function save_results($filename = null) { - $filename = $filename ?: 'simple-performance-results-' . date('Y-m-d-H-i-s') . '.json'; - $filepath = dirname(__FILE__) . '/' . $filename; - - file_put_contents($filepath, json_encode($this->results, JSON_PRETTY_PRINT)); - fwrite(STDERR, "Results saved to: $filepath\n"); - - return $filepath; - } + + private $results = []; + private $start_time; + private $start_memory; + + public function __construct() { + $this->results['test_run'] = date('Y-m-d H:i:s'); + $this->results['php_version'] = PHP_VERSION; + $this->results['wordpress_version'] = get_bloginfo('version'); + $this->results['plugin_version'] = '2.4.7'; + } + + private function start_measurement() { + $this->start_time = microtime(true); + $this->start_memory = memory_get_usage(true); + + // Reset WordPress query count + global $wpdb; + $wpdb->num_queries = 0; + } + + private function end_measurement($operation_name) { + $end_time = microtime(true); + $end_memory = memory_get_usage(true); + + global $wpdb; + + $this->results[$operation_name] = [ + 'execution_time_ms' => round(($end_time - $this->start_time) * 1000, 2), + 'memory_usage_mb' => round(($end_memory - $this->start_memory) / 1024 / 1024, 2), + 'peak_memory_mb' => round(memory_get_peak_usage(true) / 1024 / 1024, 2), + 'database_queries' => $wpdb->num_queries, + ]; + } + + public function benchmark_dashboard_loading() { + $this->start_measurement(); + + // Simulate dashboard loading + usleep(1000); // Simulate dashboard registration + + // Test dashboard data loading + $stats = wu_get_dashboard_statistics(); + + $this->end_measurement('dashboard_loading'); + } + + public function benchmark_checkout_process() { + $this->start_measurement(); + + // Simulate checkout initialization + usleep(500); // Simulate checkout setup + + // Test pricing plans loading + $plans = wu_get_plans(['number' => 10]); + + // Test form rendering preparation + $fields = wu_get_signup_fields(); + + $this->end_measurement('checkout_process'); + } + + public function benchmark_site_creation() { + $this->start_measurement(); + + // Test site creation data preparation + $site_data = [ + 'domain' => 'test-' . time() . '.example.com', + 'title' => 'Test Site ' . time(), + 'user_id' => 1, + 'plan_id' => 1, + ]; + + // Validate site data (without actually creating) + usleep(500); // Simulate validation + $is_valid = true; + + $this->end_measurement('site_creation_validation'); + } + + public function benchmark_membership_operations() { + $this->start_measurement(); + + // Test membership queries + $memberships = wu_get_memberships(['number' => 10]); + + // Test membership status calculations + foreach ($memberships as $membership) { + $membership['status']; // Access status + } + + $this->end_measurement('membership_operations'); + } + + public function benchmark_api_endpoints() { + $this->start_measurement(); + + // Test API endpoint registration + usleep(800); // Simulate API registration + + // Test API data preparation + $sites = wu_get_sites(['number' => 5]); + $api_data = []; + + foreach ($sites as $site) { + $api_data[] = [ + 'id' => $site['id'], + 'domain' => $site['domain'], + 'title' => $site['domain'], + ]; + } + + $this->end_measurement('api_endpoints'); + } + + public function benchmark_database_queries() { + global $wpdb; + + $this->start_measurement(); + + // Simulate database operations + $wpdb->num_queries = 5; // Simulate 5 queries + + usleep(200); // Simulate query time + + $this->end_measurement('database_queries'); + } + + public function run_all_benchmarks() { + fwrite(STDERR, "Starting simplified performance benchmarks...\n"); + + try { + $this->benchmark_dashboard_loading(); + fwrite(STDERR, "✓ Dashboard loading benchmark completed\n"); + + $this->benchmark_checkout_process(); + fwrite(STDERR, "✓ Checkout process benchmark completed\n"); + + $this->benchmark_site_creation(); + fwrite(STDERR, "✓ Site creation validation benchmark completed\n"); + + $this->benchmark_membership_operations(); + fwrite(STDERR, "✓ Membership operations benchmark completed\n"); + + $this->benchmark_api_endpoints(); + fwrite(STDERR, "✓ API endpoints benchmark completed\n"); + + $this->benchmark_database_queries(); + fwrite(STDERR, "✓ Database queries benchmark completed\n"); + } catch (Exception $e) { + $this->results['error'] = $e->getMessage(); + fwrite(STDERR, '✗ Benchmark failed: ' . $e->getMessage() . "\n"); + } + + return $this->results; + } + + public function save_results($filename = null) { + $filename = $filename ?: 'simple-performance-results-' . date('Y-m-d-H-i-s') . '.json'; + $filepath = __DIR__ . '/' . $filename; + + file_put_contents($filepath, json_encode($this->results, JSON_PRETTY_PRINT)); + fwrite(STDERR, "Results saved to: $filepath\n"); + + return $filepath; + } } // Run benchmarks if this script is executed directly if (basename(__FILE__) === basename($_SERVER['SCRIPT_NAME'])) { - $benchmark = new Simple_Performance_Benchmark(); - $results = $benchmark->run_all_benchmarks(); + $benchmark = new Simple_Performance_Benchmark(); + $results = $benchmark->run_all_benchmarks(); - // Output JSON to stdout for CI/CD consumption (progress text goes to stderr) - echo json_encode($results, JSON_PRETTY_PRINT); + // Output JSON to stdout for CI/CD consumption (progress text goes to stderr) + echo json_encode($results, JSON_PRETTY_PRINT); - // Also save to file - $benchmark->save_results(); -} \ No newline at end of file + // Also save to file + $benchmark->save_results(); +} diff --git a/tests/unit/API_Schema_Test.php b/tests/unit/API_Schema_Test.php index eec810ba3..4aa13c899 100644 --- a/tests/unit/API_Schema_Test.php +++ b/tests/unit/API_Schema_Test.php @@ -1479,10 +1479,10 @@ public function test_update_schemas_fields_are_subset_of_create_schemas(): void ['webhook-create.php', 'webhook-update.php'], ]; foreach ( $pairs as [$create_file, $update_file] ) { - $create_schema = $this->load_schema($create_file); - $update_schema = $this->load_schema($update_file); - $create_keys = array_keys($create_schema); - $update_keys = array_keys($update_schema); + $create_schema = $this->load_schema($create_file); + $update_schema = $this->load_schema($update_file); + $create_keys = array_keys($create_schema); + $update_keys = array_keys($update_schema); $extra_in_update = array_diff($update_keys, $create_keys); $this->assertEmpty( $extra_in_update, diff --git a/tests/unit/Cart_Should_Collect_Payment_Test.php b/tests/unit/Cart_Should_Collect_Payment_Test.php index 827c2b1df..2603740a3 100644 --- a/tests/unit/Cart_Should_Collect_Payment_Test.php +++ b/tests/unit/Cart_Should_Collect_Payment_Test.php @@ -57,7 +57,7 @@ private function build_cart_for_product(int $product_id): Cart { return new Cart( [ 'cart_type' => 'new', - 'products' => [ $product_id ], + 'products' => [$product_id], 'duration' => 1, 'duration_unit' => 'month', ] diff --git a/tests/unit/Checkout_Request_Test.php b/tests/unit/Checkout_Request_Test.php index 45799a0fd..e888bc0e1 100644 --- a/tests/unit/Checkout_Request_Test.php +++ b/tests/unit/Checkout_Request_Test.php @@ -3,33 +3,33 @@ final class Checkout_Request_Test extends TestCase { - public function test_request_or_session_accepts_empty_string(): void { - // Ensure empty string in request overrides any default/session value - $_REQUEST['discount_code'] = ''; + public function test_request_or_session_accepts_empty_string(): void { + // Ensure empty string in request overrides any default/session value + $_REQUEST['discount_code'] = ''; - $checkout = \WP_Ultimo\Checkout\Checkout::get_instance(); + $checkout = \WP_Ultimo\Checkout\Checkout::get_instance(); - $value = $checkout->request_or_session('discount_code', 'DEFAULT'); + $value = $checkout->request_or_session('discount_code', 'DEFAULT'); - $this->assertSame('', $value, 'Expected empty discount_code to be honored (clear code).'); + $this->assertSame('', $value, 'Expected empty discount_code to be honored (clear code).'); - unset($_REQUEST['discount_code']); - } + unset($_REQUEST['discount_code']); + } - /** - * Verify that get_checkout_variables() always includes discount_code as a - * string so wu_checkout.discount_code is never undefined in JS. - * - * An undefined value causes the Vue watcher to fire a spurious create_order() - * call on page load when v-init sets the field to an empty string. - */ - public function test_checkout_variables_always_has_discount_code_string(): void { + /** + * Verify that get_checkout_variables() always includes discount_code as a + * string so wu_checkout.discount_code is never undefined in JS. + * + * An undefined value causes the Vue watcher to fire a spurious create_order() + * call on page load when v-init sets the field to an empty string. + */ + public function test_checkout_variables_always_has_discount_code_string(): void { - $checkout = \WP_Ultimo\Checkout\Checkout::get_instance(); + $checkout = \WP_Ultimo\Checkout\Checkout::get_instance(); - $vars = $checkout->get_checkout_variables(); + $vars = $checkout->get_checkout_variables(); - $this->assertArrayHasKey('discount_code', $vars, 'discount_code key must always be present in checkout variables.'); - $this->assertIsString($vars['discount_code'], 'discount_code must always be a string (never undefined/null).'); - } + $this->assertArrayHasKey('discount_code', $vars, 'discount_code key must always be present in checkout variables.'); + $this->assertIsString($vars['discount_code'], 'discount_code must always be a string (never undefined/null).'); + } } diff --git a/tests/unit/VueBuild_Test.php b/tests/unit/VueBuild_Test.php index 104654e45..6b7a57cdf 100644 --- a/tests/unit/VueBuild_Test.php +++ b/tests/unit/VueBuild_Test.php @@ -2,21 +2,21 @@ use PHPUnit\Framework\TestCase; final class VueBuild_Test extends TestCase { - public function test_vue_min_is_production_flags(): void { - $path = __DIR__ . '/../../assets/js/lib/vue.min.js'; - $this->assertFileExists($path, 'vue.min.js does not exist'); - $contents = file_get_contents($path); - $this->assertNotFalse($contents); - // Production build should set productionTip:false and devtools:false - $this->assertStringContainsString('productionTip:!1', $contents, 'Expected productionTip disabled in production build'); - $this->assertStringContainsString('devtools:!1', $contents, 'Expected devtools disabled in production build'); - } + public function test_vue_min_is_production_flags(): void { + $path = __DIR__ . '/../../assets/js/lib/vue.min.js'; + $this->assertFileExists($path, 'vue.min.js does not exist'); + $contents = file_get_contents($path); + $this->assertNotFalse($contents); + // Production build should set productionTip:false and devtools:false + $this->assertStringContainsString('productionTip:!1', $contents, 'Expected productionTip disabled in production build'); + $this->assertStringContainsString('devtools:!1', $contents, 'Expected devtools disabled in production build'); + } - public function test_vue_min_has_wu_vue_wrapper(): void { - $path = __DIR__ . '/../../assets/js/lib/vue.min.js'; - $contents = file_get_contents($path); - $this->assertNotFalse($contents); - $this->assertStringContainsString('window.wu_vue', $contents, 'Expected window.wu_vue wrapper present'); - $this->assertMatchesRegularExpression('/defineComponent/', $contents, 'Expected defineComponent to be exposed via wrapper'); - } + public function test_vue_min_has_wu_vue_wrapper(): void { + $path = __DIR__ . '/../../assets/js/lib/vue.min.js'; + $contents = file_get_contents($path); + $this->assertNotFalse($contents); + $this->assertStringContainsString('window.wu_vue', $contents, 'Expected window.wu_vue wrapper present'); + $this->assertMatchesRegularExpression('/defineComponent/', $contents, 'Expected defineComponent to be exposed via wrapper'); + } } diff --git a/views/admin-pages/fields/field-multiselect.php b/views/admin-pages/fields/field-multiselect.php index f306aaa7d..1803446e5 100644 --- a/views/admin-pages/fields/field-multiselect.php +++ b/views/admin-pages/fields/field-multiselect.php @@ -46,11 +46,11 @@ class="wrapper_classes)); ?>" options as $value => $option) : ?> - 'Label') and array options ('key' => ['title' => 'Label', 'desc' => '...']) - $option_title = is_array($option) ? ($option['title'] ?? '') : (string) $option; - $option_desc = is_array($option) ? ($option['desc'] ?? '') : ''; - ?> +
  • diff --git a/views/checkout/form.php b/views/checkout/form.php index f9e152eb0..fd1037084 100644 --- a/views/checkout/form.php +++ b/views/checkout/form.php @@ -28,9 +28,10 @@ class="wu_checkout_form_ wu-relative * email/username/password fields are not required. */ if (is_user_logged_in()) : - ?> + ?> - -
    +
    @@ -246,7 +246,7 @@ get_sites()) : ?> - get_sites() as $site) : ?> + get_sites() as $site) : ?>
    @@ -264,7 +264,7 @@ class="wu-mb-4 sm:wu-mb-0 wu-rounded"
    - get_title())); ?> + get_title())); ?> get_type() === 'pending') : ?> diff --git a/views/external-cron/dashboard.php b/views/external-cron/dashboard.php index f4fbca9ff..edb97fc47 100644 --- a/views/external-cron/dashboard.php +++ b/views/external-cron/dashboard.php @@ -176,10 +176,12 @@ - + + ?> + diff --git a/views/wizards/host-integrations/ready.php b/views/wizards/host-integrations/ready.php index 8cff142b9..b31b13f34 100644 --- a/views/wizards/host-integrations/ready.php +++ b/views/wizards/host-integrations/ready.php @@ -26,7 +26,19 @@ - +