Bug 19532: (follow-up) aria-hidden attr on OPAC, and more
[koha.git] / t / db_dependent / Installer.t
1 #!/usr/bin/perl
2 #
3 # This file is part of Koha.
4 #
5 # Copyright (C) 2014  Aleisha Amohia (Bug 11541)
6 # Copyright (C) 2016  Mark Tompsett (Bug 17234)
7 #
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20
21 # This Koha test module is still a stub!
22 # Add more tests here!!!
23
24 use Modern::Perl;
25 use Test::More tests => 22;
26 use File::Temp qw(tempfile);
27 use utf8;
28
29 use Koha::Database;
30
31 BEGIN {
32     use_ok('C4::Installer', qw( column_exists index_exists unique_key_exists foreign_key_exists primary_key_exists marc_framework_sql_list ));
33 }
34
35 ok( my $installer = C4::Installer->new(), 'Testing NewInstaller' );
36 is( ref $installer, 'C4::Installer', 'Testing class of object' );
37 is( $installer->{'dbname'}, C4::Context->config('database'), 'Testing DbName' );
38 is(
39     $installer->{'dbms'},
40     C4::Context->config('db_scheme')
41     ? C4::Context->config('db_scheme')
42     : 'mysql',
43     'Testing DbScheme'
44 );
45 is(
46     $installer->{'hostname'},
47     C4::Context->config('hostname'),
48     'Testing Hostname'
49 );
50 is( $installer->{'port'},     C4::Context->config('port'), 'Testing Port' );
51 is( $installer->{'user'},     C4::Context->config('user'), 'Testing User' );
52 is( $installer->{'password'}, C4::Context->config('pass'), 'Testing Password' );
53
54 # The borrower table is known to have columns and constraints.
55 my $schema = Koha::Database->new->schema;
56 my $source = $schema->source('Borrower');
57
58 my @column_names = $source->columns();
59 my $column_name  = $column_names[0];
60 ok( column_exists( 'borrowers', $column_name ), 'Known column does exist' );
61 ok( ! column_exists( 'borrowers', 'xxx'), 'Column xxx does not exist' );
62 {
63     ok( ! column_exists( 'this_table_will_never_exist', 'xxx'), 'Column xxx does not exist, the table does not exist' );
64 }
65 my @constraint_names = $source->unique_constraint_names();
66 my $constraint_name  = $constraint_names[0];
67 ok( index_exists( 'borrowers', $constraint_name), 'Known contraint does exist' );
68 ok( ! index_exists( 'borrowers', 'xxx'), 'Constraint xxx does not exist' );
69
70 ok( foreign_key_exists( 'borrowers', 'borrowers_ibfk_1' ), 'FK borrowers_ibfk_1 exists' );
71 ok( ! foreign_key_exists( 'borrowers', 'xxx' ), 'FK xxxx does not exist' );
72
73 ok( unique_key_exists( 'items', 'itembarcodeidx' ), 'UNIQUE KEY itembarcodeidx exists' );
74 ok( ! unique_key_exists( 'borrowers', 'xxx' ), 'UNIQUE KEY xxxx does not exist' );
75
76 ok( primary_key_exists( 'borrowers' ), 'Borrowers does have a primary key on some column');
77 ok( primary_key_exists( 'borrowers', 'borrowernumber'), 'Borrowers has primary key on borrowernumber');
78 ok( ! primary_key_exists( 'borrowers', 'email'), 'Borrowers does not have a primary key on email');
79
80 subtest 'marc_framework_sql_list' => sub {
81     plan tests => 1;
82
83     my ($fh, $filepath) = tempfile( DIR =>  C4::Context->config("intranetdir") . "/installer/data/mysql/en/marcflavour/marc21/mandatory", SUFFIX => '.yml', UNLINK => 1 );
84     print $fh Encode::encode_utf8("---\ndescription:\n    - \"Standardowe typy haseÅ‚ przedmiotowych MARC21\"\n");
85     close $fh;
86
87     my $yaml_files = $installer->marc_framework_sql_list('en', 'MARC21');
88
89     my $description;
90     FILE: for my $file ( @$yaml_files ) {
91         for my $framework ( @{ $file->{frameworks}} ) {
92             if ( $framework->{fwkfile} eq $filepath ) {
93                 $description = $framework->{fwkdescription}->[0];
94                 last FILE;
95             }
96         }
97     }
98     is( $description, 'Standardowe typy haseÅ‚ przedmiotowych MARC21' );
99 };