<?php
/**
 * Test script for bulk apply SEO functionality
 */

// Simulate AJAX request
$_SERVER['REQUEST_METHOD'] = 'POST';
$_POST['action'] = 'bulk_apply_seo';
$_POST['item_type'] = 'product';
$_POST['auto_generate'] = 'true';

// Set up session
session_start();
$_SESSION['admin_logged_in'] = true;

// Capture output
ob_start();

// Set up error handling
error_reporting(E_ALL);
ini_set('display_errors', 0);
ini_set('log_errors', 1);

// Include the main file
require_once 'admin_seo_manager.php';

$output = ob_get_clean();

// Parse and display JSON response
echo "Response:\n";
echo $output . "\n\n";

$decoded = json_decode($output, true);
if ($decoded) {
    echo "Parsed JSON:\n";
    echo "Success: " . ($decoded['success'] ? 'Yes' : 'No') . "\n";
    echo "Message: " . $decoded['message'] . "\n";
    if (isset($decoded['processed'])) {
        echo "Processed: " . $decoded['processed'] . " items\n";
    }
    if (isset($decoded['errors']) && count($decoded['errors']) > 0) {
        echo "Errors: " . count($decoded['errors']) . "\n";
        foreach ($decoded['errors'] as $error) {
            echo "  - " . $error . "\n";
        }
    }
} else {
    echo "Failed to parse JSON!\n";
    echo "Raw output: " . $output . "\n";
}
?>
