Skip to content

Commit

Permalink
modified
Browse files Browse the repository at this point in the history
  • Loading branch information
thangnn committed Oct 24, 2024
1 parent c61f8df commit 1504dc7
Showing 1 changed file with 6 additions and 20 deletions.
26 changes: 6 additions & 20 deletions plugins/bc-blog/tests/TestCase/Service/BlogContentsServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,34 +344,20 @@ public function test_findByContentId()
}
/**
* test findByUrl
* @param $url
* @param $expected
* @dataProvider findByUrlDataProvider
*/
public function test_findByUrl($url, $expected)
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($url);
$rs = $this->BlogContentsService->findByUrl('/test');
$this->assertEquals('url test', $rs->content->title);

if (empty($url)) {
$this->assertEquals($expected, $rs);
}else{
$this->assertEquals($expected, $rs->content->title);
}
}

public static function findByUrlDataProvider()
{
return [
['', ''],
['/test', 'url test'],
['/demo', 'url demo'],
];
//with empty url
$rs = $this->BlogContentsService->findByUrl('');
$this->assertNull($rs);
}

}

0 comments on commit 1504dc7

Please sign in to comment.