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

Unittest installations controller #4104

Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public function beforeFilter(EventInterface $event)
* @return void
* @noTodo
* @checked
* @unitTest
*/
public function index()
{
Expand All @@ -79,6 +80,7 @@ public function index()
* @return void
* @noTodo
* @checked
* @unitTest
*/
public function step2(InstallationsAdminServiceInterface $service)
{
Expand All @@ -98,6 +100,7 @@ public function step2(InstallationsAdminServiceInterface $service)
* @return void|Response
* @noTodo
* @checked
* @unitTest
*/
public function step3(InstallationsAdminServiceInterface $service)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@
*/

namespace BcInstaller\Test\TestCase\Controller\Admin;
use BaserCore\Test\Scenario\InitAppScenario;
use BaserCore\TestSuite\BcTestCase;
use BaserCore\Utility\BcContainerTrait;
use BcInstaller\Controller\Admin\InstallationsController;
use Cake\Core\Configure;
use Cake\Event\Event;
use CakephpFixtureFactories\Scenario\ScenarioAwareTrait;

/**
* Class InstallationsControllerTest
Expand All @@ -21,14 +25,18 @@
*/
class InstallationsControllerTest extends BcTestCase
{
use ScenarioAwareTrait;

use BcContainerTrait;

/**
/**
* setup
*/
public function setUp(): void
{
parent::setUp();
$this->loadFixtureScenario(InitAppScenario::class);
$this->loginAdmin($this->getRequest());
}

/**
Expand All @@ -46,6 +54,7 @@ public function tearDown(): void
*/
public function testBeforeFilter()
{
$this->markTestSkipped('このテストは未確認です。');
$this->InstallationsController = new InstallationsController($this->getRequest());
$event = new Event('Controller.beforeFilter', $this->InstallationsController);
$this->InstallationsController->beforeFilter($event);
Expand All @@ -57,23 +66,77 @@ public function testBeforeFilter()
*/
public function testIndex()
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
Configure::write("BcEnv.isInstalled", false);

$this->get('/');

//CSRFがあるか確認すること
$_cookies = $this->getPrivateProperty($this->_response, '_cookies');
$cookies = $this->getPrivateProperty($_cookies, 'cookies');
$this->assertNotEmpty($cookies['csrfToken;;/']);

Configure::write("BcEnv.isInstalled", true);
}

/**
* Step 2: 必須条件チェック
*/
public function testStep2()
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
$this->enableSecurityToken();
$this->enableCsrfToken();

Configure::write("BcEnv.isInstalled", false);

$this->get('/baser/admin/bc-installer/installations/step2');
$this->assertResponseCode(200);

$this->post('/baser/admin/bc-installer/installations/step2', ['mode'=>'next']);
$this->assertResponseCode(302);

Configure::write("BcEnv.isInstalled", true);
}

/**
* Step 3: データベースの接続設定
*/
public function testStep3()
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
$this->enableSecurityToken();
$this->enableCsrfToken();
Configure::write("BcEnv.isInstalled", false);

$this->get('/baser/admin/bc-installer/installations/step3');
$this->assertResponseCode(200);

$config = [
'mode' => 'back',
'dbType' => 'mysql',
'dbHost' => 'localhost',
'dbPrefix' => '',
'dbPort' => '3306',
'dbUsername' => 'dbUsername',
'dbPassword' => 'dbPassword',
'dbSchema' => 'dbSchema',
'dbName' => 'basercms',
'dbEncoding' => 'utf-8',
'dbDataPattern' => 'BcThemeSample.default'
];

$this->post('/baser/admin/bc-installer/installations/step3', $config);
$this->assertResponseCode(302);
$this->assertRedirect('/baser/admin/bc-installer/installations/step2');

$config['mode'] = 'checkDb';
$this->post('/baser/admin/bc-installer/installations/step3', $config);
$this->assertResponseCode(200);

$config['mode'] = 'createDb';
$this->post('/baser/admin/bc-installer/installations/step3', $config);
$this->assertResponseCode(200);


Configure::write("BcEnv.isInstalled", true);
}

/**
Expand Down