View | Details | Raw Unified | Return to bug 31207
Collapse All | Expand All

(-)a/t/db_dependent/selenium/opacshelfbrowser.t (-1 / +198 lines)
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 File::Basename qw( dirname );
21
22
use C4::Biblio qw( AddBiblio DelBiblio );
23
use C4::Context;
24
use Koha::AuthUtils;
25
use MARC::Record;
26
use MARC::Field;
27
use Test::More;
28
29
use t::lib::Mocks;
30
use t::lib::Selenium;
31
use t::lib::TestBuilder;
32
33
eval { require Selenium::Remote::Driver; };
34
if ( $@ ) {
35
    plan skip_all => "Selenium::Remote::Driver is needed for Selenium tests.";
36
} else {
37
    plan tests => 3;
38
}
39
40
my $testdir = dirname( __FILE__ );
41
42
my @cleanup;
43
44
my $OPACShelfBrowser_value           = C4::Context->preference( 'OPACShelfBrowser' );
45
my $LocalCoverImages_value           = C4::Context->preference( 'LocalCoverImages' );
46
my $OPACLocalCoverImages_value       = C4::Context->preference( 'OPACLocalCoverImages' );
47
my $OpacSeparateHoldings_value       = C4::Context->preference( 'OpacSeparateHoldings' );
48
my $OpacSeparateHoldingsBranch_value = C4::Context->preference( 'OpacSeparateHoldingsBranch' );
49
50
# Enable the OPAC shelf browser
51
C4::Context->set_preference( 'OPACShelfBrowser', '1' );
52
53
# Enable the display of local cover images in the staff interface and in the OPAC
54
C4::Context->set_preference( 'LocalCoverImages', '1' );
55
C4::Context->set_preference( 'OPACLocalCoverImages', '1' );
56
57
# Add a test biblio (for attaching local cover images to)
58
my $biblio = MARC::Record->new();
59
if ( C4::Context->preference( 'marcflavour' ) eq 'MARC21' ) {
60
    $biblio->append_fields(
61
        MARC::Field->new( '245', ' ', ' ', a => 'test biblio for MARC21 instance' ),
62
        MARC::Field->new( '100', ' ', ' ', a => 'test author' )
63
    );
64
} elsif ( C4::Context->preference( 'marcflavour' ) eq 'UNIMARC' ) {
65
    $biblio->append_fields(
66
        MARC::Field->new( '200', ' ', ' ', a => 'test biblio for UNIMARC intance' ),
67
        MARC::Field->new( '200', ' ', ' ', f => 'test author' )
68
    );
69
}
70
my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $biblio, '' );
71
72
my $builder = t::lib::TestBuilder->new;
73
74
# Add a test item (required in order for the OPAC "Browse shelf" hyperlink to appear)
75
my $itemnumber1 = $builder->build_sample_item(
76
    {
77
        biblionumber   => $biblionumber,
78
        library        => 'CPL',
79
        itemcallnumber => '123 A',
80
        itype          => 'BK'
81
    }
82
)->itemnumber;
83
my $item1 = Koha::Items->find( $itemnumber1 );
84
85
# Add another test item (required in order for the OPAC "Other holdings" tab to appear)
86
my $itemnumber2 = $builder->build_sample_item(
87
    {
88
        biblionumber   => $biblionumber,
89
        library        => 'MPL',
90
        itemcallnumber => '123 B',
91
        itype          => 'BK'
92
    }
93
)->itemnumber;
94
my $item2 = Koha::Items->find( $itemnumber2 );
95
96
push @cleanup, $builder, $item1, $item2;
97
98
my $s             = t::lib::Selenium->new;
99
my $driver        = $s->driver;
100
my $opac_base_url = $s->opac_base_url;
101
my $base_url      = $s->base_url;
102
103
# Adjust the height and width of the generated screenshots
104
#$driver->set_window_size( 2160, 991 ); # Height, then Width
105
106
my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { flags => 1, branchcode => 'CPL' } } );
107
my $password = Koha::AuthUtils::generate_password( $patron->category );
108
t::lib::Mocks::mock_preference( 'RequireStrongPassword', 0 );
109
$patron->set_password( { password => $password } );
110
111
push @cleanup, $patron;
112
113
$s->auth( $patron->userid, $password );
114
115
subtest 'OPAC Shelf browser - Check the display of biblio-level local cover images (OpacSeparateHoldings set to "Don\'t separate")' => sub {
116
    plan tests => 2;
117
118
    C4::Context->set_preference( 'OpacSeparateHoldings', '0' );
119
    C4::Context->set_preference( 'OpacSeparateHoldingsBranch', 'homebranch' );
120
121
    $driver->get( $base_url . "tools/upload-cover-image.pl?biblionumber=$biblionumber&filetype=image" );
122
    #$driver->capture_screenshot( 'Selenium_00.png' );
123
    my $image_upload_elt = $driver->find_element( '//input[@id="fileToUpload"]' );
124
    my $remote_fname = $driver->upload_file( $testdir . '/../data/2x2-000000ff.png' );
125
    $image_upload_elt->send_keys( $remote_fname );
126
    sleep 5; # Wait for the "Upload progress:" progress bar to become full and show 100%
127
    #$driver->capture_screenshot( 'Selenium_01.png' );
128
    my $process_image_button = $driver->find_element( '//button[@class="btn btn-primary btn-sm save_image"]' );
129
    $process_image_button->click;
130
    #$driver->capture_screenshot( 'Selenium_02.png' );
131
    $driver->get( $base_url . "catalogue/detail.pl?biblionumber=$biblionumber" );
132
    #$driver->capture_screenshot( 'Selenium_03.png' );
133
    my $local_cover_image_elt = $driver->find_element( '//*[@id="biblio-cover-slider"]/div/a' );
134
    is( $local_cover_image_elt->get_attribute( 'title', 1 ), 'Local cover image', 'A local cover image has been successfully uploaded at the biblio level' );
135
136
    $driver->get( $opac_base_url . "opac-detail.pl?biblionumber=$biblionumber&amp;shelfbrowse_itemnumber=$itemnumber1#holdings" );
137
    sleep 5; # Wait for the uploaded local cover image to become visible in the OPAC Shelf browser's "Holdings" tab
138
    #$driver->capture_screenshot( 'Selenium_04.png' );
139
    my $shelf_browser_thumbnail_elt = $driver->find_element( '//*[@id="holdings"]/div[@id="shelfbrowser"]//div[@id="local-thumbnail-shelf-' . $biblionumber . '"]/img' );
140
    is( $shelf_browser_thumbnail_elt->get_attribute( 'class' , 1 ), 'thumbnail', 'The biblio-level local cover image is displayed in the OPAC Shelf browser in the "Holdings" tab' );
141
};
142
143
subtest 'OPAC Shelf browser - Check the display of item-level local cover images (OpacSeparateHoldings set to "Separate" and OpacSeparateHoldingsBranch set to "home library")' => sub {
144
    plan tests => 2;
145
146
    C4::Context->set_preference( 'OpacSeparateHoldings', '1' );
147
    C4::Context->set_preference( 'OpacSeparateHoldingsBranch', 'homebranch' );
148
149
    $driver->get( $base_url . "tools/upload-cover-image.pl?itemnumber=$itemnumber2&filetype=image" );
150
    #$driver->capture_screenshot( 'Selenium_05.png' );
151
    my $image_upload_elt = $driver->find_element( '//input[@id="fileToUpload"]' );
152
    my $remote_fname = $driver->upload_file( $testdir . '/../data/2x2-000000ff.png' );
153
    #my $remote_fname = $driver->upload_file( $testdir . '/../data/aedrian-YD8aZ9Pbb14-unsplash.jpg' );
154
    $image_upload_elt->send_keys( $remote_fname );
155
    sleep 5; # Wait for the "Upload progress:" progress bar to become full and show 100%
156
    #$driver->capture_screenshot( 'Selenium_06.png' );
157
    my $process_image_button = $driver->find_element( '//button[@class="btn btn-primary btn-sm save_image"]' );
158
    $process_image_button->click;
159
    #$driver->capture_screenshot( 'Selenium_07.png' );
160
    $driver->get( $base_url . "catalogue/detail.pl?biblionumber=$biblionumber" );
161
    #$driver->capture_screenshot( 'Selenium_08.png' );
162
    my $local_cover_image_elt = $driver->find_element( '//*[@id="biblio-cover-slider"]/div/a' );
163
    is( $local_cover_image_elt->get_attribute( 'title', 1 ), 'Local cover image', 'A local cover image has been successfully uploaded at the item level' );
164
165
    $s->opac_auth( $patron->userid, $password );
166
    #$driver->capture_screenshot( 'Selenium_09.png' );
167
168
    $driver->get( $opac_base_url . "opac-detail.pl?biblionumber=$biblionumber&amp;shelfbrowse_itemnumber=$itemnumber2#otherholdings" );
169
    sleep 5; # Wait for the uploaded local cover image to become visible in the OPAC Shelf browser
170
    #$driver->capture_screenshot( 'Selenium_10.png' );
171
    my $shelf_browser_thumbnail_elt = $driver->find_element( '//*[@id="otherholdings"]/div[@id="shelfbrowser"]//div[@id="local-thumbnail-shelf-' . $biblionumber . '"]/img' );
172
    is( $shelf_browser_thumbnail_elt->get_attribute( 'class' , 1 ), 'thumbnail', 'The item-level local cover image is displayed in the OPAC Shelf browser in the "Other holdings" tab' );
173
};
174
175
subtest 'OPAC Shelf browser - Check the display of local cover images (OpacSeparateHoldings set to "Separate" and OpacSeparateHoldingsBranch set to "holding library")' => sub {
176
    plan tests => 1;
177
178
    C4::Context->set_preference( 'OpacSeparateHoldings', '1' );
179
    C4::Context->set_preference( 'OpacSeparateHoldingsBranch', 'holdingbranch' );
180
181
    $driver->get( $opac_base_url . "opac-detail.pl?biblionumber=$biblionumber&amp;shelfbrowse_itemnumber=$itemnumber2#otherholdings" );
182
    sleep 5; # Wait for the uploaded local cover image to become visible in the OPAC Shelf browser
183
    #$driver->capture_screenshot( 'Selenium_11.png' );
184
    my $shelf_browser_thumbnail_elt = $driver->find_element( '//*[@id="otherholdings"]/div[@id="shelfbrowser"]//div[@id="local-thumbnail-shelf-' . $biblionumber . '"]/img' );
185
    is( $shelf_browser_thumbnail_elt->get_attribute( 'class' , 1 ), 'thumbnail', 'The item-level local cover image is displayed in the OPAC Shelf browser in the "Other holdings" tab' );
186
};
187
188
# Revert the related System Preferences to their original values,
189
# delete the test item and then delete the test biblio
190
END {
191
    C4::Context->set_preference( 'OPACShelfBrowser',           $OPACShelfBrowser_value );
192
    C4::Context->set_preference( 'LocalCoverImages',           $LocalCoverImages_value );
193
    C4::Context->set_preference( 'OPACLocalCoverImages',       $OPACLocalCoverImages_value );
194
    C4::Context->set_preference( 'OpacSeparateHoldings',       $OpacSeparateHoldings_value );
195
    C4::Context->set_preference( 'OpacSeparateHoldingsBranch', $OpacSeparateHoldingsBranch_value );
196
    $_->delete for @cleanup;
197
    DelBiblio( $biblionumber );
198
};

Return to bug 31207