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
10 changes: 9 additions & 1 deletion inc/checkout/class-cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,15 @@ public function __construct($args) {
*/
$this->attributes = (object) $args;

if (apply_filters('wu_cart_skip_initialization', false, $args, $this)) {
$skip_initialization = apply_filters('wu_cart_skip_initialization', false, $args, $this);

if ($skip_initialization) {
if ($skip_initialization instanceof \WP_Error) {
$this->errors->merge_from($skip_initialization);
} elseif ( ! $this->errors->has_errors()) {
$this->errors->add('cart_initialization_skipped', __('This checkout is not available.', 'ultimate-multisite'));
}

return;
}

Expand Down
16 changes: 16 additions & 0 deletions tests/WP_Ultimo/Checkout/Checkout_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
remove_filter('wu_checkout_skip_user_exists_check', [$this, 'skip_checkout']);
remove_filter('wu_checkout_skip_inline_login', [$this, 'skip_checkout']);
remove_filter('wu_cart_skip_initialization', [$this, 'set_cart_error']);
remove_filter('wu_cart_skip_initialization', '__return_true');

parent::tearDown();
}
Expand Down Expand Up @@ -1696,7 +1697,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 1700 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.

Check warning on line 1700 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 @@ -1850,9 +1851,9 @@
*/
public function test_setup_checkout_sets_already_setup_flag(): void {

$checkout = Checkout::get_instance();

Check warning on line 1854 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

Check warning on line 1854 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 1855 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

Check warning on line 1855 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 1856 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

Check warning on line 1856 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 @@ -1901,10 +1902,10 @@
*/
public function test_setup_checkout_initialises_session(): void {

$checkout = Checkout::get_instance();

Check warning on line 1905 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

Check warning on line 1905 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 1906 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

Check warning on line 1906 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 1907 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

Check warning on line 1907 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 1908 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

Check warning on line 1908 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 @@ -1939,8 +1940,8 @@

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

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

Check warning on line 1943 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

Check warning on line 1943 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 1944 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

Check warning on line 1944 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 Expand Up @@ -5484,6 +5485,21 @@
$this->assertEquals('checkout_disabled', $cart->errors->get_error_code());
}

/**
* Test that Cart constructor marks skipped initialization as invalid.
*/
public function test_cart_constructor_sets_default_error_when_skip_filter_returns_true(): void {

add_filter('wu_cart_skip_initialization', '__return_true');

$cart = new Cart([
'products' => [],
]);

$this->assertFalse($cart->is_valid());
$this->assertEquals('cart_initialization_skipped', $cart->errors->get_error_code());
}

// -------------------------------------------------------------------------
// Teardown
// -------------------------------------------------------------------------
Expand Down
Loading