403Webshell
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 :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/project-slim/tests/test_validation_direct.php
<?php

/**
 * Direct Validation System Test
 * Tests the enhanced validation classes directly without API calls
 */

require_once __DIR__ . '/../vendor/autoload.php';

// Import the validators
use App\Validators\AuthValidator;
use App\Validators\UserValidator;
use App\Validators\CompanyValidator;
use App\Validators\ReportValidator;
use App\Exceptions\ValidationException;

echo "๐Ÿงช Direct Validation System Test\n";
echo str_repeat("=", 50) . "\n";

// Test 1: AuthValidator - Invalid Registration
echo "\n๐Ÿ“ Test 1: AuthValidator - Invalid Registration Data\n";
try {
    $authValidator = new AuthValidator();
    $invalidData = [
        'first_name' => 'A',  // Too short
        'last_name' => '',    // Empty
        'email' => 'invalid-email',  // Invalid format
        'password' => '123',  // Too weak
        'phone' => 'invalid-phone'  // Invalid format
    ];
    $authValidator->validateRegister($invalidData);
    echo "โŒ FAIL: Should have thrown ValidationException\n";
} catch (ValidationException $e) {
    echo "โœ… PASS: Validation correctly rejected invalid data\n";
    $errors = $e->getErrors();
    echo "๐Ÿ“‹ Validation Errors:\n";
    foreach ($errors as $field => $fieldErrors) {
        echo "  - {$field}: " . implode(', ', (array)$fieldErrors) . "\n";
    }
} catch (Exception $e) {
    echo "โŒ FAIL: Unexpected error: " . $e->getMessage() . "\n";
}

// Test 2: AuthValidator - Valid Registration
echo "\n๐Ÿ“ Test 2: AuthValidator - Valid Registration Data\n";
try {
    $authValidator = new AuthValidator();
    $validData = [
        'first_name' => 'John',
        'last_name' => 'Doe',
        'email' => 'john.doe@example.com',
        'password' => 'StrongPassword123!',
        'phone' => '+1234567890'
    ];
    $authValidator->validateRegister($validData);
    echo "โœ… PASS: Valid registration data accepted\n";
} catch (ValidationException $e) {
    echo "โŒ FAIL: Valid data was rejected\n";
    $errors = $e->getErrors();
    foreach ($errors as $field => $fieldErrors) {
        echo "  - {$field}: " . implode(', ', (array)$fieldErrors) . "\n";
    }
} catch (Exception $e) {
    echo "โŒ FAIL: Unexpected error: " . $e->getMessage() . "\n";
}

// Test 3: AuthValidator - Strong Password Validation
echo "\n๐Ÿ“ Test 3: AuthValidator - Strong Password Validation\n";
$weakPasswords = [
    'weak' => 'weak',
    'nouppercase123!' => 'nouppercase123!',
    'NOLOWERCASE123!' => 'NOLOWERCASE123!',
    'NoNumbers!' => 'NoNumbers!',
    'NoSpecialChars123' => 'NoSpecialChars123',
    'Short1!' => 'Short1!'
];

foreach ($weakPasswords as $description => $password) {
    try {
        $authValidator = new AuthValidator();
        $data = [
            'first_name' => 'Test',
            'last_name' => 'User',
            'email' => 'test@example.com',
            'password' => $password
        ];
        $authValidator->validateRegister($data);
        echo "โŒ FAIL: Weak password '{$description}' was accepted\n";
    } catch (ValidationException $e) {
        echo "โœ… PASS: Weak password '{$description}' correctly rejected\n";
    }
}

// Test 4: UserValidator - User Creation
echo "\n๐Ÿ“ Test 4: UserValidator - User Creation\n";
try {
    $userValidator = new UserValidator();
    $invalidUserData = [
        'first_name' => 'A',  // Too short
        'email' => 'invalid-email',
        'password' => 'weak',
        'role' => 'invalid-role'
    ];
    $userValidator->validateCreate($invalidUserData);
    echo "โŒ FAIL: Should have thrown ValidationException\n";
} catch (ValidationException $e) {
    echo "โœ… PASS: User validation correctly rejected invalid data\n";
    $errors = $e->getErrors();
    echo "๐Ÿ“‹ User Validation Errors:\n";
    foreach ($errors as $field => $fieldErrors) {
        echo "  - {$field}: " . implode(', ', (array)$fieldErrors) . "\n";
    }
}

// Test 5: CompanyValidator - Company Creation
echo "\n๐Ÿ“ Test 5: CompanyValidator - Company Creation\n";
try {
    $companyValidator = new CompanyValidator();
    $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
    ];
    $companyValidator->validateCreate($invalidCompanyData);
    echo "โŒ FAIL: Should have thrown ValidationException\n";
} catch (ValidationException $e) {
    echo "โœ… PASS: Company validation correctly rejected invalid data\n";
    $errors = $e->getErrors();
    echo "๐Ÿ“‹ Company Validation Errors:\n";
    foreach ($errors as $field => $fieldErrors) {
        echo "  - {$field}: " . implode(', ', (array)$fieldErrors) . "\n";
    }
}

// Test 6: CompanyValidator - Valid Company Data
echo "\n๐Ÿ“ Test 6: CompanyValidator - Valid Company Data\n";
try {
    $companyValidator = new CompanyValidator();
    $validCompanyData = [
        'name' => 'Acme Corporation',
        'email' => 'contact@acme.com',
        'address' => '123 Business Street',
        'city' => 'New York',
        'country' => 'United States',
        'industry' => 'technology',
        'company_size' => '51-200'
    ];
    $companyValidator->validateCreate($validCompanyData);
    echo "โœ… PASS: Valid company data accepted\n";
} catch (ValidationException $e) {
    echo "โŒ FAIL: Valid company data was rejected\n";
    $errors = $e->getErrors();
    foreach ($errors as $field => $fieldErrors) {
        echo "  - {$field}: " . implode(', ', (array)$fieldErrors) . "\n";
    }
}

// Test 7: ReportValidator - Report Generation
echo "\n๐Ÿ“ Test 7: ReportValidator - Report Generation\n";
try {
    $reportValidator = new ReportValidator();
    $invalidReportData = [
        'type' => 'invalid-type',
        'company_id' => 'not-a-number',
        'date_from' => 'invalid-date',
        'date_to' => '2023-01-01',  // Before date_from
        'format' => 'invalid-format'
    ];
    // Set date_from to a date after date_to to test date range validation
    $invalidReportData['date_from'] = '2023-12-31';
    
    $reportValidator->validateGenerate($invalidReportData);
    echo "โŒ FAIL: Should have thrown ValidationException\n";
} catch (ValidationException $e) {
    echo "โœ… PASS: Report validation correctly rejected invalid data\n";
    $errors = $e->getErrors();
    echo "๐Ÿ“‹ Report Validation Errors:\n";
    foreach ($errors as $field => $fieldErrors) {
        echo "  - {$field}: " . implode(', ', (array)$fieldErrors) . "\n";
    }
}

// Test 8: BaseValidator Features Test
echo "\n๐Ÿ“ Test 8: BaseValidator Features Test\n";
try {
    $authValidator = new AuthValidator();
    
    // Test email validation
    $emailTestData = [
        'first_name' => 'Test',
        'last_name' => 'User',
        'email' => 'not-an-email',
        'password' => 'StrongPassword123!'
    ];
    $authValidator->validateRegister($emailTestData);
    echo "โŒ FAIL: Invalid email should be rejected\n";
} catch (ValidationException $e) {
    $errors = $e->getErrors();
    if (isset($errors['email'])) {
        echo "โœ… PASS: Email validation working\n";
    } else {
        echo "โŒ FAIL: Email validation error not found\n";
    }
}

// Test 9: Phone Number Validation
echo "\n๐Ÿ“ Test 9: Phone Number Validation\n";
$invalidPhones = [
    '123',
    'abc-def-ghij',
    '1234567890123456789',  // Too long
    '+',
    '++123456789'
];

foreach ($invalidPhones as $phone) {
    try {
        $authValidator = new AuthValidator();
        $data = [
            'first_name' => 'Test',
            'last_name' => 'User',
            'email' => 'test@example.com',
            'password' => 'StrongPassword123!',
            'phone' => $phone
        ];
        $authValidator->validateRegister($data);
        echo "โŒ FAIL: Invalid phone '{$phone}' was accepted\n";
    } catch (ValidationException $e) {
        echo "โœ… PASS: Invalid phone '{$phone}' correctly rejected\n";
    }
}

// Test 10: ValidationException getErrors() method
echo "\n๐Ÿ“ Test 10: ValidationException getErrors() Method\n";
try {
    $authValidator = new AuthValidator();
    $data = [
        'email' => 'invalid',
        'password' => ''
    ];
    $authValidator->validateLogin($data);
} catch (ValidationException $e) {
    $errors = $e->getErrors();
    if (is_array($errors) && !empty($errors)) {
        echo "โœ… PASS: getErrors() method returns proper array\n";
        echo "๐Ÿ“‹ Error structure:\n";
        foreach ($errors as $field => $fieldErrors) {
            echo "  - {$field}: " . (is_array($fieldErrors) ? implode(', ', $fieldErrors) : $fieldErrors) . "\n";
        }
    } else {
        echo "โŒ FAIL: getErrors() method not working properly\n";
    }
}

echo "\n" . str_repeat("=", 50) . "\n";
echo "๐ŸŽฏ Direct Validation Test Complete!\n";
echo "โœจ Enhanced validation framework is working with:\n";
echo "   โœ… BaseValidator with fluent interface\n";
echo "   โœ… Strong password validation\n";
echo "   โœ… Email validation\n";
echo "   โœ… Phone number validation\n";
echo "   โœ… Field-specific error mapping\n";
echo "   โœ… Required field validation\n";
echo "   โœ… Data type validation (integer, boolean, etc.)\n";
echo "   โœ… Length validation (min/max)\n";
echo "   โœ… Range validation\n";
echo "   โœ… Date validation and range checking\n";
echo "   โœ… ValidationException with getErrors() method\n";

?>

Youez - 2016 - github.com/yon3zu
LinuXploit