Skip to content

Commit

Permalink
add unitTest_BlogHelper_getPostId (#3161)
Browse files Browse the repository at this point in the history
Co-authored-by: thangnn <[email protected]>
  • Loading branch information
thangnnmd and thangnn authored Feb 26, 2024
1 parent 29335cb commit 82d25c1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions plugins/bc-blog/src/View/Helper/BlogHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1396,6 +1396,7 @@ public function getCategoryTitle(BlogPost $post)
* @return string
* @checked
* @noTodo
* @unitTest
*/
public function getPostId(BlogPost $post)
{
Expand Down
24 changes: 24 additions & 0 deletions plugins/bc-blog/tests/TestCase/View/Helper/BlogHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1874,4 +1874,28 @@ public function test_getCategoryTitle()
$result = $this->Blog->getCategoryTitle($blogPost);
$this->assertEmpty($result);
}

/**
* getPostId
*/
public function test_getPostId()
{
// テストデータを作る
$this->loadFixtureScenario(InitAppScenario::class);
$this->Blog->getView()->setRequest($this->getRequest()->withAttribute('currentSite', SiteFactory::get(1)));
$post = new BlogPost([
'id' => 1,
'blog_content_id' => 1,
'name' => 'release',
]);

//check exits id
$result = $this->Blog->getPostId($post);
$this->assertEquals(1, $result);

//check not exits id
$post = new BlogPost([]);
$result = $this->Blog->getPostId($post);
$this->assertEmpty($result);
}
}

0 comments on commit 82d25c1

Please sign in to comment.