7 use Test::More tests => 12;
10 use_ok('Koha::Database');
14 ok( $database = Koha::Database->new(), 'Created Koha::Database Object' );
17 ok( $schema = $database->schema(), 'Get a schema' );
19 ok( $dbh = $schema->storage->dbh(), 'Get an old fashioned DBI dbh handle' );
20 ok( $schema->storage->connected(), 'Check our db connection is active' );
21 is( ref($schema), 'Koha::Schema', 'Koha::Database->new->schema should return a Koha::Schema' );
22 my $another_schema = $database->schema();
23 is( $another_schema->storage->_conn_pid, $schema->storage->_conn_pid, 'Getting another schema should return the same one, it has correctly been cached' );
24 $another_schema = Koha::Database->new->schema();
25 is( $another_schema->storage->_conn_pid, $schema->storage->_conn_pid, 'Getting another schema should return the same one, it has correctly been cached' );
28 ok( $new_schema = $database->new_schema(), 'Try to get a new schema' );
29 ok( $database->set_schema($new_schema), 'Switch to new schema' );
30 ok( $database->restore_schema(), 'Switch back' );
32 # run in a transaction
33 $schema->storage->txn_begin();
36 $schema->resultset('Category')->search({ categorycode => 'GIFT-RUS' })->delete;
38 $schema->resultset('Category')->create({
39 categorycode => 'GIFT-RUS',
42 my $desc = $schema->resultset('Category')->search({
43 categorycode => 'GIFT-RUS',
44 })->single->get_column('description');
45 is($desc, $gift, 'stored and retrieved UTF8 string');
46 $schema->storage->txn_rollback();