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

BcThemeConfigHelper::mainImage() ユニットテスト #4055

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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