Skip to content

Commit

Permalink
Merge pull request #3920 from thangnnmd/unitTest_BlogContentsService_…
Browse files Browse the repository at this point in the history
…findByUrl

BlogContentsService::findByUrl
  • Loading branch information
HungDV2022 authored Oct 28, 2024
2 parents 62c1313 + de7d52c commit d827feb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions plugins/bc-blog/src/Service/BlogContentsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,9 @@ public function getContentsTemplateRelativePath(array $options): string
*
* @param string $url
* @return EntityInterface|null
* @checked
* @noTodo
* @unitTest
*/
public function findByUrl(string $url): ?EntityInterface
{
Expand Down
19 changes: 19 additions & 0 deletions plugins/bc-blog/tests/TestCase/Service/BlogContentsServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,4 +342,23 @@ public function test_findByContentId()
$rs = $this->BlogContentsService->findByContentId(999);
$this->assertNull($rs);
}
/**
* test findByUrl
*/
public function test_findByUrl()
{
//generate data
BlogContentFactory::make(['id' => 1])->persist();
ContentFactory::make(['id' => 1, 'type' => 'BlogContent', 'entity_id' => 1, 'title' => 'url test', 'url' => '/test', 'site_id' => 1])->persist();
ContentFactory::make(['id' => 2, 'type' => 'BlogContent', 'entity_id' => 1,'title' => 'url demo', 'url' => '/demo', 'site_id' => 1])->persist();
SiteFactory::make(['id' => 1, 'theme' => 'BcBlog'])->persist();

$rs = $this->BlogContentsService->findByUrl('/test');
$this->assertEquals('url test', $rs->content->title);

//with empty url
$rs = $this->BlogContentsService->findByUrl('');
$this->assertNull($rs);
}

}

0 comments on commit d827feb

Please sign in to comment.