|
Lines 1-67
Link Here
|
| 1 |
#!/usr/bin/perl |
|
|
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
|
| 6 |
use Test::More tests => 10; |
| 7 |
use Test::Deep; |
| 8 |
|
| 9 |
use C4::Context; |
| 10 |
BEGIN { |
| 11 |
use_ok('C4::Csv'); |
| 12 |
} |
| 13 |
|
| 14 |
my $dbh = C4::Context->dbh; |
| 15 |
$dbh->{AutoCommit} = 0; |
| 16 |
$dbh->{RaiseError} = 1; |
| 17 |
|
| 18 |
$dbh->do('DELETE FROM export_format'); |
| 19 |
|
| 20 |
my $sth = $dbh->prepare(q{ |
| 21 |
INSERT INTO export_format (profile, description, content, type) |
| 22 |
VALUES (?, ?, ?, ?) |
| 23 |
}); |
| 24 |
$sth->execute('MARC', 'MARC profile', '245$a', 'marc'); |
| 25 |
$sth->execute('SQL', 'SQL profile', 'borrowers.surname', 'sql'); |
| 26 |
|
| 27 |
my $all_profiles = C4::Csv::GetCsvProfiles(); |
| 28 |
is(@$all_profiles, 2, 'test getting all CSV profiles'); |
| 29 |
|
| 30 |
my $sql_profiles = C4::Csv::GetCsvProfiles('sql'); |
| 31 |
is(@$sql_profiles, 1, 'test getting SQL CSV profiles'); |
| 32 |
is($sql_profiles->[0]->{profile}, 'SQL', '... and got the right one'); |
| 33 |
my $marc_profiles = C4::Csv::GetCsvProfiles('marc'); |
| 34 |
is(@$marc_profiles, 1, 'test getting MARC CSV profiles'); |
| 35 |
is($marc_profiles->[0]->{profile}, 'MARC', '... and got the right one'); |
| 36 |
|
| 37 |
my $id = C4::Csv::GetCsvProfileId('MARC'); |
| 38 |
my $profile = C4::Csv::GetCsvProfile($id); |
| 39 |
is($profile->{profile}, 'MARC', 'retrieved profile by ID'); |
| 40 |
|
| 41 |
is(C4::Csv::GetCsvProfile(), undef, 'test getting CSV profile but not supplying ID'); |
| 42 |
|
| 43 |
cmp_deeply( |
| 44 |
C4::Csv::GetCsvProfilesLoop(), |
| 45 |
[ |
| 46 |
{ |
| 47 |
export_format_id => ignore(), |
| 48 |
profile => 'MARC', |
| 49 |
}, |
| 50 |
{ |
| 51 |
export_format_id => ignore(), |
| 52 |
profile => 'SQL', |
| 53 |
}, |
| 54 |
], |
| 55 |
'test getting profile loop' |
| 56 |
); |
| 57 |
|
| 58 |
cmp_deeply( |
| 59 |
C4::Csv::GetCsvProfilesLoop('marc'), |
| 60 |
[ |
| 61 |
{ |
| 62 |
export_format_id => ignore(), |
| 63 |
profile => 'MARC', |
| 64 |
}, |
| 65 |
], |
| 66 |
'test getting profile loop for one type' |
| 67 |
); |