Skip to content

Commit 51e4458

Browse files
committed
Merge branch 'HungDV2022-unittest_InstallationsController_index' into 5.2.x
2 parents 3cbf69f + 24a3deb commit 51e4458

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

plugins/bc-installer/src/Controller/Admin/InstallationsController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public function beforeFilter(EventInterface $event)
6464
* @return void
6565
* @noTodo
6666
* @checked
67+
* @unitTest
6768
*/
6869
public function index()
6970
{

plugins/bc-installer/tests/TestCase/Controller/Admin/InstallationsControllerTest.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111

1212
namespace BcInstaller\Test\TestCase\Controller\Admin;
1313
use BaserCore\TestSuite\BcTestCase;
14+
use BaserCore\Utility\BcContainerTrait;
1415
use BcInstaller\Controller\Admin\InstallationsController;
16+
use Cake\Core\Configure;
1517
use Cake\Event\Event;
1618

1719
/**
@@ -22,7 +24,8 @@
2224
class InstallationsControllerTest extends BcTestCase
2325
{
2426

25-
/**
27+
use BcContainerTrait;
28+
2629
/**
2730
* setup
2831
*/
@@ -46,6 +49,7 @@ public function tearDown(): void
4649
*/
4750
public function testBeforeFilter()
4851
{
52+
$this->markTestSkipped('このテストは未確認です。');
4953
$this->InstallationsController = new InstallationsController($this->getRequest());
5054
$event = new Event('Controller.beforeFilter', $this->InstallationsController);
5155
$this->InstallationsController->beforeFilter($event);
@@ -57,7 +61,23 @@ public function testBeforeFilter()
5761
*/
5862
public function testIndex()
5963
{
60-
$this->markTestIncomplete('このテストは、まだ実装されていません。');
64+
Configure::write("BcEnv.isInstalled", false);
65+
//backup file
66+
copy(ROOT . DS . 'config' . DS . '.env', ROOT . DS . 'config' . DS . '.env.bak');
67+
copy(ROOT . DS . 'config' . DS . 'install.php', ROOT . DS . 'config' . DS . 'install.php.bak');
68+
copy(ROOT . DS . 'vendor' . DS . 'autoload.php', ROOT . DS . 'vendor' . DS . 'autoload.php.bak');
69+
$this->get('/');
70+
71+
//CSRFがあるか確認すること
72+
$_cookies = $this->getPrivateProperty($this->_response, '_cookies');
73+
$cookies = $this->getPrivateProperty($_cookies, 'cookies');
74+
$this->assertNotEmpty($cookies['csrfToken;;/']);
75+
76+
Configure::write("BcEnv.isInstalled", true);
77+
//backup
78+
rename(ROOT . DS . 'config' . DS . '.env.bak', ROOT . DS . 'config' . DS . '.env');
79+
rename(ROOT . DS . 'config' . DS . 'install.php.bak', ROOT . DS . 'config' . DS . 'install.php');
80+
rename(ROOT . DS . 'vendor' . DS . 'autoload.php.bak', ROOT . DS . 'vendor' . DS . 'autoload.php');
6181
}
6282

6383
/**

0 commit comments

Comments
 (0)