Skip to content
Merged
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
45 changes: 45 additions & 0 deletions tests/WP_Ultimo/Checkout/Checkout_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,51 @@ public function test_persist_current_step_to_session_saves_account_fields(): voi
);
}

/**
* Test pre-flight persistence stores filtered fields under pre_selected.
*/
public function test_persist_current_step_to_session_handles_pre_flight(): void {

$checkout = Checkout::get_instance();
$reflection = new \ReflectionClass($checkout);

$this->ensure_session($checkout);

$session_prop = $this->get_session_prop($reflection);
$session = $session_prop->getValue($checkout);

$session->set('signup', []);

$_POST['pre-flight'] = '1';
$_POST['email_address'] = 'pre-flight@example.com';
$_POST['checkout_action'] = 'wu_checkout';
$_POST['_wpnonce'] = 'nonce';

$method = $reflection->getMethod('persist_current_step_to_session');

if (PHP_VERSION_ID < 80100) {
$method->setAccessible(true);
}

$saved = $method->invoke($checkout);
$signup = $session->get('signup');

$this->assertArrayNotHasKey('pre-flight', $saved);
$this->assertArrayNotHasKey('checkout_action', $saved);
$this->assertArrayNotHasKey('_wpnonce', $saved);
$this->assertSame('pre-flight@example.com', $saved['email_address']);
$this->assertSame('pre-flight@example.com', $signup['pre_selected']['email_address']);

Comment on lines +632 to +640

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Map the test file and locate the relevant method.
ast-grep outline tests/WP_Ultimo/Checkout/Checkout_Test.php --view expanded

# Find the implementation that persists the current step to session.
rg -n "function persist_current_step_to_session|persist_current_step_to_session\(" tests/WP_Ultimo src lib includes wp-content -g '!vendor' -g '!node_modules' || true

Repository: Ultimate-Multisite/ultimate-multisite

Length of output: 17857


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Read the test method around the referenced lines.
sed -n '600,650p' tests/WP_Ultimo/Checkout/Checkout_Test.php

# Locate the implementation file and method body.
rg -n "function persist_current_step_to_session" .

# If the method is found, print a tight surrounding range.
# (The `awk` block handles the first matching file path from rg.)
path=$(rg -l "function persist_current_step_to_session" . | head -n 1)
if [ -n "${path:-}" ]; then
  echo "--- IMPLEMENTATION: $path ---"
  rg -n "persist_current_step_to_session|pre-flight|pre_selected|add_values\(" "$path"
  line=$(rg -n "function persist_current_step_to_session" "$path" | head -n 1 | cut -d: -f1)
  start=$((line - 20))
  [ "$start" -lt 1 ] && start=1
  end=$((line + 80))
  sed -n "${start},${end}p" "$path"
fi

Repository: Ultimate-Multisite/ultimate-multisite

Length of output: 4938


Assert the top-level signup write too. This test only checks signup['pre_selected']['email_address']; add an assertion for signup['email_address'] being present or absent so the pre-flight contract is pinned down.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/WP_Ultimo/Checkout/Checkout_Test.php` around lines 632 - 640, The
pre-flight test in Checkout_Test only asserts the nested pre_selected email, so
the top-level signup payload contract is not pinned down. Update the test around
the invoke($checkout) / get('signup') flow to also assert the presence or
absence of signup['email_address'] alongside
signup['pre_selected']['email_address'], using the existing $saved and $signup
assertions to make the expected write behavior explicit.

$session->set('signup', []);

unset(
$_POST['pre-flight'],
$_POST['email_address'],
$_POST['checkout_action'],
$_POST['_wpnonce']
);
}

// -------------------------------------------------------------------------
// Step navigation — is_first_step
// -------------------------------------------------------------------------
Expand Down
Loading