29 lines
		
	
	
		
			978 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			29 lines
		
	
	
		
			978 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
 | 
						|
use Lewisdale\Webmentions\Url;
 | 
						|
use PHPUnit\Framework\Attributes\TestWith;
 | 
						|
use PHPUnit\Framework\TestCase;
 | 
						|
 | 
						|
class UrlTest extends TestCase
 | 
						|
{
 | 
						|
 | 
						|
    #[TestWith(["https://lewisdale.dev/post/a-post", "lewisdale.dev", true])]
 | 
						|
    #[TestWith(["https://css-tricks.com/test/host", "lewisdale.dev", false])]
 | 
						|
    #[TestWith(["ht:/lewisdale.dev/not-a-valid-url", "lewisdale.dev", false])]
 | 
						|
    public function testItValidatesAHost(string $source, string $target, bool $expected)
 | 
						|
    {
 | 
						|
        $this->assertEquals($expected, Url::matchesHost($source, $target, $expected));
 | 
						|
    }
 | 
						|
 | 
						|
    #[TestWith(["http://a-valid-http-url.com", true])]
 | 
						|
    #[TestWith(["ht://an-invalid-url.com", false])]
 | 
						|
    #[TestWith(["https://no-tld./", false])]
 | 
						|
    #[TestWith(["https://a-valid-https.com", true])]
 | 
						|
    #[TestWith(["ftp://wrong-protocol.com", false])]
 | 
						|
    public function testItValidatesAUrl(string $url, bool $expected)
 | 
						|
    {
 | 
						|
        $this->assertEquals($expected, Url::validateUrl($url));
 | 
						|
    }
 | 
						|
}
 |