-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #264 from nanasess/add-sccheckerrortest
SC_CheckError のテストケースを充実させる
- Loading branch information
Showing
56 changed files
with
4,544 additions
and
328 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
tests/class/SC_CheckError/SC_CheckError_ALL_EXIST_CHECKTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
66
tests/class/SC_CheckError/SC_CheckError_ALNUM_CHECKTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
84
tests/class/SC_CheckError/SC_CheckError_ALPHA_CHECKTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 => 'a']; | ||
$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
41
tests/class/SC_CheckError/SC_CheckError_AbstractTestCase.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.