Koha/t/db_dependent/Koha_Database.t
Galen Charlton b21d16ca75 Bug 11906: regression test for using DBIC to store & fetch UTF8 strings
This patch adds a regression test for verifying that a
DBIx::Class schema object initialized by Koha database sets up
the database connection to correct store and retrieve UTF8
values as Perl utf8 strings.

To test:

[1] Apply this patch.
[2] Run prove -v t/db_dependent/Koha_Database.t
[3] The test should fail.
[4] Apply the main patch for this bug, then do step 2 again.
[5] The test should pass.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>

Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
2014-03-27 14:44:39 +00:00

42 lines
1.2 KiB
Perl

#!/usr/bin/perl
#
use Modern::Perl;
use utf8;
use Test::More tests => 10;
BEGIN {
use_ok('Koha::Database');
}
my $database;
ok( $database = Koha::Database->new(), 'Created Koha::Database Object' );
my $schema;
ok( $schema = $database->schema(), 'Get a schema' );
my $dbh;
ok( $dbh = $schema->storage->dbh(), 'Get an old fashioned DBI dbh handle' );
ok( $schema->storage->connected(), 'Check our db connection is active' );
ok( $schema = $database->schema(), 'Try and get the same schema' );
my $new_schema;
ok( $new_schema = $database->new_schema(), 'Try to get a new schema' );
ok( $database->set_schema($new_schema), 'Switch to new schema' );
ok( $database->restore_schema(), 'Switch back' );
# run in a transaction
$schema->storage->txn_begin();
# clear the way
$schema->resultset('Category')->search({ categorycode => 'GIFT-RUS' })->delete;
my $gift = 'подарок';
$schema->resultset('Category')->create({
categorycode => 'GIFT-RUS',
description => $gift,
});
my $desc = $schema->resultset('Category')->search({
categorycode => 'GIFT-RUS',
})->single->get_column('description');
is($desc, $gift, 'stored and retrieved UTF8 string');
$schema->storage->txn_rollback();