Skip to content

Commit

Permalink
fix #1938 テーマ設定 API 取得 (#1940)
Browse files Browse the repository at this point in the history
Co-authored-by: Đỗ Văn Hùng <HungDV2022>
Co-authored-by: ryuring <egashira@catchup.co.jp>
  • Loading branch information
HungDV2022 and ryuring committed Mar 12, 2023
1 parent dbeb08c commit b892a1d
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,15 @@ class ThemeConfigsController extends BcApiController
* @param ThemeConfigsServiceInterface $service
* @checked
* @noTodo
* @unitTest
*/
public function view(ThemeConfigsServiceInterface $service)
{
//todo [API] 取得
$this->request->allowMethod(['get']);
$this->set([
'themeConfig' => $service->get()
]);
$this->viewBuilder()->setOption('serialize', ['themeConfig']);
}

/**
Expand Down
34 changes: 34 additions & 0 deletions plugins/bc-theme-config/tests/Scenario/ThemeConfigsScenario.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* baserCMS : Based Website Development Project <https://basercms.net>
* Copyright (c) NPO baser foundation <https://baserfoundation.org/>
*
* @copyright Copyright (c) NPO baser foundation
* @link https://basercms.net baserCMS Project
* @since 5.0.0
* @license https://basercms.net/license/index.html MIT License
*/

namespace BcThemeConfig\Test\Scenario;

use BcThemeConfig\Test\Factory\ThemeConfigFactory;
use CakephpFixtureFactories\Scenario\FixtureScenarioInterface;

/**
* 利用する場合は、テーブルの初期化に次のフィクスチャの定義が必要
* - plugin.BcThemeConfig.Factory/ThemeConfigs
*/
class ThemeConfigsScenario implements FixtureScenarioInterface
{

/**
* load
*/
public function load(...$args)
{
ThemeConfigFactory::make(['name' => 'color_main', 'value' => '001800'])->persist();
ThemeConfigFactory::make(['name' => 'color_sub', 'value' => '001800'])->persist();
ThemeConfigFactory::make(['name' => 'color_link', 'value' => '2B7BB9'])->persist();
ThemeConfigFactory::make(['name' => 'color_hover', 'value' => '2B7BB9'])->persist();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use BaserCore\Test\Scenario\InitAppScenario;
use BaserCore\TestSuite\BcTestCase;
use BcThemeConfig\Test\Scenario\ThemeConfigsScenario;
use CakephpFixtureFactories\Scenario\ScenarioAwareTrait;
use Cake\TestSuite\IntegrationTestTrait;

Expand Down Expand Up @@ -81,7 +82,18 @@ public function tearDown(): void
*/
public function test_view()
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
//データを生成
$this->loadFixtureScenario(ThemeConfigsScenario::class);
//APIをコル
$this->get('/baser/api/bc-theme-config/theme_configs/view.json?token=' . $this->accessToken);
//ステータスを確認
$this->assertResponseOk();
//戻る値を確認
$result = json_decode((string)$this->_response->getBody());
//全て4件を取得できるか確認
$this->assertCount(4, get_object_vars($result->themeConfig));
//単位Objectの値を確認
$this->assertEquals('2B7BB9', $result->themeConfig->color_hover);
}

/**
Expand Down

0 comments on commit b892a1d

Please sign in to comment.