Return related posts for a specified blog post
Add the initial code for specifying a blog post and returning related posts. This includes adding a repository for related posts, and adding it as a service within the `opdavies_blog` module. References #3
This commit is contained in:
parent
62424d5b04
commit
d7f3d8c482
3 changed files with 73 additions and 0 deletions
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
// phpcs:disable Drupal.Commenting.DocComment, Drupal.NamingConventions.ValidFunctionName
|
||||
|
||||
namespace Drupal\Tests\opdavies_blog\Kernel;
|
||||
|
||||
use Drupal\opdavies_blog\Repository\RelatedPostsRepository;
|
||||
use Drupal\opdavies_blog_test\Factory\PostFactory;
|
||||
|
||||
final class RelatedPostsTest extends PostTestBase {
|
||||
|
||||
private RelatedPostsRepository $relatedPostsRepository;
|
||||
|
||||
/** @test */
|
||||
public function it_returns_related_posts(): void {
|
||||
$postA = (new PostFactory())->setTitle('Post A')
|
||||
->withTags(['Drupal 8'])
|
||||
->create();
|
||||
$postA->save();
|
||||
|
||||
$postB = (new PostFactory())->setTitle('Post B')
|
||||
->withTags(['Drupal 8'])
|
||||
->create();
|
||||
$postB->save();
|
||||
|
||||
$relatedPosts = $this->relatedPostsRepository->getFor($postA);
|
||||
|
||||
$this->assertCount(1, $relatedPosts);
|
||||
$this->assertSame('Post B', $relatedPosts->first()->label());
|
||||
}
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->relatedPostsRepository = $this->container->get(RelatedPostsRepository::class);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue