Bug 14693: Contract.t should generate dates based on current date
authorTomas Cohen Arazi <tomascohen@unc.edu.ar>
Wed, 19 Aug 2015 14:01:32 +0000 (11:01 -0300)
committerTomas Cohen Arazi <tomascohen@unc.edu.ar>
Fri, 21 Aug 2015 13:43:38 +0000 (10:43 -0300)
The current test for still-active contracts fails because it was written
with fixed dates, which already passed :-D

This patch calculates the current date, and uses it to generate a future
one, so the tests serve their purpose no matter what the current date is.

To test:
- Run:
  $ prove t/db_dependent/Contract.t
=> FAIL: activeonly compares contractenddate with now(), and fails
         because a fixed 2015-07-31 is writteng on the test data
- Apply the patch
- Run:
  $ prove t/db_dependent/Contract.t
=> SUCCESS: the sample data has been calculated using the current date
            and the tests pass.
- Sign off :-D

Edit: added missing use DateTime::Duration,

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Tomas Cohen Arazi <tomascohen@unc.edu.ar>
t/db_dependent/Contract.t

index 7439873..eefa047 100644 (file)
 # along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 use Modern::Perl;
+
 use C4::Context;
 use C4::Bookseller;
+use Koha::DateUtils;
+
+use DateTime::Duration;
 
 use Test::More tests => 43;
 
@@ -70,10 +74,12 @@ is( $contract->{contractname}, $my_contract1->{contractname}, 'AddContract store
 is( $contract->{contractdescription}, $my_contract1->{contractdescription}, 'AddContract stores the contract description correctly.' );
 is( $contract->{booksellerid}, $my_contract1->{booksellerid}, 'AddContract stores the bookseller id correctly.' );
 
+my $now = dt_from_string;
+my $three_more_days = $now + DateTime::Duration->new( days => 3 );
 
 $my_contract1 = {
-    contractstartdate   => '2015-07-02',
-    contractenddate     => '2015-07-31',
+    contractstartdate   => $now->ymd,
+    contractenddate     => $three_more_days->ymd,
     contractname        => 'My modified contract name',
     contractdescription => 'My modified contract description',
     booksellerid        => $bookseller_id2,