DBD-PO
view release on metacpan or search on metacpan
t/03_DBD-PO/15_header_msgstr_hash.t view on Meta::CPAN
# connect
{
$dbh = DBI->connect(
"dbi:PO:f_dir=$PATH;po_eol=\n;po_charset=utf-8",
undef,
undef,
{
RaiseError => 1,
PrintError => 0,
AutoCommit => 1,
},
);
isa_ok($dbh, 'DBI::db', 'connect');
if ($TRACE) {
open my $file, '>', trace_file_name();
$dbh->trace(4, $file);
}
my $result = $dbh->do(<<"EO_SQL");
CREATE TABLE $TABLE_15 (
msgid VARCHAR,
msgstr VARCHAR
)
EO_SQL
is($result, '0E0', 'create table');
ok(-e $FILE_15, 'table file found');
}
# add header
{
my $msgstr = $dbh->func(
undef,
'build_header_msgstr',
);
my $result = $dbh->do(<<"EO_SQL", undef, $msgstr);
INSERT INTO $TABLE_15 (
msgstr
) VALUES (?)
EO_SQL
is($result, 1, 'add header');
}
# prepare
{
$sth_update = $dbh->prepare(<<"EOT");
UPDATE $TABLE_15
SET msgstr=?
WHERE msgid=''
EOT
isa_ok($sth_update, 'DBI::st', 'prepare update');
$sth_select = $dbh->prepare(<<"EOT");
SELECT msgstr
FROM $TABLE_15
WHERE msgid=''
EOT
isa_ok($sth_update, 'DBI::st', 'prepare select');
}
sub update_header {
my $name = shift;
my ($test_keys, $test_values) = @{ $test_data{$name} };
my %params;
@params{ @{$test_keys} } = @{$test_values};
my $msgstr = $dbh->func(
\%params,
'build_header_msgstr',
);
my $result = $sth_update->execute($msgstr);
is($result, 1, "execute update header ($name)");
return;
}
sub check_table_file {
my $name = shift;
my %test_of = map {$_ => 1} @{ $test_data{$name}->[0] };
my $po = <<"EOT";
msgid ""
msgstr ""
EOT
$po .= <<"EOT" if $test_of{'Project-Id-Version'};
"Project-Id-Version: MyProject\\n"
EOT
$po .= <<"EOT" if $test_of{'Report-Msgid-Bugs-To-Mail'};
"Report-Msgid-Bugs-To: <report.msgid.bugs.to\@example.com>\\n"
EOT
$po .= <<"EOT" if $test_of{'Last-Translator-Mail'};
"Last-Translator: <last.translator\@example.com>\\n"
EOT
$po .= <<"EOT";
"MIME-Version: 1.0\\n"
"Content-Type: text/plain; charset=utf-8\\n"
EOT
$po .= <<"EOT" if ! $test_of{extended};
"Content-Transfer-Encoding: 8bit"
EOT
$po .= <<"EOT" if $test_of{extended};
"Content-Transfer-Encoding: 8bit\\n"
"Extended-1: extended_1\\n"
"Extended-2: extended_2"
EOT
local $INPUT_RECORD_SEPARATOR = ();
open my $file1, '< :encoding(utf-8)', $FILE_15 or croak $OS_ERROR;
my $content1 = <$file1>;
open my $file2, '< :encoding(utf-8)', \($po) or croak $OS_ERROR;
my $content2 = <$file2>;
eq_or_diff($content1, $content2, "check po file ($name)");
return;
}
( run in 2.294 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )