Skip to content

Commit

Permalink
ユニットテストを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
pineray committed Aug 24, 2022
1 parent 857ca69 commit 1613334
Showing 1 changed file with 113 additions and 0 deletions.
113 changes: 113 additions & 0 deletions tests/Eccube/Tests/Form/Type/Admin/BlockTypeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?php

namespace Eccube\Tests\Form\Type\Admin;

use Eccube\Entity\Master\DeviceType;
use Eccube\Form\Type\Admin\BlockType;
use Symfony\Component\HttpFoundation\Request;

class BlockTypeTest extends \Eccube\Tests\Form\Type\AbstractTypeTestCase
{
/** @var \Symfony\Component\Form\FormInterface */
protected $form;

/** @var array デフォルト値(正常系)を設定 */
protected $formData = [
'name' => 'new/Block_1',
'file_name' => 'file_name',
'block_html' => '<p>test</p>',
'DeviceType' => DeviceType::DEVICE_TYPE_MB,
'id' => 1,
];

protected function setUp(): void
{
parent::setUp();

// CSRF tokenを無効にしてFormを作成
// ブロック登録・編集
$this->form = $this->formFactory
->createBuilder(BlockType::class, null, [
'csrf_protection' => false,
])
->getForm();
self::$container->get('request_stack')->push(new Request());
}

public function testValidData()
{
$this->form->submit($this->formData);
$this->assertTrue($this->form->isValid());
}

public function testInvalidNameBlank()
{
$this->formData['name'] = '';
$this->form->submit($this->formData);
$this->assertFalse($this->form['name']->isValid());
}

public function testInvalidNameMaxLengthInvalid()
{
$str = str_repeat('S', $this->eccubeConfig['eccube_stext_len']).'S';
$this->formData['name'] = $str;

$this->form->submit($this->formData);
$this->assertFalse($this->form['name']->isValid());
}

public function testInvalidNameMaxLengthValid()
{
$str = str_repeat('S', $this->eccubeConfig['eccube_stext_len']);
$this->formData['name'] = $str;

$this->form->submit($this->formData);
$this->assertTrue($this->form['name']->isValid());
}

public function testInvalidFileNameBlank()
{
$this->formData['file_name'] = '';
$this->form->submit($this->formData);
$this->assertFalse($this->form['file_name']->isValid());
}

public function testInvalidFileNameMaxLengthInvalid()
{
$str = str_repeat('S', $this->eccubeConfig['eccube_stext_len']).'S';
$this->formData['file_name'] = $str;

$this->form->submit($this->formData);
$this->assertFalse($this->form['file_name']->isValid());
}

public function testInvalidFileNameMaxLengthValid()
{
$str = str_repeat('S', $this->eccubeConfig['eccube_stext_len']);
$this->formData['file_name'] = $str;

$this->form->submit($this->formData);
$this->assertTrue($this->form['file_name']->isValid());
}

public function testInvalidFileNameCharacter()
{
$this->formData['file_name'] = 'new/Block_1.*{;';
$this->form->submit($this->formData);
$this->assertFalse($this->form['file_name']->isValid());
}

public function testInvalidFileNameContinuousSlashes()
{
$this->formData['file_name'] = 'new//Block_1';
$this->form->submit($this->formData);
$this->assertFalse($this->form['file_name']->isValid());
}

public function testInvalidBlockHtmlBlank()
{
$this->formData['block_html'] = '';
$this->form->submit($this->formData);
$this->assertFalse($this->form['block_html']->isValid());
}
}

0 comments on commit 1613334

Please sign in to comment.