This commit is contained in:
alorig
2025-11-22 19:46:34 +05:00
parent cbb6198214
commit 8296685fbd
34 changed files with 12200 additions and 1 deletions

View File

@@ -0,0 +1,163 @@
<?php
/**
* Test Site Structure Sync
*
* Run this test to verify site structure sync is working correctly
* Usage: wp eval-file tests/test-sync-structure.php
* Or: http://your-site.com/wp-admin/admin-ajax.php?action=igny8_test_structure_sync
*
* @package Igny8Bridge
*/
// Prevent direct access
if (!defined('ABSPATH')) {
exit;
}
echo "=== IGNY8 Site Structure Sync Test ===\n\n";
// Test 1: Check site ID
echo "Test 1: Checking Site ID...\n";
$site_id = get_option('igny8_site_id');
if ($site_id) {
echo "✅ Site ID found: $site_id\n";
} else {
echo "❌ Site ID not found. Run connection setup first.\n";
exit;
}
echo "\n";
// Test 2: Check authentication
echo "Test 2: Checking Authentication...\n";
$api = new Igny8API();
if ($api->is_authenticated()) {
echo "✅ API is authenticated\n";
} else {
echo "❌ API is not authenticated. Credentials missing.\n";
exit;
}
echo "\n";
// Test 3: Get site structure
echo "Test 3: Gathering Site Structure...\n";
$structure = igny8_get_site_structure();
echo " Post Types Found: " . count($structure['post_types']) . "\n";
foreach ($structure['post_types'] as $type => $data) {
echo " - $type: {$data['label']} ({$data['count']} items)\n";
}
echo "\n Taxonomies Found: " . count($structure['taxonomies']) . "\n";
foreach ($structure['taxonomies'] as $tax => $data) {
echo " - $tax: {$data['label']} ({$data['count']} items)\n";
}
if (empty($structure['post_types']) && empty($structure['taxonomies'])) {
echo "❌ No content found to sync\n";
exit;
}
echo "✅ Site structure gathered successfully\n";
echo "\n";
// Test 4: Query for integration
echo "Test 4: Querying for Integration...\n";
$query_response = $api->get('/v1/integration/integrations/?site=' . $site_id . '&platform=wordpress');
echo " API Response Status: " . ($query_response['success'] ? 'Success' : 'Failed') . "\n";
echo " HTTP Status: " . (isset($query_response['http_status']) ? $query_response['http_status'] : 'N/A') . "\n";
// Extract integration
$integration = null;
if (isset($query_response['data'])) {
$data = $query_response['data'];
if (isset($data['results']) && !empty($data['results'])) {
$integration = $data['results'][0];
echo " Response Format: Paginated (DRF)\n";
} elseif (is_array($data) && isset($data[0])) {
$integration = $data[0];
echo " Response Format: Direct Array\n";
} elseif (is_array($data) && isset($data['id'])) {
$integration = $data;
echo " Response Format: Single Object\n";
}
}
if (!$integration || empty($integration['id'])) {
echo "❌ No integration found\n";
if (isset($query_response['error'])) {
echo " Error: " . $query_response['error'] . "\n";
}
exit;
}
echo "✅ Integration found: ID {$integration['id']}\n";
echo "\n";
// Test 5: Sync structure to backend
echo "Test 5: Syncing Structure to Backend...\n";
$payload = array(
'post_types' => $structure['post_types'],
'taxonomies' => $structure['taxonomies'],
'timestamp' => $structure['timestamp'],
'plugin_connection_enabled' => (bool) igny8_is_connection_enabled(),
'two_way_sync_enabled' => (bool) get_option('igny8_enable_two_way_sync', 1),
);
$endpoint = '/v1/integration/integrations/' . $integration['id'] . '/update-structure/';
echo " Endpoint: $endpoint\n";
echo " Payload Size: " . strlen(json_encode($payload)) . " bytes\n";
$sync_response = $api->post($endpoint, $payload);
echo " API Response Status: " . ($sync_response['success'] ? 'Success' : 'Failed') . "\n";
echo " HTTP Status: " . (isset($sync_response['http_status']) ? $sync_response['http_status'] : 'N/A') . "\n";
if ($sync_response['success']) {
echo "✅ Structure synced successfully\n";
if (isset($sync_response['data']['message'])) {
echo " Message: " . $sync_response['data']['message'] . "\n";
}
if (isset($sync_response['data']['post_types_count'])) {
echo " Post Types Synced: " . $sync_response['data']['post_types_count'] . "\n";
}
if (isset($sync_response['data']['taxonomies_count'])) {
echo " Taxonomies Synced: " . $sync_response['data']['taxonomies_count'] . "\n";
}
} else {
echo "❌ Structure sync failed\n";
if (isset($sync_response['error'])) {
echo " Error: " . $sync_response['error'] . "\n";
}
if (isset($sync_response['raw_error'])) {
echo " Details: " . json_encode($sync_response['raw_error']) . "\n";
}
exit;
}
echo "\n";
// Test 6: Verify backend stored the data
echo "Test 6: Verifying Backend Stored Data...\n";
$verify_response = $api->get('/v1/integration/integrations/' . $integration['id'] . '/content-types/');
if ($verify_response['success'] && isset($verify_response['data'])) {
$data = $verify_response['data'];
echo " Post Types in Backend: " . count($data['post_types'] ?? []) . "\n";
echo " Taxonomies in Backend: " . count($data['taxonomies'] ?? []) . "\n";
echo " Last Structure Fetch: " . ($data['last_structure_fetch'] ?? 'Unknown') . "\n";
echo "✅ Backend data verified\n";
} else {
echo "⚠️ Could not verify backend data\n";
if (isset($verify_response['error'])) {
echo " Error: " . $verify_response['error'] . "\n";
}
}
echo "\n";
echo "=== Test Complete ===\n";
echo "✅ All tests passed! Site structure sync is working.\n\n";