Skip to content

Commit

Permalink
Merge pull request #264 from nanasess/add-sccheckerrortest
Browse files Browse the repository at this point in the history
SC_CheckError のテストケースを充実させる
  • Loading branch information
Chihiro Adachi authored May 21, 2019
2 parents aebcb97 + 9bfcf92 commit 2b69746
Show file tree
Hide file tree
Showing 56 changed files with 4,544 additions and 328 deletions.
6 changes: 3 additions & 3 deletions data/class/SC_CheckError.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,9 +432,9 @@ public function MIN_LENGTH_CHECK($value)
}

/**
* 最大文字数制限の判定
* 最大数制限の判定
*
* 入力が最大数以上ならエラーを返す
* 入力が最大数より大きければエラーを返す
* @param array $value value[0] = 項目名
* value[1] = 判定対象文字列
* value[2] = 最大数
Expand Down Expand Up @@ -1749,7 +1749,7 @@ public function createParam($value)
*
* @access private
* @param string $string チェックする文字列
* @return boolean 値が10進数の数値表現のみの場合 true
* @return boolean 値が10進数の数値表現以外の場合 true
*/
public function numelicCheck($string)
{
Expand Down
115 changes: 115 additions & 0 deletions tests/class/SC_CheckError/SC_CheckError_ALL_EXIST_CHECKTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?php

class SC_CheckError_ALL_EXIST_CHECKTest extends SC_CheckError_AbstractTestCase
{
/** @var string */
const FORM_NAME1 = 'year';
/** @var string */
const FORM_NAME2 = 'month';
/** @var string */
const FORM_NAME3 = 'day';

protected function setUp()
{
parent::setUp();
$this->target_func = 'ALL_EXIST_CHECK';
}

public function testALL_EXIST_CHECK()
{
$this->arrForm = [
self::FORM_NAME1 => 2019,
self::FORM_NAME2 => '05',
self::FORM_NAME3 => 'a'
];
$this->expected = [];

$this->scenario();
$this->verify();
}


public function testALL_EXIST_CHECKWithEmpty()
{
$this->arrForm = [
self::FORM_NAME1 => '',
self::FORM_NAME2 => '',
self::FORM_NAME3 => ''
];
$this->expected = [];

$this->scenario();
$this->verify();
}

public function testALL_EXIST_CHECKWithNull()
{
$this->arrForm = [
self::FORM_NAME1 => 'a',
self::FORM_NAME2 => null,
self::FORM_NAME3 => null
];
$this->expected = [
self::FORM_NAME1 => '※ ALL_EXIST_CHECKは全ての項目を入力して下さい。<br />'
];

$this->scenario();
$this->verify();
}

public function testALL_EXIST_CHECKWithZero()
{
$this->arrForm = [
self::FORM_NAME1 => '0',
self::FORM_NAME2 => '0',
self::FORM_NAME3 => '0'
];
$this->expected = [];

$this->scenario();
$this->verify();
}

public function testALL_EXIST_CHECKWithErrorExists()
{
$this->arrForm = [
self::FORM_NAME1 => 'a',
self::FORM_NAME2 => '',
self::FORM_NAME3 => ''
];
$this->objErr = new SC_CheckError_Ex($this->arrForm);
$this->objErr->doFunc(
['label', self::FORM_NAME1, self::FORM_NAME2, self::FORM_NAME3],
[
'NUM_CHECK',
$this->target_func
]
);

$this->expected = [
self::FORM_NAME1 => '※ labelは数字で入力してください。<br />'
];

$this->verify('既存のエラーがある場合はエラーチェックしない');
}

/**
* {@inheritdoc}
*/
public function scenario()
{
$this->objErr = new SC_CheckError_Ex($this->arrForm);
$this->objErr->doFunc([$this->target_func, self::FORM_NAME1, self::FORM_NAME2, self::FORM_NAME3], [$this->target_func]);
}

/**
* {@inheritdoc}
*/
protected function verify($message = '')
{
$this->actual = $this->objErr->arrErr;

$this->assertEquals($this->expected, $this->actual, $message);
}
}

66 changes: 66 additions & 0 deletions tests/class/SC_CheckError/SC_CheckError_ALNUM_CHECKTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

class SC_CheckError_ALNUM_CHECKTest extends SC_CheckError_AbstractTestCase
{
protected function setUp()
{
parent::setUp();
$this->target_func = 'ALNUM_CHECK';
}

public function testALNUM_CHECK()
{
/** @var Faker\Generator $faker */
$faker = Faker\Factory::create('ja_JP');

$this->arrForm = [self::FORM_NAME => $faker->bothify('##??')];
$this->expected = '';

$this->scenario();
$this->verify();
}

/**
* 数値型入力のテスト.
*
* フォームからの入力で数値型(int)が入力されることは無いが
* 入力があるとエラーになってしまう
*/
public function testALNUM_CHECKWithNumber()
{
$this->markTestIncomplete('数値型はサポートされていません');
$this->arrForm = [self::FORM_NAME => 5];
$this->expected = '※ ALNUM_CHECKは英数字で入力してください。<br />';

$this->scenario();
$this->verify();
}

public function testALNUM_CHECKWithEmpty()
{
$this->arrForm = [self::FORM_NAME => ''];
$this->expected = '';

$this->scenario();
$this->verify();
}

public function testALNUM_CHECKWithNull()
{
$this->arrForm = [self::FORM_NAME => null];
$this->expected = '';

$this->scenario();
$this->verify();
}

public function testALNUM_CHECKWithSpecial()
{
$this->arrForm = [self::FORM_NAME => 'a1.'];
$this->expected = '※ ALNUM_CHECKは英数字で入力してください。<br />';

$this->scenario();
$this->verify();
}
}

84 changes: 84 additions & 0 deletions tests/class/SC_CheckError/SC_CheckError_ALPHA_CHECKTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

class SC_CheckError_ALPHA_CHECKTest extends SC_CheckError_AbstractTestCase
{
protected function setUp()
{
parent::setUp();
$this->target_func = 'ALPHA_CHECK';
}

public function testALPHA_CHECK()
{
$this->arrForm = [self::FORM_NAME => 'a'];
$this->expected = '';

$this->scenario();
$this->verify();
}


public function testALPHA_CHECKWithNumber()
{
$this->arrForm = [self::FORM_NAME => 5];
$this->expected = '※ ALPHA_CHECKは半角英字で入力してください。<br />';

$this->scenario();
$this->verify();
}

public function testALPHA_CHECKWithEmpty()
{
$this->arrForm = [self::FORM_NAME => ''];
$this->expected = '';

$this->scenario();
$this->verify();
}

public function testALPHA_CHECKWithNull()
{
$this->arrForm = [self::FORM_NAME => null];
$this->expected = '';

$this->scenario();
$this->verify();
}

public function testALPHA_CHECKWithNumbeOfString()
{
$this->arrForm = [self::FORM_NAME => '5'];
$this->expected = '※ ALPHA_CHECKは半角英字で入力してください。<br />';

$this->scenario();
$this->verify();
}

public function testALPHA_CHECKWithFloat()
{
$this->arrForm = [self::FORM_NAME => 1.1];
$this->expected = '※ ALPHA_CHECKは半角英字で入力してください。<br />';

$this->scenario();
$this->verify();
}

public function testALPHA_CHECKWithWideAlpha()
{
$this->arrForm = [self::FORM_NAME => ''];
$this->expected = '※ ALPHA_CHECKは半角英字で入力してください。<br />';

$this->scenario();
$this->verify();
}

public function testALPHA_CHECKWithSpecial()
{
$this->arrForm = [self::FORM_NAME => '.'];
$this->expected = '※ ALPHA_CHECKは半角英字で入力してください。<br />';

$this->scenario();
$this->verify();
}
}

41 changes: 41 additions & 0 deletions tests/class/SC_CheckError/SC_CheckError_AbstractTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

abstract class SC_CheckError_AbstractTestCase extends Common_TestCase
{
/**
* Form のパラメータ名.
*
* @var string
*/
const FORM_NAME = 'form';

/** @var string */
protected $target_func;

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

/**
* @var SC_CheckError
*/
protected $objErr;

/**
* Initialize to SC_CheckError
*/
protected function scenario()
{
$this->objErr = new SC_CheckError_Ex($this->arrForm);
$this->objErr->doFunc([$this->target_func, self::FORM_NAME], [$this->target_func]);
$this->objErr->doFunc(['dummy', self::FORM_NAME], [$this->target_func]);
}

/**
* {@inheritdoc}
*/
protected function verify($message = '')
{
$this->actual = $this->objErr->arrErr[self::FORM_NAME];
parent::verify($message);
}
}
Loading

0 comments on commit 2b69746

Please sign in to comment.