3 changed files with 215 additions and 0 deletions
-
90ext/dbase/tests/dbase_get_header_info_001.phpt
-
71ext/dbase/tests/dbase_get_record_with_names_001.phpt
-
54ext/dbase/tests/dbase_pack_001.phpt
@ -0,0 +1,90 @@ |
|||||
|
--TEST-- |
||||
|
dbase_get_header_info() - Basic test |
||||
|
--FILE-- |
||||
|
<?php |
||||
|
|
||||
|
date_default_timezone_set("UTC"); |
||||
|
|
||||
|
$file = dirname(__FILE__) .'/dbase_get_header_info_001.dbf'; |
||||
|
|
||||
|
$def = array( |
||||
|
array("date", "D"), |
||||
|
array("name", "C", 50), |
||||
|
array("email", "C", 128), |
||||
|
array("ismember", "L") |
||||
|
); |
||||
|
|
||||
|
|
||||
|
dbase_create($file, $def); |
||||
|
|
||||
|
if ($db = dbase_open($file, 2)) { |
||||
|
var_dump(dbase_get_header_info($db)); |
||||
|
dbase_close($db); |
||||
|
} |
||||
|
|
||||
|
@unlink($file); |
||||
|
|
||||
|
?> |
||||
|
--EXPECT-- |
||||
|
array(4) { |
||||
|
[0]=> |
||||
|
array(6) { |
||||
|
["name"]=> |
||||
|
string(4) "date" |
||||
|
["type"]=> |
||||
|
string(4) "date" |
||||
|
["length"]=> |
||||
|
int(8) |
||||
|
["precision"]=> |
||||
|
int(0) |
||||
|
["format"]=> |
||||
|
string(3) "%8s" |
||||
|
["offset"]=> |
||||
|
int(1) |
||||
|
} |
||||
|
[1]=> |
||||
|
array(6) { |
||||
|
["name"]=> |
||||
|
string(4) "name" |
||||
|
["type"]=> |
||||
|
string(9) "character" |
||||
|
["length"]=> |
||||
|
int(50) |
||||
|
["precision"]=> |
||||
|
int(0) |
||||
|
["format"]=> |
||||
|
string(5) "%-50s" |
||||
|
["offset"]=> |
||||
|
int(9) |
||||
|
} |
||||
|
[2]=> |
||||
|
array(6) { |
||||
|
["name"]=> |
||||
|
string(5) "email" |
||||
|
["type"]=> |
||||
|
string(9) "character" |
||||
|
["length"]=> |
||||
|
int(128) |
||||
|
["precision"]=> |
||||
|
int(0) |
||||
|
["format"]=> |
||||
|
string(6) "%-128s" |
||||
|
["offset"]=> |
||||
|
int(59) |
||||
|
} |
||||
|
[3]=> |
||||
|
array(6) { |
||||
|
["name"]=> |
||||
|
string(8) "ismember" |
||||
|
["type"]=> |
||||
|
string(7) "boolean" |
||||
|
["length"]=> |
||||
|
int(1) |
||||
|
["precision"]=> |
||||
|
int(0) |
||||
|
["format"]=> |
||||
|
string(3) "%1s" |
||||
|
["offset"]=> |
||||
|
int(187) |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,71 @@ |
|||||
|
--TEST-- |
||||
|
dbase_get_record_with_names() - Basic test |
||||
|
--FILE-- |
||||
|
<?php |
||||
|
|
||||
|
date_default_timezone_set("UTC"); |
||||
|
|
||||
|
$file = dirname(__FILE__) .'/dbase_get_record_with_names.dbf'; |
||||
|
|
||||
|
$def = array( |
||||
|
array("date", "D"), |
||||
|
array("name", "C", 50), |
||||
|
array("email", "C", 128), |
||||
|
array("ismember", "L") |
||||
|
); |
||||
|
|
||||
|
|
||||
|
dbase_create($file, $def); |
||||
|
|
||||
|
if ($db = dbase_open($file, 2)) { |
||||
|
dbase_add_record($db, array( |
||||
|
date('Ymd'), |
||||
|
'Name #1', |
||||
|
'Email #1', |
||||
|
'T')); |
||||
|
dbase_delete_record($db, 1); |
||||
|
var_dump(dbase_get_record_with_names($db, 1)); |
||||
|
|
||||
|
dbase_add_record($db, array( |
||||
|
date('Ymd'), |
||||
|
'Name #2', |
||||
|
'Email #2', |
||||
|
'T')); |
||||
|
var_dump(dbase_get_record_with_names($db, 2)); |
||||
|
|
||||
|
var_dump(dbase_numrecords($db)); |
||||
|
var_dump(dbase_numfields($db)); |
||||
|
|
||||
|
dbase_close($db); |
||||
|
} |
||||
|
|
||||
|
@unlink($file); |
||||
|
|
||||
|
?> |
||||
|
--EXPECTF-- |
||||
|
array(5) { |
||||
|
["date"]=> |
||||
|
string(8) "%d" |
||||
|
["name"]=> |
||||
|
string(50) "Name #1 " |
||||
|
["email"]=> |
||||
|
string(128) "Email #1 " |
||||
|
["ismember"]=> |
||||
|
int(1) |
||||
|
["deleted"]=> |
||||
|
int(1) |
||||
|
} |
||||
|
array(5) { |
||||
|
["date"]=> |
||||
|
string(8) "%d" |
||||
|
["name"]=> |
||||
|
string(50) "Name #2 " |
||||
|
["email"]=> |
||||
|
string(128) "Email #2 " |
||||
|
["ismember"]=> |
||||
|
int(1) |
||||
|
["deleted"]=> |
||||
|
int(0) |
||||
|
} |
||||
|
int(2) |
||||
|
int(4) |
||||
@ -0,0 +1,54 @@ |
|||||
|
--TEST-- |
||||
|
dbase_pack() - Basic test |
||||
|
--FILE-- |
||||
|
<?php |
||||
|
|
||||
|
date_default_timezone_set("UTC"); |
||||
|
|
||||
|
$file = dirname(__FILE__) .'/dbase_get_header_info_001.dbf'; |
||||
|
|
||||
|
$def = array( |
||||
|
array("date", "D"), |
||||
|
array("name", "C", 50), |
||||
|
array("email", "C", 128), |
||||
|
array("ismember", "L") |
||||
|
); |
||||
|
|
||||
|
|
||||
|
dbase_create($file, $def); |
||||
|
|
||||
|
if ($db = dbase_open($file, 2)) { |
||||
|
dbase_add_record($db, array( |
||||
|
date('Ymd'), |
||||
|
'Name #1', |
||||
|
'Email #1', |
||||
|
'T')); |
||||
|
dbase_delete_record($db, 1); |
||||
|
var_dump(dbase_get_record($db, 1)); |
||||
|
|
||||
|
dbase_pack($db); |
||||
|
|
||||
|
var_dump(dbase_get_record($db, 1)); |
||||
|
|
||||
|
dbase_close($db); |
||||
|
} |
||||
|
|
||||
|
@unlink($file); |
||||
|
|
||||
|
?> |
||||
|
--EXPECTF-- |
||||
|
array(5) { |
||||
|
[0]=> |
||||
|
string(8) "%d" |
||||
|
[1]=> |
||||
|
string(50) "Name #1 " |
||||
|
[2]=> |
||||
|
string(128) "Email #1 " |
||||
|
[3]=> |
||||
|
int(1) |
||||
|
["deleted"]=> |
||||
|
int(1) |
||||
|
} |
||||
|
|
||||
|
Warning: dbase_get_record(): Tried to read bad record 1 in %s on line %d |
||||
|
bool(false) |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue