From 880fee17264f23801cc00e567893a1ec0fa52b42 Mon Sep 17 00:00:00 2001
From: thangnn <nguyenthang.mediabridge@gmail.com>
Date: Wed, 18 Dec 2024 16:08:57 +0700
Subject: [PATCH] unitTest_InstallerMailer_installed

---
 .../src/Mailer/Admin/InstallerMailer.php      |  1 +
 .../Mailer/Admin/InstallerMailerTest.php      | 66 +++++++++++++++++++
 2 files changed, 67 insertions(+)
 create mode 100644 plugins/bc-installer/tests/TestCase/Mailer/Admin/InstallerMailerTest.php

diff --git a/plugins/bc-installer/src/Mailer/Admin/InstallerMailer.php b/plugins/bc-installer/src/Mailer/Admin/InstallerMailer.php
index 076f6dd09b..aba99d1054 100644
--- a/plugins/bc-installer/src/Mailer/Admin/InstallerMailer.php
+++ b/plugins/bc-installer/src/Mailer/Admin/InstallerMailer.php
@@ -33,6 +33,7 @@ class InstallerMailer extends BcAdminMailer
      * @param PasswordRequest|EntityInterface
      * @checked
      * @noTodo
+     * @unitTest
      */
     public function installed(string $email)
     {
diff --git a/plugins/bc-installer/tests/TestCase/Mailer/Admin/InstallerMailerTest.php b/plugins/bc-installer/tests/TestCase/Mailer/Admin/InstallerMailerTest.php
new file mode 100644
index 0000000000..e6b4d431d8
--- /dev/null
+++ b/plugins/bc-installer/tests/TestCase/Mailer/Admin/InstallerMailerTest.php
@@ -0,0 +1,66 @@
+<?php
+/**
+ * baserCMS :  Based Website Development Project <https://basercms.net>
+ * Copyright (c) baserCMS Users Community <https://basercms.net/community/>
+ *
+ * @copyright       Copyright (c) baserCMS Users Community
+ * @link            https://basercms.net baserCMS Project
+ * @since           baserCMS v 4.0.9
+ * @license         https://basercms.net/license/index.html
+ */
+
+namespace BcInstaller\Test\TestCase\Mailer\Admin;
+use BaserCore\Test\Factory\SiteConfigFactory;
+use BaserCore\Test\Factory\SiteFactory;
+use BaserCore\TestSuite\BcTestCase;
+use BcInstaller\Mailer\Admin\InstallerMailer;
+use Cake\TestSuite\EmailTrait;
+
+/**
+ * Class InstallerMailerTest
+ *
+ * @property  InstallerMailer $InstallerMailer
+ */
+class InstallerMailerTest extends BcTestCase
+{
+
+    use EmailTrait;
+
+    /**
+     * setup
+     */
+    public function setUp(): void
+    {
+        parent::setUp();
+        SiteConfigFactory::make(['name' => 'email', 'value' => 'basertest@example.com'])->persist();
+        SiteFactory::make(['id' => 1, 'display_name' => 'main site'])->persist();
+
+        $this->InstallerMailer = new InstallerMailer();
+    }
+
+    /**
+     * tearDown
+     *
+     * @return void
+     */
+    public function tearDown(): void
+    {
+        parent::tearDown();
+    }
+
+    /**
+     * beforeFilter
+     */
+    public function testInstalled()
+    {
+        $this->InstallerMailer->installed('test@example.com');
+
+        //戻り値確認
+        $this->assertEquals(['test@example.com' => 'test@example.com'], $this->InstallerMailer->getTo());
+        $vars = $this->InstallerMailer->viewBuilder()->getVars();
+        $this->assertEquals('test@example.com', $vars['email']);
+        $this->assertEquals('https://localhost/', $vars['siteUrl']);
+        $this->assertEquals('https://localhost/baser/admin/baser-core/users/login', $vars['adminUrl']);
+    }
+
+}