the beginning of the idiots
This commit is contained in:
		
							
								
								
									
										51
									
								
								qwen/php/tests/Utils/ValidatorTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								qwen/php/tests/Utils/ValidatorTest.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,51 @@
 | 
			
		||||
<?php
 | 
			
		||||
// tests/Utils/ValidatorTest.php
 | 
			
		||||
namespace Tests\Utils;
 | 
			
		||||
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use App\Utils\Validator;
 | 
			
		||||
 | 
			
		||||
class ValidatorTest extends TestCase
 | 
			
		||||
{
 | 
			
		||||
    public function testValidateEmail(): void
 | 
			
		||||
    {
 | 
			
		||||
        $this->assertTrue(Validator::validateEmail('test@example.com'));
 | 
			
		||||
        $this->assertFalse(Validator::validateEmail('invalid-email'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testValidateRequired(): void
 | 
			
		||||
    {
 | 
			
		||||
        $data = ['name' => 'John', 'email' => 'john@example.com'];
 | 
			
		||||
        $required = ['name', 'email'];
 | 
			
		||||
        
 | 
			
		||||
        $errors = Validator::validateRequired($data, $required);
 | 
			
		||||
        $this->assertEmpty($errors);
 | 
			
		||||
        
 | 
			
		||||
        $data = ['name' => 'John'];
 | 
			
		||||
        $errors = Validator::validateRequired($data, $required);
 | 
			
		||||
        $this->assertNotEmpty($errors);
 | 
			
		||||
        $this->assertContains('email is required', $errors);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testSanitizeString(): void
 | 
			
		||||
    {
 | 
			
		||||
        $input = '<script>alert("xss")</script>Hello World';
 | 
			
		||||
        $expected = '<script>alert("xss")</script>Hello World';
 | 
			
		||||
        
 | 
			
		||||
        $result = Validator::sanitizeString($input);
 | 
			
		||||
        $this->assertEquals($expected, $result);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testValidateUrl(): void
 | 
			
		||||
    {
 | 
			
		||||
        $this->assertTrue(Validator::validateUrl('https://example.com'));
 | 
			
		||||
        $this->assertFalse(Validator::validateUrl('not-a-url'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testValidateLength(): void
 | 
			
		||||
    {
 | 
			
		||||
        $this->assertTrue(Validator::validateLength('hello', 3, 10));
 | 
			
		||||
        $this->assertFalse(Validator::validateLength('hi', 3, 10));
 | 
			
		||||
        $this->assertFalse(Validator::validateLength('this string is too long', 3, 10));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user