ferrero-opentext/test_search.php
DJP 633c5a525e Fix workflow V3: metadata display and download error handling
Fixes:
- Metadata button now works (fixed JavaScript and element IDs)
- Display full metadata as JSON when clicked
- Detect and show proper error when files don't exist in storage
- Show detailed download error messages (HTTP 500, file not found)
- Display download success/failure with file size and path
- Use old working Postman collection with OAuth2 configured
- Update StatusManager to use working search pattern + status filter

Changes:
- Switch to Content Scaling Flow.postman_collection_Oliver(New).json
- Fix downloadAsset to detect JSON error responses
- Improve metadata display with toggle functionality
- Show clear error messages for missing files in DAM storage

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-17 15:13:01 -04:00

203 lines
7.2 KiB
PHP

<?php
session_start();
require_once 'config_v3.php';
require_once 'src/TestRunner.php';
$configV3 = new ConfigV3();
$config = [
'baseUrl' => $configV3->getBaseUrl(),
'timeout' => $configV3->get('api.timeout'),
'headers' => [
'Content-Type' => 'application/json',
'Accept' => 'application/json'
]
];
$collectionPath = __DIR__ . '/' . $configV3->get('postman_collection');
$testRunner = new TestRunner($collectionPath, $config);
$result = null;
$error = null;
if ($_GET['action'] === 'test') {
try {
$requests = $testRunner->getAvailableRequests();
echo "<h2>Available Requests in Collection:</h2><ul>";
foreach ($requests as $index => $request) {
echo "<li><strong>[$index]</strong> " . htmlspecialchars($request['name']) . "</li>";
}
echo "</ul>";
// Find and run the localized campaign request
foreach ($requests as $index => $request) {
if (strpos($request['name'], 'Retrieve Localized Campaign') !== false) {
echo "<h2>Running: " . htmlspecialchars($request['name']) . "</h2>";
// Get the original URL
$url = is_array($request['request']['url']) ? $request['request']['url']['raw'] : $request['request']['url'];
echo "<h3>Original URL:</h3><pre>" . htmlspecialchars($url) . "</pre>";
// Replace {{baseUrl}} with actual base URL
$url = str_replace('{{baseUrl}}', $configV3->getBaseUrl(), $url);
echo "<h3>After baseUrl replacement:</h3><pre>" . htmlspecialchars($url) . "</pre>";
// Modify the request
$modifiedRequest = $request;
if (is_array($modifiedRequest['request']['url'])) {
$modifiedRequest['request']['url']['raw'] = $url;
} else {
$modifiedRequest['request']['url'] = $url;
}
// Run the test
$result = $testRunner->runSingleTest($modifiedRequest, $index);
echo "<h3>Result Status:</h3><pre>" . htmlspecialchars($result['status']) . "</pre>";
echo "<h3>HTTP Code:</h3><pre>" . htmlspecialchars($result['response']['http_code'] ?? 'N/A') . "</pre>";
if (isset($result['response']['error'])) {
echo "<h3 style='color: red;'>Error:</h3><pre>" . htmlspecialchars($result['response']['error']) . "</pre>";
}
if (isset($result['response']['body'])) {
$body = $result['response']['body'];
$data = json_decode($body, true);
echo "<h3>Response Body (JSON decoded):</h3>";
if ($data) {
echo "<h4>Top-level keys:</h4><ul>";
foreach (array_keys($data) as $key) {
echo "<li>" . htmlspecialchars($key) . "</li>";
}
echo "</ul>";
if (isset($data['asset_list'])) {
echo "<h4>Asset List:</h4>";
if (isset($data['asset_list']['asset'])) {
$count = count($data['asset_list']['asset']);
echo "<p><strong>Found $count assets</strong></p>";
} else {
echo "<pre>" . htmlspecialchars(print_r($data['asset_list'], true)) . "</pre>";
}
}
echo "<details><summary>Full Response JSON (click to expand)</summary>";
echo "<pre style='max-height: 500px; overflow-y: auto;'>" . htmlspecialchars(json_encode($data, JSON_PRETTY_PRINT)) . "</pre>";
echo "</details>";
} else {
echo "<h4>Raw response body:</h4>";
echo "<pre style='max-height: 500px; overflow-y: auto;'>" . htmlspecialchars(substr($body, 0, 5000)) . "</pre>";
}
}
break;
}
}
} catch (Exception $e) {
$error = $e->getMessage();
}
}
$oauth2Status = $testRunner->getOAuth2Status();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Test Search API</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
padding: 20px;
background: #f5f5f5;
}
.container {
max-width: 1400px;
margin: 0 auto;
background: white;
padding: 30px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
.alert {
padding: 15px;
border-radius: 6px;
margin: 15px 0;
}
.alert-success { background: #d4edda; color: #155724; }
.alert-error { background: #f8d7da; color: #721c24; }
.btn {
padding: 12px 24px;
background: #667eea;
color: white;
border: none;
border-radius: 6px;
cursor: pointer;
font-size: 14px;
font-weight: 500;
text-decoration: none;
display: inline-block;
}
.btn:hover { background: #5568d3; }
pre {
background: #f8f9fa;
padding: 15px;
border-radius: 6px;
overflow-x: auto;
}
details {
margin: 15px 0;
padding: 15px;
background: #f8f9fa;
border-radius: 6px;
}
summary {
cursor: pointer;
font-weight: 600;
padding: 10px;
}
summary:hover {
background: #e9ecef;
border-radius: 4px;
}
</style>
</head>
<body>
<div class="container">
<h1>🔍 Test Search API</h1>
<p style="color: #666;">Test the Retrieve Localized Campaign request from Postman collection</p>
<?php if ($oauth2Status && $oauth2Status['enabled']): ?>
<div class="alert alert-<?= ($oauth2Status['has_token'] ?? false) ? 'success' : 'error' ?>">
<?= ($oauth2Status['has_token'] ?? false) ? '✅ OAuth2 Token Active' : '❌ OAuth2 Token Issue' ?>
<?php if (isset($oauth2Status['expires_at'])): ?>
- Expires: <?= htmlspecialchars($oauth2Status['expires_at']) ?>
<?php endif; ?>
</div>
<?php endif; ?>
<?php if ($error): ?>
<div class="alert alert-error">
<strong>Error:</strong> <?= htmlspecialchars($error) ?>
</div>
<?php endif; ?>
<a href="?action=test" class="btn">🚀 Run Test Search</a>
<hr style="margin: 30px 0;">
<?php if (isset($_GET['action'])): ?>
<!-- Results will be displayed above -->
<?php else: ?>
<div class="alert alert-success">
Click the button above to run the test search and see detailed output
</div>
<?php endif; ?>
</div>
</body>
</html>