Files
jachty.pkmp.com.pl/test-yacht-plugin.php
Roman Pyrih 7483681901 first commit
2026-04-21 15:48:41 +02:00

179 lines
5.4 KiB
PHP

<?php
/**
* Test script for Yacht Booking System plugin
*
* Run this file in browser: http://jachty.pagedev.local/test-yacht-plugin.php
*/
// Load WordPress
require_once __DIR__ . '/wp-load.php';
// Check if user is admin
if (!current_user_can('manage_options')) {
die('You must be logged in as admin to run this test.');
}
echo '<h1>Yacht Booking System - Test Script</h1>';
// 1. Check if plugin file exists
$plugin_file = __DIR__ . '/wp-content/plugins/yacht-booking-system/yacht-booking-system.php';
echo '<h2>1. Plugin File Check</h2>';
if (file_exists($plugin_file)) {
echo '✅ Plugin file exists: ' . $plugin_file . '<br>';
} else {
echo '❌ Plugin file NOT found: ' . $plugin_file . '<br>';
die();
}
// 2. Check if plugin is active
echo '<h2>2. Plugin Activation Status</h2>';
$plugin_slug = 'yacht-booking-system/yacht-booking-system.php';
if (is_plugin_active($plugin_slug)) {
echo '✅ Plugin is ACTIVE<br>';
} else {
echo '⚠️ Plugin is NOT active. Attempting to activate...<br>';
// Try to activate
$result = activate_plugin($plugin_slug);
if (is_wp_error($result)) {
echo '❌ Activation failed: ' . $result->get_error_message() . '<br>';
} else {
echo '✅ Plugin activated successfully!<br>';
}
}
// 3. Check if custom table was created
echo '<h2>3. Database Table Check</h2>';
global $wpdb;
$table_name = $wpdb->prefix . 'yacht_availability';
$table_exists = $wpdb->get_var("SHOW TABLES LIKE '$table_name'") === $table_name;
if ($table_exists) {
echo '✅ Custom table exists: ' . $table_name . '<br>';
// Show table structure
$columns = $wpdb->get_results("DESCRIBE $table_name");
echo '<details><summary>Table structure</summary><pre>';
print_r($columns);
echo '</pre></details>';
} else {
echo '❌ Custom table NOT found: ' . $table_name . '<br>';
}
// 4. Check if CPTs are registered
echo '<h2>4. Custom Post Types Check</h2>';
if (post_type_exists('yacht')) {
echo '✅ "yacht" post type is registered<br>';
} else {
echo '❌ "yacht" post type NOT registered<br>';
}
if (post_type_exists('yacht_booking')) {
echo '✅ "yacht_booking" post type is registered<br>';
} else {
echo '❌ "yacht_booking" post type NOT registered<br>';
}
// 5. Check plugin options
echo '<h2>5. Plugin Options Check</h2>';
$version = get_option('yacht_booking_version');
if ($version) {
echo '✅ Plugin version: ' . $version . '<br>';
} else {
echo '⚠️ Plugin version option not set<br>';
}
$installed_at = get_option('yacht_booking_installed_at');
if ($installed_at) {
echo '✅ Installed at: ' . $installed_at . '<br>';
} else {
echo '⚠️ Installation date not set<br>';
}
// 6. Check custom capabilities
echo '<h2>6. Custom Capabilities Check</h2>';
$admin = get_role('administrator');
if ($admin) {
$caps = array(
'yacht_booking_manage_yachts',
'yacht_booking_manage_bookings',
'yacht_booking_manage_settings',
);
foreach ($caps as $cap) {
if ($admin->has_cap($cap)) {
echo '✅ Capability exists: ' . $cap . '<br>';
} else {
echo '❌ Capability NOT found: ' . $cap . '<br>';
}
}
}
// 7. Test REST API endpoints
echo '<h2>7. REST API Endpoints Check</h2>';
$rest_server = rest_get_server();
$namespaces = $rest_server->get_namespaces();
if (in_array('yacht-booking/v1', $namespaces)) {
echo '✅ REST API namespace registered: yacht-booking/v1<br>';
// List all routes
$routes = $rest_server->get_routes('yacht-booking/v1');
echo '<details><summary>Available routes (' . count($routes) . ')</summary><ul>';
foreach (array_keys($routes) as $route) {
echo '<li>' . $route . '</li>';
}
echo '</ul></details>';
} else {
echo '❌ REST API namespace NOT registered<br>';
}
// 8. Check if admin menu exists
echo '<h2>8. Admin Menu Check</h2>';
global $menu, $submenu;
$found = false;
foreach ($menu as $item) {
if ($item[2] === 'yacht-bookings') {
echo '✅ Admin menu item found: "' . $item[0] . '"<br>';
$found = true;
break;
}
}
if (!$found) {
echo '⚠️ Admin menu item NOT found (may be admin-only)<br>';
}
// 9. Test creating a test yacht
echo '<h2>9. Test Yacht Creation</h2>';
$test_yacht_id = wp_insert_post(array(
'post_type' => 'yacht',
'post_title' => 'Test Yacht - ' . time(),
'post_content' => 'This is a test yacht for verification',
'post_status' => 'publish',
));
if ($test_yacht_id && !is_wp_error($test_yacht_id)) {
echo '✅ Test yacht created successfully (ID: ' . $test_yacht_id . ')<br>';
// Add meta
update_post_meta($test_yacht_id, '_yacht_capacity', 8);
update_post_meta($test_yacht_id, '_yacht_price_per_day', 1500);
echo '✅ Meta data added (capacity: 8, price: 1500)<br>';
// Clean up
wp_delete_post($test_yacht_id, true);
echo '✅ Test yacht deleted (cleanup)<br>';
} else {
echo '❌ Failed to create test yacht<br>';
}
echo '<hr>';
echo '<h2>✅ Test Complete!</h2>';
echo '<p><strong>Next steps:</strong></p>';
echo '<ul>';
echo '<li>Visit <a href="' . admin_url('admin.php?page=yacht-bookings') . '">Yacht Bookings Admin Panel</a></li>';
echo '<li>Check <a href="' . admin_url('plugins.php') . '">Plugins page</a> to verify activation</li>';
echo '<li>Go to <a href="' . rest_url('yacht-booking/v1/yachts') . '">REST API: /yachts</a> (should return empty array)</li>';
echo '</ul>';