gateway = new SqliteGateway(":memory:"); } public function testCanInsertAWebmention() { $webmention = new Webmention( null, "https://lewisdale.dev/post/a-post", "https://a-source.url", MentionType::Like, "No content", new \Lewisdale\Webmentions\Models\Author(), ); $webmention->id = $this->gateway->save($webmention); $this->assertNotNull($webmention->id); } public function testCanRetrieveAWebmention() { $webmention = new Webmention( null, "https://lewisdale.dev/post/a-post", "https://a-source.url", MentionType::Like, "No content", new \Lewisdale\Webmentions\Models\Author(null, null, null, null), ); $webmention->id = $this->gateway->save($webmention); $retrieved = $this->gateway->get($webmention->id); $this->assertEquals($webmention, $retrieved); } public function testCanDeleteAWebmention() { $webmention = new Webmention( null, "https://lewisdale.dev/post/a-post", "https://a-source.url", MentionType::Like, "No content", new \Lewisdale\Webmentions\Models\Author() ); $webmention->id = $this->gateway->save($webmention); $this->gateway->delete($webmention); $retrieved = $this->gateway->get($webmention->id); $this->assertNull($retrieved); } public function testCanGetByPost() { foreach (range(0, 4) as $_) { $this->gateway->save(new Webmention( null, "https://lewisdale.dev/post/a-new-post", "https://a-source.url", MentionType::Reply, "No content", new \Lewisdale\Webmentions\Models\Author() )); } foreach (range(0, 4) as $_) { $this->gateway->save(new Webmention( null, "https://lewisdale.dev/post/a-different-post", "https://a-source.url", MentionType::Like, "No content", new \Lewisdale\Webmentions\Models\Author() )); } $mentions = $this->gateway->getByPost("https://lewisdale.dev/post/a-new-post"); $this->assertCount(5, $mentions); } public function testCanFindByParams() { $this->gateway->save(new Webmention( null, "https://lewisdale.dev/post/a-new-post", "https://a-source.url", MentionType::Reply, "No content", new \Lewisdale\Webmentions\Models\Author() )); $this->gateway->save(new Webmention( null, "https://lewisdale.dev/post/a-new-post", "https://a-different-source.url", MentionType::Like, "No content", new \Lewisdale\Webmentions\Models\Author() )); $this->gateway->save(new Webmention( null, "https://lewisdale.dev/post/a-new-post", "https://a-source.url", MentionType::Reply, "Some content", new \Lewisdale\Webmentions\Models\Author() )); $this->assertCount( 2, $this->gateway->find([ "target" => "https://lewisdale.dev/post/a-new-post", "source" => "https://a-source.url", ]) ); $this->assertCount( 1, $this->gateway->find([ "target" => "https://lewisdale.dev/post/a-new-post", "source" => "https://a-different-source.url", ]) ); $this->assertCount( 1, $this->gateway->find([ "target" => "https://lewisdale.dev/post/a-new-post", "source" => "https://a-source.url", "content" => "Some content", ]) ); } public function testItSavesAnAuthorWithTheWebmention() { $webmention = new Webmention( null, "https://a-target-url.com", "https://a-source-url.com", MentionType::Like, "Liked this post", new \Lewisdale\Webmentions\Models\Author( null, "Doreen Mifah", "https://my-homepage.com", "https://cdn.imgserver.com/400/400" ) ); $webmention->id = $this->gateway->save($webmention); $retrieved = $this->gateway->get($webmention->id)?->author; $expected = $webmention->author; $this->assertEquals($expected->name, $retrieved?->name); $this->assertEquals($expected->url, $retrieved?->url); $this->assertEquals($expected->photo, $retrieved?->photo); } public function testItLooksUpWebmentionsByAuthorName() { $this->gateway->save(new Webmention( null, "https://a-target-url.com", "https://a-source-url.com", MentionType::Like, "Liked this post", new \Lewisdale\Webmentions\Models\Author( null, "Doreen Mifah", "https://my-homepage.com", "https://cdn.imgserver.com/400/400" ) )); $this->gateway->save(new Webmention( null, "https://a-target-url.com", "https://a-source-url.com", MentionType::Like, "Liked this post", new \Lewisdale\Webmentions\Models\Author( null, "Carl Weathers", "https://carl-weathers.com", "https://cdn.imgserver.com/400/400" ) )); $this->gateway->save(new Webmention( null, "https://a-target-url.com", "https://a-source-url.com", MentionType::Like, "Liked this post", new \Lewisdale\Webmentions\Models\Author( null, "Barry White", "https://barry.white.com", "https://cdn.imgserver.com/400/400" ) )); $this->gateway->save(new Webmention( null, "https://a-target-url.com", "https://a-source-url.com", MentionType::Reply, "This was a cool post!", new \Lewisdale\Webmentions\Models\Author( null, "Carl Weathers", "https://carl-weathers.com", "https://cdn.imgserver.com/400/400" ) )); $retrieved = $this->gateway->find(["author_name" => "Carl Weathers"]); $this->assertCount(2, $retrieved); } }