1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- <?php
- namespace EasySwoole\Validate\tests;
- class ActiveUrlTest extends BaseTestCase
- {
-
- public function testValidCase()
- {
-
- $this->freeValidate();
- $this->validate->addColumn('url')->activeUrl();
- $validateResult = $this->validate->validate(['url' => 'http://baidu.com']);
- $this->assertTrue($validateResult);
- }
-
- public function testDefaultErrorMsgCase()
- {
-
- $this->freeValidate();
- $this->validate->addColumn('url', '网站')->activeUrl();
- $validateResult = $this->validate->validate(['url' => 'http://xxx.cn']);
- $this->assertFalse($validateResult);
- $this->assertEquals('网站必须是可访问的网址', $this->validate->getError()->__toString());
-
- $this->freeValidate();
- $this->validate->addColumn('url')->activeUrl();
- $validateResult = $this->validate->validate(['url' => 'this is not a url']);
- $this->assertFalse($validateResult);
- $this->assertEquals('url必须是可访问的网址', $this->validate->getError()->__toString());
- }
-
- public function testCustomErrorMsgCase()
- {
- $this->freeValidate();
- $this->validate->addColumn('url', '网站')->activeUrl('您输入的网址无效');
- $validateResult = $this->validate->validate(['url' => 'http://xxx.cn']);
- $this->assertFalse($validateResult);
- $this->assertEquals('您输入的网址无效', $this->validate->getError()->__toString());
- }
- }
|