Bug 23681: (QA follow-up) New schema files
[koha.git] / t / db_dependent / RestrictionType.t
1 #!/usr/bin/perl
2
3 use Modern::Perl;
4
5 use C4::Context;
6 use Koha::Database;
7 use t::lib::TestBuilder;
8
9 use Test::More tests => 3;
10
11 my $schema = Koha::Database->new->schema;
12 $schema->storage->txn_begin;
13 my $dbh     = C4::Context->dbh;
14 my $builder = t::lib::TestBuilder->new;
15
16 use_ok('Koha::RestrictionType');
17 use_ok('Koha::RestrictionTypes');
18
19 $dbh->do(q|DELETE FROM borrower_debarments|);
20 $dbh->do(q|DELETE FROM debarment_types|);
21
22 $builder->build(
23     {
24         source => 'DebarmentType',
25         value  => {
26             code         => 'ONE',
27             display_text => 'One',
28             is_system    => 1,
29             is_default   => 0
30         }
31     }
32 );
33 $builder->build(
34     {
35         source => 'DebarmentType',
36         value  => {
37             code         => 'TWO',
38             display_text => 'Two',
39             is_system    => 1,
40             is_default   => 1
41         }
42     }
43 );
44
45 # keyed_on_code
46 my $keyed     = Koha::RestrictionTypes->keyed_on_code;
47 my $expecting = {
48     ONE => {
49         code         => 'ONE',
50         display_text => 'One',
51         is_system    => 1,
52         is_default   => 0
53     },
54     TWO => {
55         code         => 'TWO',
56         display_text => 'Two',
57         is_system    => 1,
58         is_default   => 1
59     }
60 };
61
62 is_deeply( $keyed, $expecting, 'keyed_on_code returns correctly' );
63
64 $schema->storage->txn_rollback;