Skip to content

Commit

Permalink
Fix FormType testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
nanasess committed Jan 11, 2018
1 parent 6c60ed5 commit 53c20b9
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 89 deletions.
15 changes: 4 additions & 11 deletions src/Eccube/Form/Type/Admin/CategoryType.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,13 @@
class CategoryType extends AbstractType
{
/**
* @Inject("config")
* @var array
*/
protected $appConfig;
protected $eccubeConfig;


/**
* @var \Eccube\Application $app
* @Inject(Application::class)
*/
protected $app;

public function __construct()
public function __construct($eccubeConfig)
{
$this->eccubeConfig = $eccubeConfig;
}

/**
Expand All @@ -66,7 +59,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'constraints' => array(
new Assert\NotBlank(),
new Assert\Length(array(
'max' => $this->appConfig['stext_len'],
'max' => $this->eccubeConfig['stext_len'],
)),
),
))
Expand Down
6 changes: 6 additions & 0 deletions tests/Eccube/Tests/EccubeTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ abstract class EccubeTestCase extends WebTestCase
*/
protected $entityManager;

/**
* @var array
*/
protected $eccubeConfig;

/**
* Applicaiton を生成しトランザクションを開始する.
*/
Expand All @@ -53,6 +58,7 @@ public function setUp()
$this->container = $this->client->getContainer();
$this->entityManager = $this->container->get('doctrine')->getManager();
$this->entityManager->getConnection()->beginTransaction();
$this->eccubeConfig = $this->container->getParameter('eccube.constants');
}

/**
Expand Down
11 changes: 11 additions & 0 deletions tests/Eccube/Tests/Form/Type/AbstractTypeTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,18 @@

use Eccube\Tests\EccubeTestCase;
use Symfony\Component\Form\Test\TypeTestCase;
use Symfony\Component\Form\FormFactoryInterface;

abstract class AbstractTypeTestCase extends EccubeTestCase
{
/**
* @var FormFactoryInterface
*/
protected $formFactory;

public function setUp()
{
parent::setUp();
$this->formFactory = $this->container->get('form.factory');
}
}
13 changes: 6 additions & 7 deletions tests/Eccube/Tests/Form/Type/AddressTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@ class AddressTypeTest extends AbstractTypeTestCase

public function setUp()
{
$this->markTestIncomplete(get_class($this).' は未実装です');
parent::setUp();

$this->form = $this->app['form.factory']
$this->form = $this->formFactory
->createBuilder(FormType::class, null, ['csrf_protection' => false])
->add('address', AddressType::class)
->getForm();
Expand All @@ -68,7 +67,7 @@ public function testInvalidData_Addr01_MaxLength()
$data = array(
'address' => array(
'pref' => '1',
'addr01' => str_repeat('', $this->app['config']['address1_len']+1),
'addr01' => str_repeat('', $this->eccubeConfig['address1_len']+1),
'addr02' => 'にゅうりょく',
));

Expand All @@ -82,7 +81,7 @@ public function testInvalidData_Addr02_MaxLength()
'address' => array(
'pref' => '1',
'addr01' => 'にゅうりょく',
'addr02' => str_repeat('', $this->app['config']['address2_len']+1),
'addr02' => str_repeat('', $this->eccubeConfig['address2_len']+1),
));

$this->form->submit($data);
Expand All @@ -107,7 +106,7 @@ public function testInvalidData_Pref_NonexistentValue()

public function testRequiredAddNotBlank_Pref()
{
$this->form = $this->app['form.factory']
$this->form = $this->formFactory
->createBuilder(FormType::class, null, ['csrf_protection' => false])
->add('address', AddressType::class, array(
'required' => true,
Expand All @@ -123,7 +122,7 @@ public function testRequiredAddNotBlank_Pref()

public function testRequiredAddNotBlank_Addr01()
{
$this->form = $this->app['form.factory']
$this->form = $this->formFactory
->createBuilder(FormType::class, null, ['csrf_protection' => false])
->add('address', AddressType::class, array(
'required' => true,
Expand All @@ -139,7 +138,7 @@ public function testRequiredAddNotBlank_Addr01()

public function testRequiredAddNotBlank_Addr02()
{
$this->form = $this->app['form.factory']
$this->form = $this->formFactory
->createBuilder(FormType::class, null, ['csrf_protection' => false])
->add('address', AddressType::class, array(
'required' => true,
Expand Down
7 changes: 3 additions & 4 deletions tests/Eccube/Tests/Form/Type/Admin/CategoryTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,10 @@ class CategoryTypeTest extends \Eccube\Tests\Form\Type\AbstractTypeTestCase

public function setUp()
{
$this->markTestIncomplete(get_class($this).' は未実装です');
parent::setUp();

// CSRF tokenを無効にしてFormを作成
$this->form = $this->app['form.factory']
$this->form = $this->formFactory
->createBuilder(CategoryType::class, null, array(
'csrf_protection' => false,
))
Expand Down Expand Up @@ -77,7 +76,7 @@ public function testInvalidName_SptabCheck()

public function testInvalidName_MaxLengthInvalid()
{
$str = str_repeat('S', $this->app['config']['stext_len']) . 'S';
$str = str_repeat('S', $this->eccubeConfig['stext_len']) . 'S';

$this->formData['name'] = $str;
$this->form->submit($this->formData);
Expand All @@ -87,7 +86,7 @@ public function testInvalidName_MaxLengthInvalid()

public function testInvalidName_MaxLengthValid()
{
$str = str_repeat('S', $this->app['config']['stext_len']);
$str = str_repeat('S', $this->eccubeConfig['stext_len']);

$this->formData['name'] = $str;
$this->form->submit($this->formData);
Expand Down
3 changes: 1 addition & 2 deletions tests/Eccube/Tests/Form/Type/Front/ContactTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,10 @@ class ContactTypeTest extends \Eccube\Tests\Form\Type\AbstractTypeTestCase

public function setUp()
{
$this->markTestIncomplete(get_class($this).' は未実装です');
parent::setUp();

// CSRF tokenを無効にしてFormを作成
$this->form = $this->app['form.factory']
$this->form = $this->formFactory
->createBuilder(ContactType::class, null, array(
'csrf_protection' => false,
))
Expand Down
55 changes: 0 additions & 55 deletions tests/Eccube/Tests/Form/Type/Install/AbstractTypeTestCase.php

This file was deleted.

7 changes: 2 additions & 5 deletions tests/Eccube/Tests/Form/Type/Install/Step1TypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@
namespace Eccube\Tests\Form\Type\Install;

use Eccube\Form\Type\Install\Step1Type;
use Eccube\Tests\Form\Type\AbstractTypeTestCase;

class Step1TypeTest extends AbstractTypeTestCase
{
/** @var \Eccube\Application */
protected $app;

/** @var \Symfony\Component\Form\FormInterface */
protected $form;

Expand Down Expand Up @@ -70,10 +68,9 @@ public function getValidTestData()

public function setUp()
{
$this->markTestIncomplete(get_class($this).' は未実装です');
parent::setUp();

$this->form = $this->app['form.factory']
$this->form = $this->formFactory
->createBuilder(Step1Type::class, null, ['csrf_protection' => false])
->getForm();
}
Expand Down
1 change: 1 addition & 0 deletions tests/Eccube/Tests/Form/Type/Install/Step3TypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
namespace Eccube\Tests\Form\Type\Install;

use Eccube\Form\Type\Install\Step3Type;
use Eccube\Tests\Form\Type\AbstractTypeTestCase;

class Step3TypeTest extends AbstractTypeTestCase
{
Expand Down
1 change: 1 addition & 0 deletions tests/Eccube/Tests/Form/Type/Install/Step4TypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
namespace Eccube\Tests\Form\Type\Install;

use Eccube\Form\Type\Install\Step4Type;
use Eccube\Tests\Form\Type\AbstractTypeTestCase;

class Step4TypeTest extends AbstractTypeTestCase
{
Expand Down
1 change: 1 addition & 0 deletions tests/Eccube/Tests/Form/Type/Install/Step5TypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
namespace Eccube\Tests\Form\Type\Install;

use Eccube\Form\Type\Install\Step5Type;
use Eccube\Tests\Form\Type\AbstractTypeTestCase;

class Step5TypeTest extends AbstractTypeTestCase
{
Expand Down
6 changes: 1 addition & 5 deletions tests/Eccube/Tests/Form/Type/NameTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@

class NameTypeTest extends AbstractTypeTestCase
{
/** @var \Eccube\Application */
protected $app;

/** @var \Symfony\Component\Form\FormInterface */
protected $form;

Expand All @@ -46,9 +43,8 @@ class NameTypeTest extends AbstractTypeTestCase

public function setUp()
{
$this->markTestIncomplete(get_class($this).' は未実装です');
parent::setUp();
$this->form = $this->app['form.factory']
$this->form = $this->formFactory
->createBuilder(FormType::class, null, ['csrf_protection' => false])
->add('name', NameType::class)
->getForm();
Expand Down

0 comments on commit 53c20b9

Please sign in to comment.