UrlTest.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace EasySwoole\Validate\tests;
  3. /**
  4. * 链接测试用例
  5. * Class UrlTest
  6. *
  7. * @internal
  8. */
  9. class UrlTest extends BaseTestCase
  10. {
  11. /*
  12. * 合法
  13. */
  14. public function testValidCase()
  15. {
  16. $this->freeValidate();
  17. $this->validate->addColumn('url')->url();
  18. $bool = $this->validate->validate(['url' => 'https://www.baidu.com']);
  19. $this->assertTrue($bool);
  20. }
  21. /*
  22. * 默认错误信息
  23. */
  24. public function testDefaultErrorMsgCase()
  25. {
  26. $this->freeValidate();
  27. $this->validate->addColumn('url')->url();
  28. $bool = $this->validate->validate(['url' => 'msg.com']);
  29. $this->assertFalse($bool);
  30. $this->assertEquals('url必须是合法的网址', $this->validate->getError()->__toString());
  31. }
  32. /*
  33. * 自定义错误信息
  34. */
  35. public function testCustomErrorMsgCase()
  36. {
  37. $this->freeValidate();
  38. $this->validate->addColumn('url')->url('链接无效');
  39. $bool = $this->validate->validate(['url' => 'msg.com']);
  40. $this->assertFalse($bool);
  41. $this->assertEquals('链接无效', $this->validate->getError()->__toString());
  42. }
  43. }