Bug 18755: Allow empty passwords in Patron Info to return OK
[koha.git] / t / db_dependent / Koha / SMS_Providers.t
blob407363bddba6768e8c46356eca690e4412a1f655
1 #!/usr/bin/perl
3 # Copyright 2016 ByWater Solutions
5 # This file is part of Koha
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Modern::Perl;
22 use Test::More tests => 6;
24 use Koha::Database;
25 use Koha::SMS::Provider;
26 use Koha::SMS::Providers;
28 use t::lib::TestBuilder;
30 my $schema = Koha::Database->new->schema;
31 $schema->storage->txn_begin;
33 my $count = Koha::SMS::Providers->search->count;
35 my $builder = t::lib::TestBuilder->new;
36 my $provider1 =
37 Koha::SMS::Provider->new( { name => 'Test 1', domain => 'test1.com' } )
38 ->store();
39 my $provider2 =
40 Koha::SMS::Provider->new( { name => 'Test 2', domain => 'test2.com' } )
41 ->store();
43 my $patron1 = $builder->build(
45 source => 'Borrower',
46 value => { sms_provider_id => $provider1->id, }
50 my $patron2 = $builder->build(
52 source => 'Borrower',
53 value => { sms_provider_id => $provider1->id, }
57 like( $provider1->id, qr|^\d+$|,
58 'Adding a new provider should have set the id' );
59 is( Koha::SMS::Providers->search->count,
60 $count + 2, 'The 2 providers should have been added' );
62 is ( $provider1->patrons_using(), 2, 'Found the correct number of patrons using provider' );
63 is ( $provider2->patrons_using(), 0, 'Found the correct number of patrons using unused provider' );
65 my $provider = Koha::SMS::Providers->find( $provider1->id );
66 is( $provider->name, $provider1->name,
67 'Find a provider by id should return the correct provider' );
69 $provider1->delete;
70 is( Koha::SMS::Providers->search->count,
71 $count + 1, 'Delete should have deleted the provider' );
73 $schema->storage->txn_rollback;