Bug 19532: (follow-up) aria-hidden attr on OPAC, and more
[koha.git] / t / db_dependent / Koha / SMS_Providers.t
1 #!/usr/bin/perl
2
3 # Copyright 2016 ByWater Solutions
4 #
5 # This file is part of Koha
6 #
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.
11 #
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.
16 #
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>.
19
20 use Modern::Perl;
21
22 use Test::More tests => 6;
23
24 use Koha::Database;
25 use Koha::SMS::Provider;
26 use Koha::SMS::Providers;
27
28 use t::lib::TestBuilder;
29
30 my $schema = Koha::Database->new->schema;
31 $schema->storage->txn_begin;
32
33 my $count = Koha::SMS::Providers->search->count;
34
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();
42
43 my $patron1 = $builder->build(
44     {
45         source => 'Borrower',
46         value  => { sms_provider_id => $provider1->id, }
47     }
48 );
49
50 my $patron2 = $builder->build(
51     {
52         source => 'Borrower',
53         value  => { sms_provider_id => $provider1->id, }
54     }
55 );
56
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' );
61
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' );
64
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' );
68
69 $provider1->delete;
70 is( Koha::SMS::Providers->search->count,
71     $count + 1, 'Delete should have deleted the provider' );
72
73 $schema->storage->txn_rollback;
74