Bug 21479: Remove the trace if the node does not exist
[koha.git] / t / db_dependent / selenium / regressions.t
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::Context;
21
22 use Test::More tests => 2;
23
24 use Koha::AuthUtils;
25 use t::lib::Selenium;
26 use t::lib::TestBuilder;
27
28 eval { require Selenium::Remote::Driver; };
29 skip "Selenium::Remote::Driver is needed for selenium tests.", 1 if $@;
30
31 my $s = t::lib::Selenium->new;
32
33 my $driver = $s->driver;
34 my $opac_base_url = $s->opac_base_url;
35 my $builder = t::lib::TestBuilder->new;
36
37 our @cleanup;
38 subtest 'OPAC - borrowernumber and branchcode as html attributes' => sub {
39     plan tests => 2;
40
41     my $patron = $builder->build_object(
42         { class => 'Koha::Patrons', value => { flags => 1 } } );
43     my $password = Koha::AuthUtils::generate_password();
44     $patron->update_password( $patron->userid, $password );
45     $s->opac_auth( $patron->userid, $password );
46     my $elt = $driver->find_element('//span[@class="loggedinusername"]');
47     is( $elt->get_attribute('data-branchcode'), $patron->library->branchcode,
48         "Since bug 20921 span.loggedinusername should contain data-branchcode"
49     );
50     is( $elt->get_attribute('data-borrowernumber'), $patron->borrowernumber,
51 "Since bug 20921 span.loggedinusername should contain data-borrowernumber"
52     );
53     push @cleanup, $patron;
54     push @cleanup, $patron->category;
55     push @cleanup, $patron->library;
56 };
57
58 subtest 'OPAC - Remove from cart' => sub {
59     plan tests => 4;
60
61     $driver->get( $opac_base_url . "opac-search.pl?q=d" );
62
63     # A better way to do that would be to modify the way we display the basket count
64     # We should show/hide the count instead or recreate the node
65     my @basket_count_elts = $driver->find_elements('//span[@id="basketcount"]/span');
66     is( scalar(@basket_count_elts), 0, 'Basket should be empty');
67
68     $driver->find_element('//a[@class="addtocart cart1"]')->click;
69     my $basket_count_elt = $driver->find_element('//span[@id="basketcount"]/span');
70     is( $basket_count_elt->get_text(),
71         1, 'One element should have been added to the cart' );
72
73     $driver->find_element('//a[@class="addtocart cart3"]')->click;
74     $driver->find_element('//a[@class="addtocart cart5"]')->click;
75     $basket_count_elt = $driver->find_element('//span[@id="basketcount"]/span');
76     is( $basket_count_elt->get_text(),
77         3, '3 elements should have been added to the cart' );
78
79     $driver->find_element('//a[@class="cartRemove cartR3"]')->click;
80     $basket_count_elt = $driver->find_element('//span[@id="basketcount"]/span');
81     is( $basket_count_elt->get_text(),
82         2, '1 element should have been removed from the cart' );
83 };
84
85 END {
86     $_->delete for @cleanup;
87 };