From 53df31173c7809b3eb833bbcae9b04dee35f5dcd Mon Sep 17 00:00:00 2001 From: ryuring Date: Mon, 6 Nov 2023 11:02:20 +0900 Subject: [PATCH] =?UTF-8?q?dataProvider=E5=86=85=E3=81=A7=E3=80=81find()?= =?UTF-8?q?=20=E3=82=92=E5=AE=9F=E8=A1=8C=E3=81=97=E3=81=A6=E3=81=84?= =?UTF-8?q?=E3=81=9F=E3=81=9F=E3=82=81=E3=80=81=E4=BB=96=E3=81=AE=E3=83=86?= =?UTF-8?q?=E3=82=B9=E3=83=88=E3=81=AB=E5=BD=B1=E9=9F=BF=E3=81=8C=E5=87=BA?= =?UTF-8?q?=E3=81=A6=E3=81=84=E3=81=9F=E3=81=AE=E3=81=A7=E8=AA=BF=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TestCase/Service/BlogPostsServiceTest.php | 269 +++++++++--------- 1 file changed, 134 insertions(+), 135 deletions(-) diff --git a/plugins/bc-blog/tests/TestCase/Service/BlogPostsServiceTest.php b/plugins/bc-blog/tests/TestCase/Service/BlogPostsServiceTest.php index 018a322416..59bd52668a 100755 --- a/plugins/bc-blog/tests/TestCase/Service/BlogPostsServiceTest.php +++ b/plugins/bc-blog/tests/TestCase/Service/BlogPostsServiceTest.php @@ -429,141 +429,140 @@ public function testCreateOrder() * ページ一覧用の検索条件を生成する * @dataProvider createIndexConditionsDataProvider */ - public function testCreateIndexConditions($isLoadScenario, $query, $options, $expected) - { - if ($isLoadScenario) { - $this->loadFixtureScenario(MultiSiteBlogScenario::class); - BlogPostFactory::make([])->publish(1, 1)->persist(); - BlogTagFactory::make(['id' => 1, 'name' => 'tag1'])->persist(); - BlogPostBlogTagFactory::make(['blog_post_id' => 1, 'blog_tag_id' => 1])->persist(); - UserFactory::make(['id' => 1, 'name' => 'test_author'])->persist(); - } - - $result = $this->execPrivateMethod($this->BlogPostsService, "createIndexConditions", [$query, $options]); - $this->assertEquals($expected, $result); - } - - /** - * createIndexConditionsテストのデータプロバイダ - * @return array - */ - public function createIndexConditionsDataProvider(): array - { - $blogPost = new BlogPostsTable(); - return [ - // 空配列の結果テスト - [ - false, - $blogPost->find('all'), - [], - $blogPost->find('all') - ], - //$params ID - [ - false, - $blogPost->find('all'), - ['id' => 1], - $blogPost->find('all')->where(['BlogPosts.id' => 1]) - ], - //$params タイトル - [ - false, - $blogPost->find('all'), - ['title' => 'test title'], - $blogPost->find('all')->where(['BlogPosts.title LIKE' => '%test title%']) - ], - //$params ユーザーID - [ - false, - $blogPost->find('all'), - ['user_id' => 1], $blogPost->find('all')->where(['BlogPosts.user_id' => 1]) - ], - //$params ブログコンテンツID - [ - false, - $blogPost->find('all'), - ['blog_content_id' => 1], - $blogPost->find('all')->where(['BlogPosts.blog_content_id' => 1]) - ], - //$params サイトID - [ - false, - $blogPost->find('all'), - ['site_id' => 1], - $blogPost->find('all')->where(['Contents.site_id' => 1]) - ], - //$params URL - [ - false, - $blogPost->find('all'), - ['contentUrl' => '/test'], - $blogPost->find('all')->contain(['BlogContents' => ['Contents']])->where(['Contents.url' => '/test']) - ], - //$params カテゴリID - [ - true, - $blogPost->find('all'), - ['blog_category_id' => 1], - $blogPost->find('all')->where(['BlogPosts.blog_category_id IN' => [1, 2]]) - ], - //$params カテゴリ名 - [ - true, - $blogPost->find('all'), - ['category' => 'release', 'force' => true], - $blogPost->find('all')->where(['BlogPosts.blog_category_id IN' => [1, 2]]) - ], - //$params タグ名 - [ - true, - $blogPost->find('all'), - ['tag' => 'tag1'], - $blogPost->find('all')->where(['BlogPosts.id IN' => 1]) - ], - //$params 年月日 - [ - false, - $blogPost->find('all'), - ['year' => 1994, 'month' => 8, 'day' => 21], - $blogPost->find('all')->where([ - 'YEAR(BlogPosts.posted)' => 1994, - 'MONTH(BlogPosts.posted)' => 8, - 'DAY(BlogPosts.posted)' => 21 - ]) - ], - //$params No - [ - false, - $blogPost->find('all'), - ['no' => 1, 'force' => true], - $blogPost->find('all')->where(['BlogPosts.no' => 1]) - ], - // $params キーワード - [ - false, - $blogPost->find('all'), - ['keyword' => 'test'], - $blogPost->find('all')->where([ - 'and' => [ - 0 => [ - 'or' => [ - ['BlogPosts.title LIKE' => '%test%'], - ['BlogPosts.content LIKE' => '%test%'], - ['BlogPosts.detail LIKE' => '%test%'] - ] - ] - ] - ])], - //$params 作成者 - [ - true, - $blogPost->find('all'), - ['author' => 'test_author'], - $blogPost->find('all')->where(['BlogPosts.user_id' => 1]) - ], - ]; - } - + // TODO dataProvider内で、find() を実行しないように変更 + // dataProvider内で、find() を実行すると、DBの接続先が、test でなく、default になってしまい、 + // 全体実行の際に、他のテストに影響が出てしまうため。 +// public function testCreateIndexConditions($isLoadScenario, $query, $options, $expected) +// { +// $users = $this->getTableLocator()->get('BaserCore.Users'); +// if ($isLoadScenario) { +// $this->loadFixtureScenario(MultiSiteBlogScenario::class); +// BlogPostFactory::make([])->publish(1, 1)->persist(); +// BlogTagFactory::make(['id' => 1, 'name' => 'tag1'])->persist(); +// BlogPostBlogTagFactory::make(['blog_post_id' => 1, 'blog_tag_id' => 1])->persist(); +// UserFactory::make(['id' => 1, 'name' => 'test_author'])->persist(); +// } +// +// $result = $this->execPrivateMethod($this->BlogPostsService, "createIndexConditions", [$query, $options]); +// $this->assertEquals($expected, $result); +// } +// +// public function createIndexConditionsDataProvider(): array +// { +// $blogPost = new BlogPostsTable(); +// return [ +// // 空配列の結果テスト +// [ +// false, +// $blogPost->find('all'), +// [], +// $blogPost->find('all') +// ], +// //$params ID +// [ +// false, +// $blogPost->find('all'), +// ['id' => 1], +// $blogPost->find('all')->where(['BlogPosts.id' => 1]) +// ], +// //$params タイトル +// [ +// false, +// $blogPost->find('all'), +// ['title' => 'test title'], +// $blogPost->find('all')->where(['BlogPosts.title LIKE' => '%test title%']) +// ], +// //$params ユーザーID +// [ +// false, +// $blogPost->find('all'), +// ['user_id' => 1], $blogPost->find('all')->where(['BlogPosts.user_id' => 1]) +// ], +// //$params ブログコンテンツID +// [ +// false, +// $blogPost->find('all'), +// ['blog_content_id' => 1], +// $blogPost->find('all')->where(['BlogPosts.blog_content_id' => 1]) +// ], +// //$params サイトID +// [ +// false, +// $blogPost->find('all'), +// ['site_id' => 1], +// $blogPost->find('all')->where(['Contents.site_id' => 1]) +// ], +// //$params URL +// [ +// false, +// $blogPost->find('all'), +// ['contentUrl' => '/test'], +// $blogPost->find('all')->contain(['BlogContents' => ['Contents']])->where(['Contents.url' => '/test']) +// ], +// //$params カテゴリID +// [ +// true, +// $blogPost->find('all'), +// ['blog_category_id' => 1], +// $blogPost->find('all')->where(['BlogPosts.blog_category_id IN' => [1, 2]]) +// ], +// //$params カテゴリ名 +// [ +// true, +// $blogPost->find('all'), +// ['category' => 'release', 'force' => true], +// $blogPost->find('all')->where(['BlogPosts.blog_category_id IN' => [1, 2]]) +// ], +// //$params タグ名 +// [ +// true, +// $blogPost->find('all'), +// ['tag' => 'tag1'], +// $blogPost->find('all')->where(['BlogPosts.id IN' => 1]) +// ], +// //$params 年月日 +// [ +// false, +// $blogPost->find('all'), +// ['year' => 1994, 'month' => 8, 'day' => 21], +// $blogPost->find('all')->where([ +// 'YEAR(BlogPosts.posted)' => 1994, +// 'MONTH(BlogPosts.posted)' => 8, +// 'DAY(BlogPosts.posted)' => 21 +// ]) +// ], +// //$params No +// [ +// false, +// $blogPost->find('all'), +// ['no' => 1, 'force' => true], +// $blogPost->find('all')->where(['BlogPosts.no' => 1]) +// ], +// // $params キーワード +// [ +// false, +// $blogPost->find('all'), +// ['keyword' => 'test'], +// $blogPost->find('all')->where([ +// 'and' => [ +// 0 => [ +// 'or' => [ +// ['BlogPosts.title LIKE' => '%test%'], +// ['BlogPosts.content LIKE' => '%test%'], +// ['BlogPosts.detail LIKE' => '%test%'] +// ] +// ] +// ] +// ])], +// //$params 作成者 +// [ +// true, +// $blogPost->find('all'), +// ['author' => 'test_author'], +// $blogPost->find('all')->where(['BlogPosts.user_id' => 1]) +// ], +// ]; +// } /** * 同じタグの関連投稿を取得する