ifnex/04_Laravel/test-api.php
Kazem Alghasi 4ee1d27d44 feat: Complete customer ordering system (Phase 3)
Laravel Backend:
- Add AuthController for Sanctum token login/logout
- Add CustomerOrderController with 6 endpoints
  (profile, countries, orders CRUD, cancel)
- Extend ShipmentStatus enum with pending_payment/cancelled
- Add SampleShippingRatesSeeder (10 zones, 3 service types)
- Zone-assign 232 countries (Gulf=1, Asia=2, EU=3, East=4, US=5)
- Add migration to extend shipments.status enum
- Add test-api.php automated test suite (5 tests)

WordPress Frontend:
- Add [ifnex_order_form] multi-step wizard (4 steps)
- Add [ifnex_orders_list] with status filter & cancel action
- Add [ifnex_user_profile] with wallet & stats
- Add ifnex-orders.css (RTL-ready, IFNEX theme)
- Add ifnex-order-form.js (step navigation + AJAX)
- Add AJAX handlers (countries, calculate, submit, cancel)
- Fix plugin asset paths with dirname(__FILE__)
2026-08-10 06:09:56 +03:30

136 lines
6.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
require __DIR__.'/vendor/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
$kernel->bootstrap();
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Hash;
use App\Models\User;
echo "══════════════════════════════════════════\n";
echo " 🧪 IFNEX API Test Suite\n";
echo "══════════════════════════════════════════\n\n";
// ─── 0. تنظیم رمز عبور برای تست ─────────────────────────────
$testEmail = 'kazem@vernasoft.group';
$testPassword = 'Test@12345';
$user = User::where('email', $testEmail)->first();
if (!$user) {
echo "❌ کاربر {$testEmail} پیدا نشد!\n";
exit(1);
}
$user->password = Hash::make($testPassword);
$user->save();
echo "✅ رمز کاربر {$user->name} به '{$testPassword}' تغییر یافت\n\n";
// ─── 1. تست Login ──────────────────────────────────────────
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n";
echo "تست ۱: دریافت توکن (Login)\n";
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n";
$response = Http::post('http://localhost:8000/api/v1/auth/login', [
'email' => $testEmail,
'password' => $testPassword,
'token_name' => 'test-api',
]);
echo "Status: " . $response->status() . "\n";
$data = $response->json();
print_r($data);
if ($response->status() !== 200 || !isset($data['token'])) {
echo "\n❌ Login ناموفق بود! بقیه تست‌ها را نمی‌توان انجام داد.\n";
exit(1);
}
$token = $data['token'];
echo "\n✅ Login موفق! توکن دریافت شد.\n\n";
// ─── 2. تست Profile ────────────────────────────────────────
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n";
echo "تست ۲: دریافت پروفایل\n";
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n";
$response2 = Http::withToken($token)
->get('http://localhost:8000/api/v1/customer/profile');
echo "Status: " . $response2->status() . "\n";
print_r($response2->json());
echo "\n";
// ─── 3. تست Countries ──────────────────────────────────────
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n";
echo "تست ۳: لیست کشورها\n";
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n";
$response3 = Http::withToken($token)
->get('http://localhost:8000/api/v1/customer/countries');
echo "Status: " . $response3->status() . "\n";
$countries = $response3->json();
echo "تعداد کشورها: " . (isset($countries['data']) ? count($countries['data']) : 0) . "\n";
if (isset($countries['data']) && count($countries['data']) > 0) {
echo "اولین کشور: " . print_r($countries['data'][0], true) . "\n";
}
echo "\n";
// ─── 4. تست ساخت سفارش ────────────────────────────────────
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n";
echo "تست ۴: ثبت سفارش جدید\n";
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n";
$orderData = [
'direction' => 'export',
'type' => 'PARCEL',
'from_country_id' => 1,
'to_country_id' => 2,
'weight' => 2.5,
'volumetric_weight' => 3,
'sender_name' => 'Kazem Test',
'sender_phone' => '09123456789',
'sender_address' => 'Tehran, Valiasr St.',
'sender_city' => 'Tehran',
'receiver_name' => 'Ali Customer',
'receiver_phone' => '+971501234567',
'receiver_address' => 'Dubai, Marina',
'receiver_city' => 'Dubai',
];
$response4 = Http::withToken($token)
->post('http://localhost:8000/api/v1/customer/orders', $orderData);
echo "Status: " . $response4->status() . "\n";
$orderResult = $response4->json();
print_r($orderResult);
echo "\n";
// ─── 5. تست لیست سفارشات ───────────────────────────────────
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n";
echo "تست ۵: لیست سفارشات کاربر\n";
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n";
$response5 = Http::withToken($token)
->get('http://localhost:8000/api/v1/customer/orders');
echo "Status: " . $response5->status() . "\n";
$orders = $response5->json();
echo "تعداد سفارشات: " . (isset($orders['data']) ? count($orders['data']) : 0) . "\n";
if (isset($orders['data']) && count($orders['data']) > 0) {
echo "اولین سفارش: AWB = " . ($orders['data'][0]['awb_no'] ?? '—') . "\n";
}
echo "\n";
// ─── جمع‌بندی ───────────────────────────────────────────────
echo "══════════════════════════════════════════\n";
echo " 🎯 نتیجه نهایی\n";
echo "══════════════════════════════════════════\n";
echo "Login: " . ($response->status() === 200 ? "" : "") . "\n";
echo "Profile: " . ($response2->status() === 200 ? "" : "") . "\n";
echo "Countries: " . ($response3->status() === 200 ? "" : "") . "\n";
echo "Create Order:" . ($response4->status() === 201 ? "" : "") . "\n";
echo "List Orders: " . ($response5->status() === 200 ? "" : "") . "\n";
echo "══════════════════════════════════════════\n";