Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions inc/checkout/class-checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -3383,10 +3383,14 @@ public function request_or_session($key, $default_value = false) {
*/
public function get_next_step_name() {

$steps = $this->steps;
$steps = $this->get_steps_or_empty_array();

$keys = array_column($steps, 'id');

if (empty($keys)) {
return $this->step_name;
}

$current_step_index = array_search($this->step_name, array_values($keys), true);

/*
Expand All @@ -3411,7 +3415,7 @@ public function get_next_step_name() {
*/
public function is_first_step() {

$step_names = array_column($this->steps, 'id');
$step_names = array_column($this->get_steps_or_empty_array(), 'id');

if (empty($step_names)) {
return true;
Expand Down Expand Up @@ -3449,7 +3453,7 @@ public function is_last_step() {
return false;
}

$step_names = array_column($this->steps, 'id');
$step_names = array_column($this->get_steps_or_empty_array(), 'id');

if (empty($step_names)) {
return true;
Expand All @@ -3458,6 +3462,22 @@ public function is_last_step() {
return array_pop($step_names) === $this->step_name;
}

/**
* Returns checkout steps as an array.
*
* Payment return and thank-you requests can enqueue checkout scripts after the
* checkout form context has been cleared, leaving the public steps property
* unset/null. Treat that state as an empty one-step flow instead of fataling
* when navigation helpers call array_column().
*
* @since 2.13.2
* @return array
*/
protected function get_steps_or_empty_array() {

return is_array($this->steps) ? $this->steps : [];
}

/**
* Decides if we should display errors on the checkout screen.
*
Expand Down
7 changes: 7 additions & 0 deletions inc/models/class-membership.php
Original file line number Diff line number Diff line change
Expand Up @@ -2128,6 +2128,13 @@ public function publish_pending_site_async(): void {
$use_loopback = (bool) apply_filters('wu_publish_pending_site_use_loopback', true, $this);
$can_finish_request = function_exists('litespeed_finish_request')
|| function_exists('fastcgi_finish_request');
$server_software = isset($_SERVER['SERVER_SOFTWARE']) ? sanitize_text_field(wp_unslash($_SERVER['SERVER_SOFTWARE'])) : '';
$is_frankenphp = 'frankenphp' === PHP_SAPI || false !== stripos($server_software, 'frankenphp');

if ($is_frankenphp) {
$can_finish_request = false;
}

$can_finish_request = (bool) apply_filters('wu_publish_pending_site_can_finish_request', $can_finish_request, $this);
$loopback_started = false;
$args = ['membership_id' => $this->get_id()];
Expand Down
35 changes: 35 additions & 0 deletions tests/WP_Ultimo/Checkout/Checkout_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,17 @@
$this->assertTrue($checkout->is_first_step());
}

/**
* Test is_first_step with null steps.
*/
public function test_is_first_step_null_steps(): void {

$checkout = Checkout::get_instance();
$checkout->steps = null;

$this->assertTrue($checkout->is_first_step());
}

/**
* Test is_first_step when on first step.
*/
Expand Down Expand Up @@ -624,6 +635,18 @@
$this->assertTrue($checkout->is_last_step());
}

/**
* Test is_last_step with null steps returns true.
*/
public function test_is_last_step_null_steps(): void {

$checkout = Checkout::get_instance();
$checkout->steps = null;
$checkout->step_name = null;

$this->assertTrue($checkout->is_last_step());
}

/**
* Test is_last_step returns false when pre-flight param is set.
*/
Expand Down Expand Up @@ -704,6 +727,18 @@
$this->assertEquals('step-2', $checkout->get_next_step_name());
}

/**
* Test get_next_step_name with null steps returns current step.
*/
public function test_get_next_step_name_null_steps_returns_current(): void {

$checkout = Checkout::get_instance();
$checkout->steps = null;
$checkout->step_name = 'thank-you';

$this->assertEquals('thank-you', $checkout->get_next_step_name());
}

/**
* Test get_next_step_name from middle step.
*/
Expand Down Expand Up @@ -1794,7 +1829,7 @@
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]];

Check warning on line 1832 in tests/WP_Ultimo/Checkout/Checkout_Test.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

When a multi-item array uses associative keys, each value should start on a new line.
return $rules;
});

Expand Down Expand Up @@ -1948,9 +1983,9 @@
*/
public function test_setup_checkout_sets_already_setup_flag(): void {

$checkout = Checkout::get_instance();

Check warning on line 1986 in tests/WP_Ultimo/Checkout/Checkout_Test.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Equals sign not aligned with surrounding assignments; expected 3 spaces but found 4 spaces
$reflection = new \ReflectionClass($checkout);

Check warning on line 1987 in tests/WP_Ultimo/Checkout/Checkout_Test.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Equals sign not aligned with surrounding assignments; expected 1 space but found 2 spaces
$setup_prop = $reflection->getProperty('already_setup');

Check warning on line 1988 in tests/WP_Ultimo/Checkout/Checkout_Test.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Equals sign not aligned with surrounding assignments; expected 1 space but found 2 spaces

if (PHP_VERSION_ID < 80100) {
$setup_prop->setAccessible(true);
Expand Down Expand Up @@ -1999,10 +2034,10 @@
*/
public function test_setup_checkout_initialises_session(): void {

$checkout = Checkout::get_instance();

Check warning on line 2037 in tests/WP_Ultimo/Checkout/Checkout_Test.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Equals sign not aligned with surrounding assignments; expected 5 spaces but found 6 spaces
$reflection = new \ReflectionClass($checkout);

Check warning on line 2038 in tests/WP_Ultimo/Checkout/Checkout_Test.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Equals sign not aligned with surrounding assignments; expected 3 spaces but found 4 spaces
$session_prop = $this->get_session_prop($reflection);

Check warning on line 2039 in tests/WP_Ultimo/Checkout/Checkout_Test.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Equals sign not aligned with surrounding assignments; expected 1 space but found 2 spaces
$setup_prop = $reflection->getProperty('already_setup');

Check warning on line 2040 in tests/WP_Ultimo/Checkout/Checkout_Test.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Equals sign not aligned with surrounding assignments; expected 3 spaces but found 4 spaces

if (PHP_VERSION_ID < 80100) {
$setup_prop->setAccessible(true);
Expand Down Expand Up @@ -2037,8 +2072,8 @@

$setup_prop->setValue($checkout, false);

$_REQUEST['pre-flight'] = '1';

Check warning on line 2075 in tests/WP_Ultimo/Checkout/Checkout_Test.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Equals sign not aligned with surrounding assignments; expected 4 spaces but found 5 spaces
$_REQUEST['checkout_form'] = 'some-form';

Check warning on line 2076 in tests/WP_Ultimo/Checkout/Checkout_Test.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Equals sign not aligned with surrounding assignments; expected 1 space but found 2 spaces
$_REQUEST['some_field'] = 'some_value';

$checkout->setup_checkout();
Expand Down
Loading