Move URL into separate file, handle source URL validation for sending webmentions
This commit is contained in:
1 parent
fca08de828
commit
ec83d67bde
8 files changed
+125
-60
No files matched your search
@@ -48,15 +48,7 @@ class EndpointTest extends TestCase
|
||||
$endpoint = new Endpoint($this->mockClient, $this->mockGateway);
|
||||
$endpoint->receiveWebmention($source, $target);
|
||||
}
|
||||
|
||||
#[TestWith(["https://my.url.com", true])]
|
||||
#[TestWith(["my.url.com", false])]
|
||||
public function testValidatesUrls(string $url, bool $expected)
|
||||
{
|
||||
$endpoint = new Endpoint($this->mockClient, $this->mockGateway);
|
||||
$this->assertEquals($expected, $endpoint->validateUrl($url), "Expected $url");
|
||||
}
|
||||
|
||||
|
||||
#[TestWith(["https://my-valid-source.url", "htt://my-invalid-target.com"])]
|
||||
#[TestWith(["my-invalid-source", "https://my-valid-target.com"])]
|
||||
#[TestWith(["http:///an-invalid-source", "an-invalid-target"])]
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<?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));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user