mirror of
				https://github.com/elyby/yii2-tempmail-validator.git
				synced 2025-05-31 14:11:55 +05:30 
			
		
		
		
	chore: bump daves-email-validation-tool from 0.1.5 to 1.2.0 (#1)
This commit is contained in:
		
							
								
								
									
										64
									
								
								tests/Ely/Yii2/TempmailValidatorTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										64
									
								
								tests/Ely/Yii2/TempmailValidatorTest.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,64 @@ | ||||
| <?php | ||||
| namespace Ely\Yii2; | ||||
|  | ||||
| include __DIR__ . '/../../../vendor/yiisoft/yii2/Yii.php'; | ||||
|  | ||||
| use PHPUnit\Framework\TestCase; | ||||
| use yii\base\Model; | ||||
| use yii\console\Application; | ||||
|  | ||||
| class TempmailValidatorTest extends TestCase | ||||
| { | ||||
|     protected function setUp(): void | ||||
|     { | ||||
|         parent::setUp(); | ||||
|         new Application([ | ||||
|             'id' => 'testapp', | ||||
|             'basePath' => __DIR__, | ||||
|             'vendorPath' => __DIR__ . '/../../../vendor', | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|     public function testValidateValue() | ||||
|     { | ||||
|         $validator = new TempmailValidator(); | ||||
|         $this->assertTrue($validator->validate('team@ely.by')); | ||||
|         $this->assertFalse($validator->validate('h4l29@spam4.me', $error)); | ||||
|         $this->assertSame('the input value is not allowed email address.', $error); | ||||
|     } | ||||
|  | ||||
|     public function testValidatorOnModel() | ||||
|     { | ||||
|         $model = $this->createDummyModel(); | ||||
|         $model->email = 'team@ely.by'; | ||||
|         $this->assertTrue($model->validate()); | ||||
|  | ||||
|         $model = $this->createDummyModel(); | ||||
|         $model->email = 'spam@spam4.me'; | ||||
|         $this->assertFalse($model->validate()); | ||||
|         $this->assertSame('Email is not allowed email address.', $model->getFirstError('email')); | ||||
|  | ||||
|         $model = $this->createDummyModel('{attribute} with custom message.'); | ||||
|         $model->email = 'spam@spam4.me'; | ||||
|         $this->assertFalse($model->validate()); | ||||
|         $this->assertSame('Email with custom message.', $model->getFirstError('email')); | ||||
|     } | ||||
|  | ||||
|     private function createDummyModel(string $customMessage = null): Model | ||||
|     { | ||||
|         return new class(['customMessage' => $customMessage]) extends Model | ||||
|         { | ||||
|             public $email; | ||||
|  | ||||
|             public $customMessage; | ||||
|  | ||||
|             public function rules(): array | ||||
|             { | ||||
|                 return [ | ||||
|                     [['email'], TempmailValidator::class, 'message' => $this->customMessage], | ||||
|                 ]; | ||||
|             } | ||||
|         }; | ||||
|     } | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user