<?php
/**
 * Test script to verify API module works without license validation
 * Run this from the Perfex CRM root directory
 */

// Define necessary constants for testing
define('BASEPATH', true);
define('APPPATH', '../application/');
define('ENVIRONMENT', 'testing');

// Include the API module file
require_once 'modules/api/api.php';

// Test if the module loads without errors
echo "Testing API module license bypass...\n";

try {
    // Test the license validation function
    $result = modules\api\core\Apiinit::the_da_vinci_code('api');

    if ($result === true) {
        echo "✅ SUCCESS: License validation bypassed successfully!\n";
    } else {
        echo "❌ FAILED: License validation still active.\n";
    }

    // Test the pre_validate function
    $validate_result = modules\api\core\Apiinit::pre_validate('api', 'test-key');
    if ($validate_result['status'] === true) {
        echo "✅ SUCCESS: License pre-validation bypassed successfully!\n";
    } else {
        echo "❌ FAILED: License pre-validation still active.\n";
    }

    // Test the activate function (should not redirect)
    $module_mock = ['system_name' => 'api'];
    ob_start();
    modules\api\core\Apiinit::activate($module_mock);
    $output = ob_get_clean();

    if (empty($output)) {
        echo "✅ SUCCESS: Module activation bypassed successfully!\n";
        echo "✅ API module should now work without license restrictions.\n";
    } else {
        echo "❌ FAILED: Module activation still shows license screen.\n";
    }

} catch (Exception $e) {
    echo "❌ ERROR: " . $e->getMessage() . "\n";
}

echo "\nNext steps:\n";
echo "1. Clear any cached data in Perfex CRM\n";
echo "2. Test API endpoints to ensure they work\n";
echo "3. Check that no license warnings appear in admin area\n";
echo "\nNote: Remember to re-enable license validation for production use!\n";
?>