Skip to content

Commit

Permalink
Merge pull request #4055 from HungDV2022/unittest_BcThemeConfigHelper…
Browse files Browse the repository at this point in the history
…_mainImage

BcThemeConfigHelper::mainImage() ユニットテスト
  • Loading branch information
HungDV2022 authored Nov 29, 2024
2 parents 9ccb3a4 + 2894f8f commit d92b0b1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class BcThemeConfigHelper extends Helper
* @return void
* @checked
* @noTodo
* @unitTest
*/
public function mainImage($options = [])
{
Expand Down Expand Up @@ -94,6 +95,7 @@ public function mainImage($options = [])
* @return void
* @checked
* @noTodo
* @unitTest
*/
public function logo($options = [])
{
Expand All @@ -120,6 +122,7 @@ public function logo($options = [])
* @return string $tag テーマ画像のHTMLタグ
* @checked
* @noTodo
* @unitTest
*/
public function getThemeImage($name, $options = [])
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,33 @@

namespace BcThemeConfig\Test\TestCase\View\Helper;

use BaserCore\Test\Scenario\InitAppScenario;
use BaserCore\TestSuite\BcTestCase;
use BaserCore\View\BcAdminAppView;
use BcThemeConfig\View\Helper\BcThemeConfigHelper;
use CakephpFixtureFactories\Scenario\ScenarioAwareTrait;

/**
* BcThemeConfigHelperTest
*/
class BcThemeConfigHelperTest extends BcTestCase
{
use ScenarioAwareTrait;

/**
* @var $BcThemeConfigHelper
*/
private $BcThemeConfigHelper;

/**
* set up
*/
public function setUp(): void
{
parent::setUp();
$this->loadFixtureScenario(InitAppScenario::class);
$BcAdminAppView = new BcAdminAppView($this->getRequest('/'));
$this->BcThemeConfigHelper = new BcThemeConfigHelper($BcAdminAppView);
}

/**
Expand All @@ -41,9 +54,10 @@ public function tearDown(): void
*/
public function testLogo()
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
$this->expectOutputRegex('/<img src="\/theme\/nada-icons\/img\/logo.png" alt="baserCMS"\/>/');
$this->BcBaser->logo();
ob_start();
$this->BcThemeConfigHelper->logo();
$result = ob_get_clean();
$this->assertEquals('<img src="/bc_front/img/logo.png" alt="">', $result);
}

/**
Expand All @@ -54,9 +68,10 @@ public function testLogo()
*/
public function testMainImage($options, $expect)
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
$this->expectOutputRegex('/' . $expect . '/s');
$this->BcBaser->mainImage($options);
ob_start();
$this->BcThemeConfigHelper->mainImage($options);
$result = ob_get_clean();
$this->assertEquals($expect, $result);
}

/**
Expand All @@ -78,16 +93,23 @@ public function testMainImage($options, $expect)
public static function mainImageDataProvider()
{
return [
[[], '<img src="\/theme\/nada-icons\/img\/main_image_1.jpg" alt="コーポレートサイトにちょうどいい国産CMS"\/>'],
[['num' => 2], 'main_image_2'],
[['all' => true, 'num' => 2], '^(.*main_image_1.*main_image_2)'],
[['all' => true, 'class' => 'test-class', 'id' => 'test-id'], '^(.*id="test-id".*class="test-class")'],
[['popup' => true], 'href="\/theme\/nada-icons\/img\/main_image_1.jpg"'],
[['alt' => 'テスト'], 'alt="テスト"'],
[['link' => '/test'], 'href="\/test"'],
[['maxWidth' => '200', 'maxHeight' => '200'], 'width="200"'],
[['width' => '200', 'height' => '200'], '^(.*width="200".*height="200")'],
[['hoge' => 'hoge'], 'main_image_1'],
[[], '<img src="/bc_front/img/main_image_1.jpg" alt="">'],
[['num' => 2], '<img src="/bc_front/img/main_image_2.jpg" alt="">'],
[['all' => true, 'num' => 2], '<ul id="MainImage">
<li><img src="/bc_front/img/main_image_1.jpg" alt=""></li>
<li><img src="/bc_front/img/main_image_2.jpg" alt=""></li>
</ul>'],
[['all' => true, 'class' => 'test-class', 'id' => 'test-id'], '<ul id="test-id" class="test-class">
<li><img src="/bc_front/img/main_image_1.jpg" alt=""></li>
</ul>'],
[['popup' => true], '<a href="/bc_front/img/main_image_1.jpg" rel="colorbox"><img src="/bc_front/img/main_image_1.jpg" alt=""></a>'],
[['alt' => 'テスト'], '<img src="/bc_front/img/main_image_1.jpg" alt="テスト">'],
[['link' => '/test'], '<a href="/test"><img src="/bc_front/img/main_image_1.jpg" alt=""></a>'],
[['maxWidth' => '200', 'maxHeight' => '200'], '<img src="/bc_front/img/main_image_1.jpg" width="200" alt="">'],
[['width' => '200', 'height' => '200'], '<img src="/bc_front/img/main_image_1.jpg" width="200" height="200" alt="">'],
[['hoge' => 'hoge'], '<img src="/bc_front/img/main_image_1.jpg" alt="">'],
];
}

Expand Down

0 comments on commit d92b0b1

Please sign in to comment.