Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add unitTest_BlogCategoriesTable_getByName #3170

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions plugins/bc-blog/src/Model/Table/BlogCategoriesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,19 +355,15 @@ public function hasChild($id)
* @param int $blogContentId
* @param string $name
* @param array $options
* @return array|null
* @return EntityInterface
*/
public function getByName($blogContentId, $name, $options = [])
{
$options = array_merge([
'conditions' => [
'BlogCategory.blog_content_id' => $blogContentId,
'BlogCategory.name' => urlencode($name),
],
'recursive' => -1
], $options);
$this->unbindModel(['hasMany' => ['BlogPost']]);
return $this->find('first', $options);
return $this->find()->where([
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thangnnmd @HungDV2022 $options が使われていませんので、find() の第2引数に入れてください。
第一引数は、'all' で大丈夫です。

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'BlogCategories.blog_content_id' => $blogContentId,
'BlogCategories.name' => urlencode($name)
]
)->first();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,9 @@ public function testHasChild()
*/
public function testGetByName($blogCategoryId, $name, $expects)
{
$this->markTestIncomplete('こちらのテストはまだ未確認です');
$result = $this->BlogCategory->getByName($blogCategoryId, $name);
//データ生成
BlogCategoryFactory::make(['blog_content_id' => 1, 'name' => 'child'])->persist();
$result = $this->BlogCategoriesTable->getByName($blogCategoryId, $name);
$this->assertEquals($expects, (bool)$result);
}

Expand Down
Loading