| Server IP : 65.108.144.40 / Your IP : 216.73.217.165 Web Server : Apache/2.4.52 (Ubuntu) System : Linux ubuntu-8gb-hel1-1 5.15.0-173-generic #183-Ubuntu SMP Fri Mar 6 13:29:34 UTC 2026 x86_64 User : dev ( 1000) PHP Version : 8.2.30 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/html/project-slim/tests/ |
Upload File : |
<?php
/**
* Test Validation System
* This script tests the enhanced validation system we just implemented
*/
// Test data arrays for validation
$invalidRegisterData = [
'first_name' => 'A', // Too short
'last_name' => '', // Empty
'email' => 'invalid-email', // Invalid format
'password' => '123', // Too weak
'phone' => 'invalid-phone' // Invalid format
];
$validRegisterData = [
'first_name' => 'John',
'last_name' => 'Doe',
'email' => 'john.doe@example.com',
'password' => 'StrongPassword123!',
'phone' => '+1234567890'
];
$invalidCompanyData = [
'name' => 'A', // Too short
'email' => 'invalid-email',
'address' => '', // Empty required field
'city' => '', // Empty required field
'country' => '', // Empty required field
'industry' => 'invalid-industry' // Invalid industry
];
$validCompanyData = [
'name' => 'Acme Corporation',
'email' => 'contact@acme.com',
'address' => '123 Business Street',
'city' => 'New York',
'country' => 'United States',
'industry' => 'technology',
'company_size' => '51-200'
];
// Function to test API endpoint
function testEndpoint($url, $data, $method = 'POST') {
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_POSTFIELDS => json_encode($data),
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'Accept: application/json'
],
]);
$response = curl_exec($curl);
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$error = curl_error($curl);
curl_close($curl);
if ($error) {
return ['error' => $error, 'http_code' => 0];
}
return [
'http_code' => $httpCode,
'response' => json_decode($response, true),
'raw_response' => $response ?: ''
];
}
echo "๐งช Testing Enhanced Validation System\n";
echo str_repeat("=", 50) . "\n";
// Test 1: Invalid registration data
echo "\n๐ Test 1: Invalid Registration Data\n";
$result = testEndpoint('http://localhost:8080/api/v1/auth/register', $invalidRegisterData);
echo "HTTP Code: {$result['http_code']}\n";
if ($result['http_code'] == 400 || $result['http_code'] == 422) {
echo "โ
PASS: Validation correctly rejected invalid data\n";
if (isset($result['response']['errors'])) {
echo "๐ Validation Errors:\n";
foreach ($result['response']['errors'] as $field => $errors) {
echo " - {$field}: " . implode(', ', (array)$errors) . "\n";
}
}
} else {
echo "โ FAIL: Expected validation error (400/422), got {$result['http_code']}\n";
echo "Response: " . $result['raw_response'] . "\n";
}
// Test 2: Valid registration data
echo "\n๐ Test 2: Valid Registration Data\n";
$result = testEndpoint('http://localhost:8080/api/v1/auth/register', $validRegisterData);
echo "HTTP Code: {$result['http_code']}\n";
if ($result['http_code'] == 201 || $result['http_code'] == 200) {
echo "โ
PASS: Valid data accepted\n";
if (isset($result['response']['message'])) {
echo "๐ Response: {$result['response']['message']}\n";
}
} else {
echo "โ FAIL: Expected success (200/201), got {$result['http_code']}\n";
echo "Response: " . $result['raw_response'] . "\n";
}
// Test 3: Invalid login data
echo "\n๐ Test 3: Invalid Login Data\n";
$invalidLoginData = [
'email' => 'invalid-email',
'password' => ''
];
$result = testEndpoint('http://localhost:8080/api/v1/auth/login', $invalidLoginData);
echo "HTTP Code: {$result['http_code']}\n";
if ($result['http_code'] == 400 || $result['http_code'] == 422) {
echo "โ
PASS: Validation correctly rejected invalid login data\n";
if (isset($result['response']['errors'])) {
echo "๐ Validation Errors:\n";
foreach ($result['response']['errors'] as $field => $errors) {
echo " - {$field}: " . implode(', ', (array)$errors) . "\n";
}
}
} else {
echo "โ FAIL: Expected validation error (400/422), got {$result['http_code']}\n";
echo "Response: " . $result['raw_response'] . "\n";
}
// Test 4: Invalid company data
echo "\n๐ Test 4: Invalid Company Data\n";
$result = testEndpoint('http://localhost:8080/api/v1/companies', $invalidCompanyData);
echo "HTTP Code: {$result['http_code']}\n";
if ($result['http_code'] == 400 || $result['http_code'] == 422 || $result['http_code'] == 401) {
echo "โ
PASS: Request handled appropriately\n";
if (isset($result['response']['errors'])) {
echo "๐ Validation Errors:\n";
foreach ($result['response']['errors'] as $field => $errors) {
echo " - {$field}: " . implode(', ', (array)$errors) . "\n";
}
} elseif (isset($result['response']['message'])) {
echo "๐ Response: {$result['response']['message']}\n";
}
} else {
echo "โ FAIL: Unexpected response code {$result['http_code']}\n";
echo "Response: " . $result['raw_response'] . "\n";
}
// Test 5: Test validation-specific features
echo "\n๐ Test 5: Validation-Specific Features\n";
// Test strong password validation
$weakPasswordData = [
'first_name' => 'Test',
'last_name' => 'User',
'email' => 'test@example.com',
'password' => 'weak' // Should fail strong password validation
];
$result = testEndpoint('http://localhost:8080/api/v1/auth/register', $weakPasswordData);
echo "Weak Password Test - HTTP Code: {$result['http_code']}\n";
if ($result['http_code'] == 400 || $result['http_code'] == 422) {
echo "โ
PASS: Strong password validation working\n";
if (isset($result['response']['errors']['password'])) {
echo "๐ Password Error: " . implode(', ', (array)$result['response']['errors']['password']) . "\n";
}
} else {
echo "โ FAIL: Strong password validation not working\n";
echo "Response: " . $result['raw_response'] . "\n";
}
// Test phone validation
$invalidPhoneData = [
'first_name' => 'Test',
'last_name' => 'User',
'email' => 'test2@example.com',
'password' => 'StrongPassword123!',
'phone' => 'invalid-phone-number'
];
$result = testEndpoint('http://localhost:8080/api/v1/auth/register', $invalidPhoneData);
echo "Invalid Phone Test - HTTP Code: {$result['http_code']}\n";
if ($result['http_code'] == 400 || $result['http_code'] == 422) {
echo "โ
PASS: Phone validation working\n";
if (isset($result['response']['errors']['phone'])) {
echo "๐ Phone Error: " . implode(', ', (array)$result['response']['errors']['phone']) . "\n";
}
} else {
echo "โ FAIL: Phone validation not working\n";
echo "Response: " . $result['raw_response'] . "\n";
}
echo "\n" . str_repeat("=", 50) . "\n";
echo "๐ฏ Validation System Test Complete!\n";
echo "โจ Enhanced validation framework is now active with:\n";
echo " - BaseValidator with 20+ validation methods\n";
echo " - Enhanced AuthValidator with robust rules\n";
echo " - Enhanced UserValidator with comprehensive validation\n";
echo " - Enhanced CompanyValidator with industry validation\n";
echo " - Enhanced ReportValidator with date and format validation\n";
echo " - Field-specific error mapping\n";
echo " - Strong password requirements\n";
echo " - Phone number validation\n";
echo " - Fluent validation interface\n";
?>