3 # This file is part of Koha.
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.
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.
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>.
29 use t::lib::TestBuilder;
32 eval { require Selenium::Remote::Driver; };
34 plan skip_all => "Selenium::Remote::Driver is needed for selenium tests.";
39 my $s = t::lib::Selenium->new;
41 my $driver = $s->driver;
42 my $opac_base_url = $s->opac_base_url;
43 my $builder = t::lib::TestBuilder->new;
45 my $PatronSelfRegistration_value = C4::Context->preference('PatronSelfRegistration');
46 C4::Context->set_preference('PatronSelfRegistration', '1');
48 my $PatronSelfRegistrationDefaultCategory_value = C4::Context->preference('PatronSelfRegistrationDefaultCategory');
52 subtest 'Disable if no default category' => sub {
55 $driver->get( $opac_base_url . 'opac-memberentry.pl' );
56 like( $driver->get_title(), qr(Koha online catalog), );
59 subtest 'Set flags' => sub {
62 my $default_category = $builder->build_object( { class => 'Koha::Patron::Categories' } );
63 C4::Context->set_preference( 'PatronSelfRegistrationDefaultCategory', $default_category->categorycode );
65 $driver->get($opac_base_url . 'opac-memberentry.pl');
66 like( $driver->get_title(), qr(Register a new account), );
68 $driver->find_element('//*[@id="borrower_surname"]')->send_keys("a surname");
69 $driver->find_element('//*[@id="borrower_firstname"]')->send_keys("a firstname");
70 $driver->find_element('//*[@id="borrower_initials"]')->send_keys("1");
71 $driver->execute_script(q{document.querySelector("#borrower_initials").setAttribute("name", "borrower_flags");});
72 my $captcha = $driver->find_element('//*[@id="captcha"]/following-sibling::span/strong')->get_text();
73 $driver->find_element('//*[@id="captcha"]')->send_keys($captcha);
76 my $patron = Koha::Patrons->search({ surname => "a surname" })->next;
77 is( $patron->flags, undef, 'flags must be undef even if user tried to pass it' );
78 push @cleanup, $patron;
79 push @cleanup, $default_category;
86 C4::Context->set_preference('PatronSelfRegistration', $PatronSelfRegistration_value);
87 C4::Context->set_preference('PatronSelfRegistration', $PatronSelfRegistrationDefaultCategory_value);
88 $_->delete for @cleanup;