Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
# This file is part of Koha. |
4 |
# |
5 |
# Koha is free software; you can redistribute it and/or modify it |
6 |
# under the terms of the GNU General Public License as published by |
7 |
# the Free Software Foundation; either version 3 of the License, or |
8 |
# (at your option) any later version. |
9 |
# |
10 |
# Koha is distributed in the hope that it will be useful, but |
11 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
# GNU General Public License for more details. |
14 |
# |
15 |
# You should have received a copy of the GNU General Public License |
16 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
17 |
|
18 |
use Modern::Perl; |
19 |
|
20 |
use C4::Biblio qw( AddBiblio DelBiblio ); |
21 |
use C4::Context; |
22 |
use Koha::AuthUtils; |
23 |
use MARC::Record; |
24 |
use MARC::Field; |
25 |
use Test::More; |
26 |
|
27 |
use t::lib::Mocks; |
28 |
use t::lib::Selenium; |
29 |
use t::lib::TestBuilder; |
30 |
|
31 |
eval { require Selenium::Remote::Driver; }; |
32 |
if ( $@ ) { |
33 |
plan skip_all => "Selenium::Remote::Driver is needed for Selenium tests."; |
34 |
} else { |
35 |
plan tests => 3; |
36 |
} |
37 |
|
38 |
my @cleanup; |
39 |
|
40 |
my $OPACShelfBrowser_value = C4::Context->preference( 'OPACShelfBrowser' ); |
41 |
my $LocalCoverImages_value = C4::Context->preference( 'LocalCoverImages' ); |
42 |
my $OPACLocalCoverImages_value = C4::Context->preference( 'OPACLocalCoverImages' ); |
43 |
my $OpacSeparateHoldings_value = C4::Context->preference( 'OpacSeparateHoldings' ); |
44 |
my $OpacSeparateHoldingsBranch_value = C4::Context->preference( 'OpacSeparateHoldingsBranch' ); |
45 |
|
46 |
# Enable the OPAC shelf browser |
47 |
C4::Context->set_preference( 'OPACShelfBrowser', '1' ); |
48 |
|
49 |
# Enable the display of local cover images in the staff interface and in the OPAC |
50 |
C4::Context->set_preference( 'LocalCoverImages', '1' ); |
51 |
C4::Context->set_preference( 'OPACLocalCoverImages', '1' ); |
52 |
|
53 |
# Add a test biblio (for attaching local cover images to) |
54 |
my $biblio = MARC::Record->new(); |
55 |
if ( C4::Context->preference( 'marcflavour' ) eq 'MARC21' ) { |
56 |
$biblio->append_fields( |
57 |
MARC::Field->new( '245', ' ', ' ', a => 'test biblio for MARC21 instance' ), |
58 |
MARC::Field->new( '100', ' ', ' ', a => 'test author' ) |
59 |
); |
60 |
} elsif ( C4::Context->preference( 'marcflavour' ) eq 'UNIMARC' ) { |
61 |
$biblio->append_fields( |
62 |
MARC::Field->new( '200', ' ', ' ', a => 'test biblio for UNIMARC intance' ), |
63 |
MARC::Field->new( '200', ' ', ' ', f => 'test author' ) |
64 |
); |
65 |
} |
66 |
my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $biblio, '' ); |
67 |
|
68 |
my $builder = t::lib::TestBuilder->new; |
69 |
|
70 |
# Add a test item (required in order for the OPAC "Browse shelf" hyperlink to appear) |
71 |
my $itemnumber1 = $builder->build_sample_item( |
72 |
{ |
73 |
biblionumber => $biblionumber, |
74 |
library => 'CPL', |
75 |
itemcallnumber => '123 A', |
76 |
itype => 'BK' |
77 |
} |
78 |
)->itemnumber; |
79 |
my $item1 = Koha::Items->find( $itemnumber1 ); |
80 |
|
81 |
# Add another test item (required in order for the OPAC "Other holdings" tab to appear) |
82 |
my $itemnumber2 = $builder->build_sample_item( |
83 |
{ |
84 |
biblionumber => $biblionumber, |
85 |
library => 'MPL', |
86 |
itemcallnumber => '123 B', |
87 |
itype => 'BK' |
88 |
} |
89 |
)->itemnumber; |
90 |
my $item2 = Koha::Items->find( $itemnumber2 ); |
91 |
|
92 |
push @cleanup, $builder, $item1, $item2; |
93 |
|
94 |
my $s = t::lib::Selenium->new; |
95 |
my $driver = $s->driver; |
96 |
my $opac_base_url = $s->opac_base_url; |
97 |
my $base_url = $s->base_url; |
98 |
|
99 |
#$driver->set_window_size( 2160, 991 ); |
100 |
|
101 |
my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { flags => 1, branchcode => 'CPL' } } ); |
102 |
my $password = Koha::AuthUtils::generate_password( $patron->category ); |
103 |
t::lib::Mocks::mock_preference( 'RequireStrongPassword', 0 ); |
104 |
$patron->set_password( { password => $password } ); |
105 |
|
106 |
push @cleanup, $patron; |
107 |
|
108 |
$s->auth( $patron->userid, $password ); |
109 |
|
110 |
subtest 'OPAC Shelf browser - Check display of local cover images (OpacSeparateHoldings set to "Don\'t separate")' => sub { |
111 |
plan tests => 2; |
112 |
|
113 |
C4::Context->set_preference( 'OpacSeparateHoldings', '0' ); |
114 |
C4::Context->set_preference( 'OpacSeparateHoldingsBranch', 'homebranch' ); |
115 |
|
116 |
$driver->get( $base_url . "tools/upload-cover-image.pl?biblionumber=$biblionumber&filetype=image" ); |
117 |
#$driver->capture_screenshot( 'Selenium_00.png' ); |
118 |
my $image_upload_elt = $driver->find_element( '//input[@id="fileToUpload"]' ); |
119 |
# test image by Kourosh Qaffari on Unsplash (https://unsplash.com/photos/RrhhzitYizg) |
120 |
my $remote_fname = $driver->upload_file( './opacshelfbrowser-test-image1.jpg' ); |
121 |
$image_upload_elt->send_keys( $remote_fname ); |
122 |
sleep 2; # Wait for the "Upload progress:" progress bar to become full and show 100% |
123 |
#$driver->capture_screenshot( 'Selenium_01.png' ); |
124 |
my $process_image_button = $driver->find_element( '//button[@class="btn btn-default btn-sm save_image"]' ); |
125 |
$process_image_button->click; |
126 |
#$driver->capture_screenshot( 'Selenium_02.png' ); |
127 |
$driver->get( $base_url . "catalogue/detail.pl?biblionumber=$biblionumber" ); |
128 |
#$driver->capture_screenshot( 'Selenium_03.png' ); |
129 |
my $local_cover_image_elt = $driver->find_element( '//*[@id="biblio-cover-slider"]/div/a' ); |
130 |
is( $local_cover_image_elt->get_attribute( 'title', 1 ), 'Local cover image', 'A local cover image has been successfully uploaded at the biblio level' ); |
131 |
|
132 |
$driver->get( $opac_base_url . "opac-detail.pl?biblionumber=$biblionumber&shelfbrowse_itemnumber=$itemnumber1#holdings" ); |
133 |
sleep 2; # Wait for the uploaded local cover image to become visible in the OPAC Shelf browser |
134 |
#$driver->capture_screenshot( 'Selenium_04.png' ); |
135 |
my $shelf_browser_thumbnail_elt = $driver->find_element( '//*[@id="local-thumbnail-shelf-' . $biblionumber . '"]/img' ); |
136 |
is( $shelf_browser_thumbnail_elt->get_attribute( 'class' , 1 ), 'thumbnail', 'The local cover image is displayed in the OPAC Shelf browser' ); |
137 |
}; |
138 |
|
139 |
subtest 'OPAC Shelf browser - Check display of local cover images (OpacSeparateHoldings set to "Separate" and OpacSeparateHoldingsBranch set to "home library")' => sub { |
140 |
plan tests => 2; |
141 |
|
142 |
C4::Context->set_preference( 'OpacSeparateHoldings', '1' ); |
143 |
C4::Context->set_preference( 'OpacSeparateHoldingsBranch', 'homebranch' ); |
144 |
|
145 |
$driver->get( $base_url . "tools/upload-cover-image.pl?itemnumber=$itemnumber2&filetype=image" ); |
146 |
#$driver->capture_screenshot( 'Selenium_05.png' ); |
147 |
my $image_upload_elt = $driver->find_element( '//input[@id="fileToUpload"]' ); |
148 |
# test image by Studio Media on Unsplash (https://unsplash.com/photos/9DaOYUYnOls) |
149 |
my $remote_fname = $driver->upload_file( './opacshelfbrowser-test-image2.jpg' ); |
150 |
$image_upload_elt->send_keys( $remote_fname ); |
151 |
sleep 2; # Wait for the "Upload progress:" progress bar to become full and show 100% |
152 |
#$driver->capture_screenshot( 'Selenium_06.png' ); |
153 |
my $process_image_button = $driver->find_element( '//button[@class="btn btn-default btn-sm save_image"]' ); |
154 |
$process_image_button->click; |
155 |
#$driver->capture_screenshot( 'Selenium_07.png' ); |
156 |
$driver->get( $base_url . "catalogue/detail.pl?biblionumber=$biblionumber" ); |
157 |
#$driver->capture_screenshot( 'Selenium_08.png' ); |
158 |
my $local_cover_image_elt = $driver->find_element( '//*[@id="biblio-cover-slider"]/div/a' ); |
159 |
is( $local_cover_image_elt->get_attribute( 'title', 1 ), 'Local cover image', 'A local cover image has been successfully uploaded at the item level' ); |
160 |
|
161 |
$s->opac_auth( $patron->userid, $password ); |
162 |
#$driver->capture_screenshot( 'Selenium_09.png' ); |
163 |
|
164 |
$driver->get( $opac_base_url . "opac-detail.pl?biblionumber=$biblionumber&shelfbrowse_itemnumber=$itemnumber2#otherholdings" ); |
165 |
sleep 2; # Wait for the uploaded local cover image to become visible in the OPAC Shelf browser |
166 |
#$driver->capture_screenshot( 'Selenium_10.png' ); |
167 |
my $shelf_browser_thumbnail_elt = $driver->find_element( '//*[@id="local-thumbnail-shelf-' . $biblionumber . '"]/img' ); |
168 |
is( $shelf_browser_thumbnail_elt->get_attribute( 'class' , 1 ), 'thumbnail', 'The local cover image is displayed in the OPAC Shelf browser in the "Other holdings" tab' ); |
169 |
}; |
170 |
|
171 |
subtest 'OPAC Shelf browser - Check display of local cover images (OpacSeparateHoldings set to "Separate" and OpacSeparateHoldingsBranch set to "holding library")' => sub { |
172 |
plan tests => 1; |
173 |
|
174 |
C4::Context->set_preference( 'OpacSeparateHoldings', '1' ); |
175 |
C4::Context->set_preference( 'OpacSeparateHoldingsBranch', 'holdingbranch' ); |
176 |
|
177 |
$driver->get( $opac_base_url . "opac-detail.pl?biblionumber=$biblionumber&shelfbrowse_itemnumber=$itemnumber2#otherholdings" ); |
178 |
sleep 2; # Wait for the uploaded local cover image to become visible in the OPAC Shelf browser |
179 |
#$driver->capture_screenshot( 'Selenium_11.png' ); |
180 |
my $shelf_browser_thumbnail_elt = $driver->find_element( '//*[@id="local-thumbnail-shelf-' . $biblionumber . '"]/img' ); |
181 |
is( $shelf_browser_thumbnail_elt->get_attribute( 'class' , 1 ), 'thumbnail', 'The local cover image is displayed in the OPAC Shelf browser in the "Other holdings" tab' ); |
182 |
}; |
183 |
|
184 |
# Revert the related System Preferences to their original values, |
185 |
# delete the test item and then delete the test biblio |
186 |
END { |
187 |
C4::Context->set_preference( 'OPACShelfBrowser', $OPACShelfBrowser_value ); |
188 |
C4::Context->set_preference( 'LocalCoverImages', $LocalCoverImages_value ); |
189 |
C4::Context->set_preference( 'OPACLocalCoverImages', $OPACLocalCoverImages_value ); |
190 |
C4::Context->set_preference( 'OpacSeparateHoldings', $OpacSeparateHoldings_value ); |
191 |
C4::Context->set_preference( 'OpacSeparateHoldingsBranch', $OpacSeparateHoldingsBranch_value ); |
192 |
$_->delete for @cleanup; |
193 |
DelBiblio( $biblionumber ); |
194 |
}; |