More work on parsing microformats
This commit is contained in:
1 parent
4179ee10e9
commit
2735abde64
4 files changed
+103
-54
No files matched your search
+47
-30
@@ -14,6 +14,10 @@ use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
use Symfony\Contracts\HttpClient\ResponseInterface;
|
||||
|
||||
class EndpointTest extends TestCase {
|
||||
private function objectContains(string $key, mixed $value) {
|
||||
return $this->callback(fn(object $obj) => $obj->$key === $value);
|
||||
}
|
||||
|
||||
#[TestWith(["https://my.url.com", true])]
|
||||
#[TestWith(["my.url.com", false])]
|
||||
public function testValidatesUrls(string $url, bool $expected)
|
||||
@@ -139,16 +143,7 @@ class EndpointTest extends TestCase {
|
||||
|
||||
$mockGateway->expects($this->once())
|
||||
->method('save')
|
||||
->with($this->equalTo(
|
||||
new Webmention(
|
||||
null,
|
||||
$target,
|
||||
$source,
|
||||
MentionType::Like,
|
||||
null,
|
||||
null
|
||||
))
|
||||
);
|
||||
->with($this->objectContains('type', MentionType::Like));
|
||||
|
||||
$endpoint = new Endpoint($mockClient, $mockGateway);
|
||||
|
||||
@@ -189,16 +184,7 @@ class EndpointTest extends TestCase {
|
||||
|
||||
$mockGateway->expects($this->once())
|
||||
->method('save')
|
||||
->with($this->equalTo(
|
||||
new Webmention(
|
||||
null,
|
||||
$target,
|
||||
$source,
|
||||
MentionType::Mention,
|
||||
null,
|
||||
null
|
||||
))
|
||||
);
|
||||
->with($this->objectContains('type', MentionType::Mention));
|
||||
|
||||
$endpoint = new Endpoint($mockClient, $mockGateway);
|
||||
$endpoint->receiveWebmention($source, $target);
|
||||
@@ -238,19 +224,50 @@ class EndpointTest extends TestCase {
|
||||
|
||||
$mockGateway->expects($this->once())
|
||||
->method('save')
|
||||
->with($this->equalTo(
|
||||
new Webmention(
|
||||
null,
|
||||
$target,
|
||||
$source,
|
||||
MentionType::Reply,
|
||||
null,
|
||||
null
|
||||
))
|
||||
);
|
||||
->with($this->objectContains('type', MentionType::Reply));
|
||||
|
||||
$endpoint = new Endpoint($mockClient, $mockGateway);
|
||||
$endpoint->receiveWebmention($source, $target);
|
||||
}
|
||||
|
||||
public function testItShouldParseAWebmentionAsARepost()
|
||||
{
|
||||
$source = "https://my-valid-source-url.com";
|
||||
$target = "https://lewisdale.dev/post/a-post-page";
|
||||
|
||||
$content = <<<XML
|
||||
<html>
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Some content</h1>
|
||||
<p>Here's some body content. It <a href="/another/page">contains a url</a>.</p>
|
||||
<p>I'm writing about <a href="$target" class="u-repost-of">this post</a>.</p>
|
||||
</body>
|
||||
</html>
|
||||
XML;
|
||||
|
||||
$mockClient = $this->createMock(HttpClientInterface::class);
|
||||
$mockResponse = $this->createMock(ResponseInterface::class);
|
||||
$mockGateway = $this->createMock(WebmentionGatewayInterface::class);
|
||||
|
||||
$mockClient->expects($this->once())
|
||||
->method('request')
|
||||
->with($this->identicalTo('GET'), $this->identicalTo($source))
|
||||
->will($this->returnValue($mockResponse));
|
||||
|
||||
$mockResponse->method('getStatusCode')
|
||||
->will($this->returnValue(200));
|
||||
|
||||
$mockResponse->method('getContent')
|
||||
->willReturn($content);
|
||||
|
||||
$mockGateway->expects($this->once())
|
||||
->method('save')
|
||||
->with($this->objectContains('type', MentionType::Repost));
|
||||
|
||||
$endpoint = new Endpoint($mockClient, $mockGateway);
|
||||
$endpoint->receiveWebmention($source, $target);
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -78,7 +78,7 @@ class SqliteGatewayTest extends TestCase
|
||||
null,
|
||||
"https://lewisdale.dev/post/a-new-post",
|
||||
"https://a-source.url",
|
||||
MentionType::Comment,
|
||||
MentionType::Reply,
|
||||
"No content",
|
||||
"Some Author Name"
|
||||
));
|
||||
@@ -124,7 +124,7 @@ class SqliteGatewayTest extends TestCase
|
||||
null,
|
||||
"https://lewisdale.dev/post/a-new-post",
|
||||
"https://a-source.url",
|
||||
MentionType::Comment,
|
||||
MentionType::Reply,
|
||||
"Some content",
|
||||
"Some Author Name"
|
||||
));
|
||||
|
||||
Reference in new issue
Block a user