|
5 | 5 | use Exception; |
6 | 6 | use Kirby\Cms\App; |
7 | 7 | use Kirby\Content\Field; |
| 8 | +use Kirby\Data\Data; |
8 | 9 | use Kirby\Exception\InvalidArgumentException; |
9 | 10 | use Kirby\TestCase; |
10 | 11 | use PHPUnit\Framework\Attributes\CoversClass; |
@@ -675,98 +676,15 @@ public function testUuid(): void |
675 | 676 |
|
676 | 677 | public function testUrl(): void |
677 | 678 | { |
678 | | - // based on https://mathiasbynens.be/demo/url-regex |
679 | | - $this->assertTrue(V::url('http://www.getkirby.com')); |
680 | | - $this->assertTrue(V::url('http://www.getkirby.com/docs/param:value/?foo=bar/#anchor')); |
681 | | - $this->assertTrue(V::url('https://www.getkirby.de.vu')); |
682 | | - $this->assertTrue(V::url('https://getkirby.com:1234')); |
683 | | - $this->assertTrue(V::url('https://getkirby.com:1234/test')); |
684 | | - $this->assertTrue(V::url('http://foo.com/blah_blah')); |
685 | | - $this->assertTrue(V::url('http://foo.com/blah_blah/')); |
686 | | - $this->assertTrue(V::url('http://foo.com/blah_blah_(wikipedia)')); |
687 | | - $this->assertTrue(V::url('http://foo.com/blah_blah_(wikipedia)_(again)')); |
688 | | - $this->assertTrue(V::url('http://www.example.com/wpstyle/?p=364')); |
689 | | - $this->assertTrue(V::url('https://www.example.com/foo/?bar=baz&inga=42&quux')); |
690 | | - $this->assertTrue(V::url('http://✪df.ws/123')); |
691 | | - $this->assertTrue(V::url('http://userid:password@example.com:8080')); |
692 | | - $this->assertTrue(V::url('http://userid:password@example.com:8080/')); |
693 | | - $this->assertTrue(V::url('http://userid@example.com')); |
694 | | - $this->assertTrue(V::url('http://userid@example.com/')); |
695 | | - $this->assertTrue(V::url('http://userid@example.com:8080')); |
696 | | - $this->assertTrue(V::url('http://userid@example.com:8080/')); |
697 | | - $this->assertTrue(V::url('http://userid:password@example.com')); |
698 | | - $this->assertTrue(V::url('http://userid:password@example.com/')); |
699 | | - $this->assertTrue(V::url('http://142.42.1.1/')); |
700 | | - $this->assertTrue(V::url('http://142.42.1.1:8080/')); |
701 | | - $this->assertTrue(V::url('http://➡.ws/䨹')); |
702 | | - $this->assertTrue(V::url('http://⌘.ws')); |
703 | | - $this->assertTrue(V::url('http://⌘.ws/')); |
704 | | - $this->assertTrue(V::url('http://foo.com/blah_(wikipedia)#cite-1')); |
705 | | - $this->assertTrue(V::url('http://foo.com/blah_(wikipedia)_blah#cite-1')); |
706 | | - $this->assertTrue(V::url('http://foo.com/unicode_(✪)_in_parens')); |
707 | | - $this->assertTrue(V::url('http://foo.com/(something)?after=parens')); |
708 | | - $this->assertTrue(V::url('http://☺.damowmow.com/')); |
709 | | - $this->assertTrue(V::url('http://code.google.com/events/#&product=browser')); |
710 | | - $this->assertTrue(V::url('http://j.mp')); |
711 | | - $this->assertTrue(V::url('ftp://foo.bar/baz')); |
712 | | - $this->assertTrue(V::url('http://foo.bar/?q=Test%20URL-encoded%20stuff')); |
713 | | - $this->assertTrue(V::url('http://مثال.إختبار')); |
714 | | - $this->assertTrue(V::url('http://例子.测试')); |
715 | | - $this->assertTrue(V::url('http://उदाहरण.परीक्षा')); |
716 | | - $this->assertTrue(V::url("http://-.~_!$&'()*+,;=:%40:80%2f::::::@example.com")); |
717 | | - $this->assertTrue(V::url('http://1337.net')); |
718 | | - $this->assertTrue(V::url('http://a.b-c.de')); |
719 | | - $this->assertTrue(V::url('http://223.255.255.254')); |
720 | | - $this->assertTrue(V::url('http://localhost/test/')); |
721 | | - $this->assertTrue(V::url('http://localhost:8080/test')); |
722 | | - $this->assertTrue(V::url('http://127.0.0.1/kirby/')); |
723 | | - $this->assertTrue(V::url('http://127.0.0.1:8080/kirby')); |
724 | | - $this->assertTrue(V::url('https://127.0.0.1/kirby/panel/pages/blog+vvvv')); |
725 | | - $this->assertTrue(V::url('https://localhost/kirby/panel/pages/blog+vvvv')); |
726 | | - |
727 | | - // TODO: Find better regex to also cover the following |
728 | | - // $this->assertTrue(V::url('http://special---offer.com/')); |
729 | | - // $this->assertTrue(V::url('http://10.1.1.1')); |
730 | | - // $this->assertTrue(V::url('http://10.1.1.254')); |
731 | | - |
732 | | - $this->assertFalse(V::url('foo')); |
733 | | - $this->assertFalse(V::url('http://')); |
734 | | - $this->assertFalse(V::url('http://.')); |
735 | | - $this->assertFalse(V::url('http://..')); |
736 | | - $this->assertFalse(V::url('http://../')); |
737 | | - $this->assertFalse(V::url('http://?')); |
738 | | - $this->assertFalse(V::url('http://??')); |
739 | | - $this->assertFalse(V::url('http://??/')); |
740 | | - $this->assertFalse(V::url('http://#')); |
741 | | - $this->assertFalse(V::url('http://##')); |
742 | | - $this->assertFalse(V::url('http://##/')); |
743 | | - $this->assertFalse(V::url('http://foo.bar?q=Spaces should be encoded')); |
744 | | - $this->assertFalse(V::url('//')); |
745 | | - $this->assertFalse(V::url('//a')); |
746 | | - $this->assertFalse(V::url('///a')); |
747 | | - $this->assertFalse(V::url('///')); |
748 | | - $this->assertFalse(V::url('http:///a')); |
749 | | - $this->assertFalse(V::url('foo.com')); |
750 | | - $this->assertFalse(V::url('rdar://1234')); |
751 | | - $this->assertFalse(V::url('h://test')); |
752 | | - $this->assertFalse(V::url('http:// shouldfail.com')); |
753 | | - $this->assertFalse(V::url(':// should fail')); |
754 | | - $this->assertFalse(V::url('http://foo.bar/foo(bar)baz quux')); |
755 | | - $this->assertFalse(V::url('ftps://foo.bar/')); |
756 | | - $this->assertFalse(V::url('http://-error-.invalid/')); |
757 | | - $this->assertFalse(V::url('http://a.b--c.de/')); |
758 | | - $this->assertFalse(V::url('http://-a.b.co')); |
759 | | - $this->assertFalse(V::url('http://a.b-.co')); |
760 | | - $this->assertFalse(V::url('http://0.0.0.0')); |
761 | | - $this->assertFalse(V::url('http://10.1.1.0')); |
762 | | - $this->assertFalse(V::url('http://10.1.1.255')); |
763 | | - $this->assertFalse(V::url('http://224.1.1.1')); |
764 | | - $this->assertFalse(V::url('http://1.1.1.1.1')); |
765 | | - $this->assertFalse(V::url('http://123.123.123')); |
766 | | - $this->assertFalse(V::url('http://3628126748')); |
767 | | - $this->assertFalse(V::url('http://.www.foo.bar/')); |
768 | | - $this->assertFalse(V::url('http://www.foo.bar./')); |
769 | | - $this->assertFalse(V::url('http://.www.foo.bar./')); |
| 679 | + $urls = Data::read(__DIR__ . '/fixtures/urls.json'); |
| 680 | + |
| 681 | + foreach ($urls['valid'] as $url) { |
| 682 | + $this->assertTrue(V::url($url), "Expected valid: $url"); |
| 683 | + } |
| 684 | + |
| 685 | + foreach ($urls['invalid'] as $url) { |
| 686 | + $this->assertFalse(V::url($url), "Expected invalid: $url"); |
| 687 | + } |
770 | 688 | } |
771 | 689 |
|
772 | 690 | public static function inputProvider(): array |
|
0 commit comments