From 3ea31cb3b662dbf54d12b62b1210112a8224d2d4 Mon Sep 17 00:00:00 2001 From: HungDV2022 <110375578+HungDV2022@users.noreply.github.com> Date: Wed, 18 Sep 2024 09:01:03 +0900 Subject: [PATCH] =?UTF-8?q?AppTable::belongsToMany=E3=80=80=E3=81=AE?= =?UTF-8?q?=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88=E3=83=86=E3=82=B9=E3=83=88?= =?UTF-8?q?=20(#3756)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Đỗ Văn Hùng --- .../baser-core/src/Model/Table/AppTable.php | 1 + .../TestCase/Model/Table/AppTableTest.php | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/plugins/baser-core/src/Model/Table/AppTable.php b/plugins/baser-core/src/Model/Table/AppTable.php index f951947c4c..b9e18cfef6 100755 --- a/plugins/baser-core/src/Model/Table/AppTable.php +++ b/plugins/baser-core/src/Model/Table/AppTable.php @@ -99,6 +99,7 @@ public function getTable(): string * @return BelongsToMany * @checked * @noTodo + * @unitTest */ public function belongsToMany(string $associated, array $options = []): BelongsToMany { diff --git a/plugins/baser-core/tests/TestCase/Model/Table/AppTableTest.php b/plugins/baser-core/tests/TestCase/Model/Table/AppTableTest.php index 71f2d88c87..3e961591ec 100644 --- a/plugins/baser-core/tests/TestCase/Model/Table/AppTableTest.php +++ b/plugins/baser-core/tests/TestCase/Model/Table/AppTableTest.php @@ -118,6 +118,29 @@ public static function getUrlPatternDataProvider() ]; } + /** + * test belongsToMany + */ + public function testBelongsToMany() + { + //プレフィックスを設定 + $dbConfig = BcUtil::getCurrentDbConfig(); + $dbConfig['prefix'] = 'unittest_'; + $connection = new Connection($dbConfig); + $this->App = $this->getTableLocator()->get('BaserCore.App')->setConnection($connection); + + $this->App = $this->getTableLocator()->get('BcBlog.BlogPosts'); + //Usersに連携 + $rs = $this->App->belongsToMany('Users', [ + 'className' => 'BaserCore.Users', + 'foreignKey' => 'user_id', + ]); + //戻り値を確認 + $this->assertEquals('user_id', $rs->getForeignKey()); + $this->assertEquals('BaserCore.Users', $rs->getClassName()); + $this->assertEquals('unittest_blog_posts', $rs->getSource()->getTable()); + } + /** * Test getMax *