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

testGetPostContent #2963

Merged

Conversation

nghiem-mb
Copy link
Contributor

No description provided.

public function testGetPostContent()
{
// 準備
$templateDir = ROOT . DS . 'plugins' . DS . 'bc-admin-third' . DS . 'templates'. DS;
Copy link
Collaborator

Choose a reason for hiding this comment

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

@nghiem-mb テスト実行時、テンプレートが存在しないというエラーが出たのでしょうか?

BlogHelper::getPostContent() を確認したところ、エレメント呼び出しでプラグイン名の指定がなかったので、エラーになった可能性が高いです。
(ブラウザで実行している場合はプラグイン名なしでも動作します)

次のように変更した上で再度テストを作ってもらえますか?

// BlogHelper 493行目、501行目
$this->BcBaser->getElement('BcBlog.blog_post_content'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ryuring
変更しましたが、以下のエラー出ています。
いろいろ修正しましたが、まだ駄目です。
ご確認お願いします。

There was 1 error:

1) BcBlog\Test\TestCase\View\Helper\BlogHelperTest::testGetPostContent
Cake\View\Exception\MissingHelperException: Helper class BlogHelper could not be found.

/var/www/html/vendor/cakephp/cakephp/src/View/HelperRegistry.php:133
/var/www/html/vendor/cakephp/cakephp/src/Core/ObjectRegistry.php:103
/var/www/html/vendor/cakephp/cakephp/src/View/HelperRegistry.php:70
/var/www/html/vendor/cakephp/cakephp/src/View/View.php:1132
/var/www/html/plugins/bc-front/templates/plugin/BcBlog/element/blog_post_content_more.php:27
/var/www/html/vendor/cakephp/cakephp/src/View/View.php:1222
/var/www/html/vendor/cakephp/cakephp/src/View/View.php:1179
/var/www/html/vendor/cakephp/cakephp/src/View/View.php:1731
/var/www/html/vendor/cakephp/cakephp/src/View/View.php:701
/var/www/html/plugins/baser-core/src/View/Helper/BcBaserHelper.php:326
/var/www/html/plugins/bc-blog/src/View/Helper/BlogHelper.php:506
/var/www/html/plugins/bc-blog/tests/TestCase/View/Helper/BlogHelperTest.php:311
/var/www/html/vendor/bin/phpunit:122

Copy link
Collaborator

Choose a reason for hiding this comment

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

@nghiem-mb テンプレートの中で、ヘルパが読み込まれていないみたいですね。
ブラウザからアクセスする場合はViewクラスで読み込まれますが、テストの場合は明示的に読み込んであげる必要があるみたいですね。

次の行を追記してみてください。

$this->Blog->getView()->addHelper('Blog', ['className' => 'BcBlog.Blog']);

もしくは、setUp() にて、BlogHelper を初期化する際に、BlogFrontAppView を利用するといいかもしれません。
ブラウザからのアクセスの際はその仕様なのでそちらの方がいいかもしれません。

@ryuring ryuring assigned nghiem-mb and unassigned ryuring Dec 22, 2023
@ryuring ryuring added the Reviewed レビュー済 label Dec 22, 2023
@nghiem-mb nghiem-mb assigned ryuring and unassigned nghiem-mb Jan 10, 2024
@ryuring ryuring merged commit 555b3da into baserproject:dev-cake5 Jan 10, 2024
1 check passed
@momofff momofff added this to the close milestone Jan 18, 2024
@nghiem-mb nghiem-mb deleted the BlogHelper-testGetPostContent branch January 19, 2024 04:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Reviewed レビュー済
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants