-
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 #223 from nobuhiko/add-test#222
fgetcsvのテストを追加
- Loading branch information
Showing
3 changed files
with
154 additions
and
4 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
133 changes: 133 additions & 0 deletions
133
tests/class/pages/admin/products/LC_Page_Admin_Products_UploadCSVTest.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,133 @@ | ||
<?php | ||
|
||
$HOME = realpath(dirname(__FILE__)) . "/../../../../.."; | ||
require_once($HOME . "/tests/class/Common_TestCase.php"); | ||
/** | ||
* | ||
*/ | ||
class LC_Page_Admin_Products_UploadCSVTest extends Common_TestCase | ||
{ | ||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
if ('\\' !== DIRECTORY_SEPARATOR) { | ||
$this->markTestSkipped('Windows only'); | ||
} | ||
} | ||
|
||
protected function tearDown() | ||
{ | ||
parent::tearDown(); | ||
// ロケールを初期化する | ||
$initial = new SC_Initial(); | ||
$initial->phpconfigInit(); | ||
} | ||
|
||
public function test日本語ロケールで商品csvアップロード() | ||
{ | ||
// 日本語版 Windows のロケールを設定する | ||
setLocale(LC_ALL, 'Japanese_Japan.932'); | ||
|
||
$HOME = realpath(dirname(__FILE__)) . "/../../../../.."; | ||
$filepath = $HOME . "/tests/product.csv"; | ||
$enc_filepath = SC_Utils_Ex::sfEncodeFile($filepath, CHAR_CODE, CSV_TEMP_REALDIR); | ||
|
||
$fp = fopen($enc_filepath, 'r'); | ||
|
||
$line_count = 0; | ||
while (!feof($fp)) { | ||
$arrCSV = fgetcsv($fp, CSV_LINE_MAX); | ||
// 空行はスキップ | ||
if (empty($arrCSV)) { | ||
continue; | ||
} | ||
// 行カウント | ||
$line_count++; | ||
|
||
$this->expected = 71; | ||
$this->assertNotCount($this->expected, $arrCSV, '日本語のロケールでは '.$line_count.' 列目の行数が不正になるはず'); | ||
|
||
// ヘッダ行はスキップ | ||
if ($line_count == 1) { | ||
continue; | ||
} | ||
} | ||
fclose($fp); | ||
|
||
$this->expected = 10; | ||
$this->actual = $line_count; | ||
|
||
$this->verify('列数'); | ||
} | ||
|
||
public function testSC_Initialのロケールで商品csvアップロード() | ||
{ | ||
$HOME = realpath(dirname(__FILE__)) . "/../../../../.."; | ||
$filepath = $HOME . "/tests/product.csv"; | ||
$enc_filepath = SC_Utils_Ex::sfEncodeFile($filepath, CHAR_CODE, CSV_TEMP_REALDIR); | ||
|
||
$fp = fopen($enc_filepath, 'r'); | ||
|
||
$line_count = 0; | ||
while (!feof($fp)) { | ||
$arrCSV = fgetcsv($fp, CSV_LINE_MAX); | ||
// 空行はスキップ | ||
if (empty($arrCSV)) { | ||
continue; | ||
} | ||
// 行カウント | ||
$line_count++; | ||
|
||
$this->expected = 71; | ||
$this->assertCount($this->expected, $arrCSV, $line_count.' 列目の行数は一致する'); | ||
|
||
// ヘッダ行はスキップ | ||
if ($line_count == 1) { | ||
continue; | ||
} | ||
} | ||
fclose($fp); | ||
|
||
$this->expected = 10; | ||
$this->actual = $line_count; | ||
|
||
$this->verify('列数'); | ||
} | ||
|
||
public function test英語のロケールで商品csvアップロード() | ||
{ | ||
// 英語版 Windows のロケールを設定する | ||
setlocale(LC_ALL, 'English_United States.1252'); | ||
|
||
$HOME = realpath(dirname(__FILE__)) . "/../../../../.."; | ||
$filepath = $HOME . "/tests/product.csv"; | ||
$enc_filepath = SC_Utils_Ex::sfEncodeFile($filepath, CHAR_CODE, CSV_TEMP_REALDIR); | ||
|
||
$fp = fopen($enc_filepath, 'r'); | ||
|
||
$line_count = 0; | ||
while (!feof($fp)) { | ||
$arrCSV = fgetcsv($fp, CSV_LINE_MAX); | ||
// 空行はスキップ | ||
if (empty($arrCSV)) { | ||
continue; | ||
} | ||
// 行カウント | ||
$line_count++; | ||
|
||
$this->expected = 71; | ||
$this->assertCount($this->expected, $arrCSV, $line_count.' 列目の行数は一致する'); | ||
|
||
// ヘッダ行はスキップ | ||
if ($line_count == 1) { | ||
continue; | ||
} | ||
} | ||
fclose($fp); | ||
|
||
$this->expected = 10; | ||
$this->actual = $line_count; | ||
|
||
$this->verify('列数'); | ||
} | ||
} |
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,10 @@ | ||
���iID,���i�K�iID,�e�K�i����ID,�K�i����ID,�e�K�i���ޖ�,�K�i���ޖ�,���[�J�[ID,���[�J�[��,���i��,"�\���X�e�[�^�X(���J�E����J)",���[�J�[URL(�R�����g1),�R�����g2,�������[�h(�R�����g3),�R�����g4,�R�����g5,�R�����g6,���l��(SHOP��p),�ꗗ-���C���R�����g,�ꗗ-���C���摜,�ڍ�-���C���R�����g,�ڍ�-���C���摜,�ڍ�-���C���g��摜,�ڍ�-�T�u�^�C�g��(1),�ڍ�-�T�u�R�����g(1),�ڍ�-�T�u�摜(1),�ڍ�-�T�u�g��摜(1),�ڍ�-�T�u�^�C�g��(2),�ڍ�-�T�u�R�����g(2),�ڍ�-�T�u�摜(2),�ڍ�-�T�u�g��摜(2),�ڍ�-�T�u�^�C�g��(3),�ڍ�-�T�u�R�����g(3),�ڍ�-�T�u�摜(3),�ڍ�-�T�u�g��摜(3),�ڍ�-�T�u�^�C�g��(4),�ڍ�-�T�u�R�����g(4),�ڍ�-�T�u�摜(4),�ڍ�-�T�u�g��摜(4),�ڍ�-�T�u�^�C�g��(5),�ڍ�-�T�u�R�����g(5),�ڍ�-�T�u�摜(5),�ڍ�-�T�u�g��摜(5),�������ڈ�ID,�폜�t���O,���i���ID,���i�R�[�h,�ɐ�,�ɖ������t���O,�̔�������,�ʏ퉿�i,�̔����i,����,�|�C���g�t�^��,�_�E�����[�h�t�@�C����,�_�E�����[�h���t�@�C��,�֘A���iID(1),�֘A���i�R�����g(1),�֘A���iID(2),�֘A���i�R�����g(2),�֘A���iID(3),�֘A���i�R�����g(3),�֘A���iID(4),�֘A���i�R�����g(4),�֘A���iID(5),�֘A���i�R�����g(5),�֘A���iID(6),�֘A���i�R�����g(6),���i�X�e�[�^�X,���i�X�e�[�^�X��,�J�e�S��ID,�J�e�S���� | ||
1,1,6,3,S,����,,,�A�C�X�N���[��,1,,,"�A�C�X,�o�j��,�`���R,����",,,,,�����Ăɂǂ����B,ice130.jpg,�₽�����̂͂������ł���?,ice260.jpg,ice500.jpg,,<b>����������<b>,,,,,,,,,,,,,,,,,,,2,0,1,ice-01,,1,,1000,933,,10,,,,,,,,,,,,,,,1,NEW,5,�A�C�X | ||
1,4,6,2,S,�`���R,,,�A�C�X�N���[��,1,,,"�A�C�X,�o�j��,�`���R,����",,,,,�����Ăɂǂ����B,ice130.jpg,�₽�����̂͂������ł���?,ice260.jpg,ice500.jpg,,<b>����������<b>,,,,,,,,,,,,,,,,,,,2,0,1,ice-04,,1,,1000,933,,10,,,,,,,,,,,,,,,1,NEW,5,�A�C�X | ||
1,5,5,2,M,�`���R,,,�A�C�X�N���[��,1,,,"�A�C�X,�o�j��,�`���R,����",,,,,�����Ăɂǂ����B,ice130.jpg,�₽�����̂͂������ł���?,ice260.jpg,ice500.jpg,,<b>����������<b>,,,,,,,,,,,,,,,,,,,2,0,1,ice-05,,1,,1000,933,,10,,,,,,,,,,,,,,,1,NEW,5,�A�C�X | ||
1,6,4,2,L,�`���R,,,�A�C�X�N���[��,1,,,"�A�C�X,�o�j��,�`���R,����",,,,,�����Ăɂǂ����B,ice130.jpg,�₽�����̂͂������ł���?,ice260.jpg,ice500.jpg,,<b>����������<b>,,,,,,,,,,,,,,,,,,,2,0,1,ice-06,,1,,1000,933,,10,,,,,,,,,,,,,,,1,NEW,5,�A�C�X | ||
1,7,6,1,S,�o�j��,,,�A�C�X�N���[��,1,,,"�A�C�X,�o�j��,�`���R,����",,,,,�����Ăɂǂ����B,ice130.jpg,�₽�����̂͂������ł���?,ice260.jpg,ice500.jpg,,<b>����������<b>,,,,,,,,,,,,,,,,,,,2,0,1,ice-07,,1,,1000,933,,10,,,,,,,,,,,,,,,1,NEW,5,�A�C�X | ||
1,8,5,1,M,�o�j��,,,�A�C�X�N���[��,1,,,"�A�C�X,�o�j��,�`���R,����",,,,,�����Ăɂǂ����B,ice130.jpg,�₽�����̂͂������ł���?,ice260.jpg,ice500.jpg,,<b>����������<b>,,,,,,,,,,,,,,,,,,,2,0,1,ice-08,,1,,1000,933,,10,,,,,,,,,,,,,,,1,NEW,5,�A�C�X | ||
1,9,4,1,L,�o�j��,,,�A�C�X�N���[��,1,,,"�A�C�X,�o�j��,�`���R,����",,,,,�����Ăɂǂ����B,ice130.jpg,�₽�����̂͂������ł���?,ice260.jpg,ice500.jpg,,<b>����������<b>,,,,,,,,,,,,,,,,,,,2,0,1,ice-09,,1,,1000,933,,10,,,,,,,,,,,,,,,1,NEW,5,�A�C�X | ||
2,10,0,0,,,,,���Ȃ�,1,,,"��,�Ȃ�,�i�x",,,,,��l�p���炠��܂��B,nabe130.jpg,���܂ɂ͓�ł��ǂ��ł��傤�B,nabe260.jpg,nabe500.jpg,,,,,,,,,,,,,,,,,,,,,3,0,1,nabe-01,99,0,5,1700,1650,,10,,,1,���������ɁB,,,,,,,,,,,,,4,�Ȃ� | ||
3,11,0,0,,,,,���Ȃ׃��V�s,1,,,"��,�Ȃ�,�i�x,���V�s,����",,,,,���́A��`�̂��烌�V�s�ł��B,recipe130.jpg,"<b>���̏��i�̓_�E�����[�h���i�ł�</b><br />�����Ń`�������W���Ă݂������ɁB",recipe260.jpg,recipe500.jpg,,,,,,,,,,,,,,,,,,,,,1,0,2,recipe-01,,1,,,100,,10,���Ȃ׃��V�s.pdf,recipe_onabe.pdf,,,,,,,,,,,,,"4,5","�I�X�X��,����i","4,6","�Ȃ�,���V�s" |