Lines 30-36
use MARC::Record;
Link Here
|
30 |
use MARC::Field; |
30 |
use MARC::Field; |
31 |
use C4::Context; |
31 |
use C4::Context; |
32 |
use C4::Biblio; |
32 |
use C4::Biblio; |
33 |
use Koha::Cache qw/flush_all/; |
33 |
use Koha::Cache qw/get_instance flush_all/; |
34 |
use Koha::Database; |
34 |
use Koha::Database; |
35 |
|
35 |
|
36 |
BEGIN { |
36 |
BEGIN { |
Lines 60-72
sub run_hiding_tests {
Link Here
|
60 |
|
60 |
|
61 |
my ( $isbn_field, $isbn_subfield ) = |
61 |
my ( $isbn_field, $isbn_subfield ) = |
62 |
GetMarcFromKohaField( 'biblioitems.isbn', q{} ); |
62 |
GetMarcFromKohaField( 'biblioitems.isbn', q{} ); |
63 |
my $update_sql = |
63 |
my $update_sql = q{UPDATE marc_subfield_structure SET hidden=? }; |
64 |
q{UPDATE marc_subfield_structure SET hidden=? } |
64 |
my $sth = $dbh->prepare($update_sql); |
65 |
. q{WHERE tagfield='} |
|
|
66 |
. $isbn_field |
67 |
. q{' OR } |
68 |
. q{ tagfield='008';}; |
69 |
my $sth = $dbh->prepare($update_sql); |
70 |
foreach my $hidden_value (@valid_hidden_values) { |
65 |
foreach my $hidden_value (@valid_hidden_values) { |
71 |
|
66 |
|
72 |
$sth->execute($hidden_value); |
67 |
$sth->execute($hidden_value); |
Lines 99-108
sub run_hiding_tests {
Link Here
|
99 |
if ( any { $_ == $hidden_value } @{ $hidden->{$interface} } ) { |
94 |
if ( any { $_ == $hidden_value } @{ $hidden->{$interface} } ) { |
100 |
|
95 |
|
101 |
# Subfield and controlfield are set to be hidden |
96 |
# Subfield and controlfield are set to be hidden |
102 |
is( $filtered_record->field('020'), |
97 |
is( $filtered_record->field($isbn_field), |
103 |
undef, |
98 |
undef, |
104 |
"Data field has been deleted because of hidden=$hidden_value" ); |
99 |
"Data field has been deleted because of hidden=$hidden_value" ); |
105 |
isnt( $unfiltered_record->field('020'), undef, |
100 |
isnt( $unfiltered_record->field($isbn_field), undef, |
106 |
"Data field has been deleted in the original record because of hidden=$hidden_value" |
101 |
"Data field has been deleted in the original record because of hidden=$hidden_value" |
107 |
); |
102 |
); |
108 |
|
103 |
|
Lines 118-127
sub run_hiding_tests {
Link Here
|
118 |
|
113 |
|
119 |
} |
114 |
} |
120 |
else { |
115 |
else { |
121 |
isnt( $filtered_record->field('020'), undef, |
116 |
isnt( $filtered_record->field($isbn_field), undef, |
122 |
"Data field hasn't been deleted because of hidden=$hidden_value" |
117 |
"Data field hasn't been deleted because of hidden=$hidden_value" |
123 |
); |
118 |
); |
124 |
isnt( $unfiltered_record->field('020'), undef, |
119 |
isnt( $unfiltered_record->field($isbn_field), undef, |
125 |
"Data field hasn't been deleted in the original record because of hidden=$hidden_value" |
120 |
"Data field hasn't been deleted in the original record because of hidden=$hidden_value" |
126 |
); |
121 |
); |
127 |
|
122 |
|
Lines 133-143
sub run_hiding_tests {
Link Here
|
133 |
"Control field hasn't been deleted in the original record because of hidden=$hidden_value" |
128 |
"Control field hasn't been deleted in the original record because of hidden=$hidden_value" |
134 |
); |
129 |
); |
135 |
|
130 |
|
|
|
131 |
# force all the hidden values the same, so filtered and unfiltered |
132 |
# records should be identical. |
136 |
is_deeply( $filtered_record, $unfiltered_record, |
133 |
is_deeply( $filtered_record, $unfiltered_record, |
137 |
'Records are the same' ); |
134 |
'Records are the same' ); |
138 |
} |
135 |
} |
139 |
|
136 |
|
140 |
} |
137 |
} |
|
|
138 |
|
139 |
$sth->execute(-1); # -1 is visible in opac and intranet. |
140 |
|
141 |
my $cache = Koha::Cache->get_instance(); |
142 |
$cache->flush_all(); # easy way to ensure DB is queried again. |
143 |
|
144 |
my $shouldhidemarc = Koha::Filter::MARC::ViewPolicy->should_hide_marc( |
145 |
{ |
146 |
frameworkcode => q{}, |
147 |
interface => $interface |
148 |
} |
149 |
); |
150 |
my @hiddenfields = grep { $shouldhidemarc->{$_}==1 } keys %{$shouldhidemarc}; |
151 |
|
152 |
$sth->execute(8); # 8 is invisible in opac and intranet. |
153 |
|
154 |
$cache->flush_all(); # easy way to ensure DB is queried again. |
155 |
|
156 |
$shouldhidemarc = Koha::Filter::MARC::ViewPolicy->should_hide_marc( |
157 |
{ |
158 |
frameworkcode => q{}, |
159 |
interface => $interface |
160 |
} |
161 |
); |
162 |
my @keyvalues = keys %{$shouldhidemarc}; |
163 |
my @visiblefields = grep { $shouldhidemarc->{$_}==1 } @keyvalues; |
164 |
|
165 |
is(scalar @hiddenfields,0,'Should Hide MARC - Full Visibility'); |
166 |
is_deeply(\@visiblefields,\@keyvalues,'Should Hide MARC - No Visibility'); |
141 |
return; |
167 |
return; |
142 |
} |
168 |
} |
143 |
|
169 |
|
Lines 164-170
sub create_marc_record {
Link Here
|
164 |
|
190 |
|
165 |
subtest 'Koha::Filter::MARC::ViewPolicy opac tests' => sub { |
191 |
subtest 'Koha::Filter::MARC::ViewPolicy opac tests' => sub { |
166 |
|
192 |
|
167 |
plan tests => 102; |
193 |
plan tests => 104; |
168 |
|
194 |
|
169 |
$schema->storage->txn_begin(); |
195 |
$schema->storage->txn_begin(); |
170 |
run_hiding_tests('opac'); |
196 |
run_hiding_tests('opac'); |
Lines 173-179
subtest 'Koha::Filter::MARC::ViewPolicy opac tests' => sub {
Link Here
|
173 |
|
199 |
|
174 |
subtest 'Koha::Filter::MARC::ViewPolicy intranet tests' => sub { |
200 |
subtest 'Koha::Filter::MARC::ViewPolicy intranet tests' => sub { |
175 |
|
201 |
|
176 |
plan tests => 102; |
202 |
plan tests => 104; |
177 |
|
203 |
|
178 |
$schema->storage->txn_begin(); |
204 |
$schema->storage->txn_begin(); |
179 |
run_hiding_tests('intranet'); |
205 |
run_hiding_tests('intranet'); |
180 |
- |
|
|