3 # This file is part of Koha.
5 # Copyright 2014 Biblibre SARL
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>.
24 use Test
::More tests
=> 43;
27 use_ok
('C4::Contract');
30 my $dbh = C4
::Context
->dbh;
31 $dbh->{AutoCommit
} = 0;
32 $dbh->{RaiseError
} = 1;
34 $dbh->do(q
|DELETE FROM aqbasket
|);
35 $dbh->do(q
|DELETE FROM aqcontract
|);
36 $dbh->do(q
|DELETE FROM aqbooksellers
|);
39 my $bookseller_id1 = C4
::Bookseller
::AddBookseller
( { name
=> 'My first bookseller' } );
40 isnt
( $bookseller_id1, undef, 'AddBookseller does not return undef' );
41 my $bookseller_id2 = C4
::Bookseller
::AddBookseller
( { name
=> 'My second bookseller' } );
42 isnt
( $bookseller_id2, undef, 'AddBookseller does not return undef' );
43 my $contracts = GetContracts
();
44 is
( @
$contracts, 0, 'GetContracts returns the correct number of contracts' );
45 my $contract = GetContract
();
46 is
( $contract, undef, 'GetContract without argument returns undef' );
50 contractstartdate
=> '2014-06-01',
51 contractenddate
=> '2014-06-30',
52 contractname
=> 'My contract name',
53 contractdescription
=> 'My contract description',
54 booksellerid
=> $bookseller_id1,
56 my $my_contract_id1 = AddContract
();
57 is
( $my_contract_id1, undef, 'AddContract without argument returns undef' );
58 $my_contract_id1 = AddContract
($my_contract1);
59 isnt
( $my_contract_id1, undef, 'AddContract does not return undef' );
61 $contracts = GetContracts
();
62 is
( @
$contracts, 1, 'AddContract adds a contract' );
64 $contract = GetContract
();
65 is
( $contract, undef, 'GetContract without argument returns undef' );
66 $contract = GetContract
( { contractnumber
=> $my_contract_id1 } );
67 is
( $contract->{contractstartdate
}, $my_contract1->{contractstartdate
}, 'AddContract stores the contract start date correctly.' );
68 is
( $contract->{contractenddate
}, $my_contract1->{contractenddate
}, 'AddContract stores the contract end date correctly.' );
69 is
( $contract->{contractname
}, $my_contract1->{contractname
}, 'AddContract stores the contract name correctly.' );
70 is
( $contract->{contractdescription
}, $my_contract1->{contractdescription
}, 'AddContract stores the contract description correctly.' );
71 is
( $contract->{booksellerid
}, $my_contract1->{booksellerid
}, 'AddContract stores the bookseller id correctly.' );
75 contractstartdate
=> '2015-07-02',
76 contractenddate
=> '2015-07-31',
77 contractname
=> 'My modified contract name',
78 contractdescription
=> 'My modified contract description',
79 booksellerid
=> $bookseller_id2,
81 my $mod_status = ModContract
($my_contract1);
82 is
( $mod_status, undef, 'ModContract without the contract number returns 0E0' );
84 $my_contract1->{contractnumber
} = $my_contract_id1;
85 $mod_status = ModContract
($my_contract1);
86 is
( $mod_status, 1, 'ModContract returns true' );
87 $contracts = GetContracts
();
88 is
( @
$contracts, 1, 'ModContract does not modify the number of contracts' );
89 $contract = GetContract
( { contractnumber
=> $my_contract_id1 } );
90 is
( $contract->{contractstartdate
}, $my_contract1->{contractstartdate
}, 'ModContract updates the contract start date correctly.' );
91 is
( $contract->{contractenddate
}, $my_contract1->{contractenddate
}, 'ModContract updates the contract end date correctly.' );
92 is
( $contract->{contractname
}, $my_contract1->{contractname
}, 'ModContract updates the contract name correctly.' );
93 is
( $contract->{contractdescription
}, $my_contract1->{contractdescription
}, 'ModContract updates the contract description correctly.' );
94 is
( $contract->{booksellerid
}, $my_contract1->{booksellerid
}, 'ModContract updates the bookseller id correctly.' );
98 contractstartdate
=> '2013-08-05',
99 contractenddate
=> '2013-09-25',
100 contractname
=> 'My other contract name',
101 contractdescription
=> 'My other description contract name',
102 booksellerid
=> $bookseller_id1,
104 my $my_contract_id2 = AddContract
($my_contract2);
105 $contracts = GetContracts
( { booksellerid
=> $bookseller_id1 } );
106 is
( @
$contracts, 1, 'GetContracts returns the correct number of contracts' );
107 $contracts = GetContracts
({
110 is
( @
$contracts, 1, 'GetContracts with active only returns only current contracts' );
111 $contracts = GetContracts
( { booksellerid
=> $bookseller_id2 } );
112 is
( @
$contracts, 1, 'GetContracts returns the correct number of contracts' );
113 $contracts = GetContracts
();
114 is
( @
$contracts, 2, 'GetContracts returns the correct number of contracts' );
116 is
( $contracts->[0]->{contractnumber
}, $my_contract_id1, 'GetContracts returns the contract number correctly' );
117 is
( $contracts->[0]->{contractstartdate
}, $my_contract1->{contractstartdate
}, 'GetContracts returns the contract start date correctly.' );
118 is
( $contracts->[0]->{contractenddate
}, $my_contract1->{contractenddate
}, 'GetContracts returns the contract end date correctly.' );
119 is
( $contracts->[0]->{contractname
}, $my_contract1->{contractname
}, 'GetContracts returns the contract name correctly.' );
120 is
( $contracts->[0]->{contractdescription
}, $my_contract1->{contractdescription
}, 'GetContracts returns the contract description correctly.' );
121 is
( $contracts->[0]->{booksellerid
}, $my_contract1->{booksellerid
}, 'GetContracts returns the bookseller id correctly.' );
123 is
( $contracts->[1]->{contractnumber
}, $my_contract_id2, 'GetContracts returns the contract number correctly' );
124 is
( $contracts->[1]->{contractstartdate
}, $my_contract2->{contractstartdate
}, 'GetContracts returns the contract start date correctly.' );
125 is
( $contracts->[1]->{contractenddate
}, $my_contract2->{contractenddate
}, 'GetContracts returns the contract end date correctly.' );
126 is
( $contracts->[1]->{contractname
}, $my_contract2->{contractname
}, 'GetContracts returns the contract name correctly.' );
127 is
( $contracts->[1]->{contractdescription
}, $my_contract2->{contractdescription
}, 'GetContracts returns the contract description correctly.' );
128 is
( $contracts->[1]->{booksellerid
}, $my_contract2->{booksellerid
}, 'GetContracts returns the bookseller id correctly.' );
131 my $del_status = DelContract
();
132 is
( $del_status, undef, 'DelContract without contract number returns undef' );
134 $del_status = DelContract
( { contractnumber
=> $my_contract_id1 } );
135 is
( $del_status, 1, 'DelContract returns true' );
136 $contracts = GetContracts
();
137 is
( @
$contracts, 1, 'DelContract deletes a contract' );
139 $del_status = DelContract
( { contractnumber
=> $my_contract_id2 } );
140 is
( $del_status, 1, 'DelContract returns true' );
141 $contracts = GetContracts
();
142 is
( @
$contracts, 0, 'DelContract deletes a contract' );