View | Details | Raw Unified | Return to bug 19176
Collapse All | Expand All

(-)a/t/db_dependent/Patrons.t (-3 / +4 lines)
Lines 24-29 use C4::Context; Link Here
24
use Koha::Database;
24
use Koha::Database;
25
use Koha::DateUtils;
25
use Koha::DateUtils;
26
26
27
use t::lib::Dates;
27
use t::lib::TestBuilder;
28
use t::lib::TestBuilder;
28
29
29
BEGIN {
30
BEGIN {
Lines 71-83 $b3->store(); Link Here
71
my $b1_new = Koha::Patrons->find( $b1->borrowernumber() );
72
my $b1_new = Koha::Patrons->find( $b1->borrowernumber() );
72
is( $b1->surname(), $b1_new->surname(), "Found matching patron" );
73
is( $b1->surname(), $b1_new->surname(), "Found matching patron" );
73
isnt( $b1_new->updated_on, undef, "borrowers.updated_on should be set" );
74
isnt( $b1_new->updated_on, undef, "borrowers.updated_on should be set" );
74
is( dt_from_string($b1_new->updated_on), $now, "borrowers.updated_on should have been set to now on creating" );
75
t::lib::Dates::compare( $b1_new->updated_on, $now, "borrowers.updated_on should have been set to now on creating" );
75
76
76
my $b3_new = Koha::Patrons->find( $b3->borrowernumber() );
77
my $b3_new = Koha::Patrons->find( $b3->borrowernumber() );
77
is( dt_from_string($b3_new->updated_on), $three_days_ago, "borrowers.updated_on should have been kept to what we set on creating" );
78
t::lib::Dates::compare( $b3_new->updated_on, $three_days_ago, "borrowers.updated_on should have been kept to what we set on creating" );
78
$b3_new->set({ firstname => 'Some first name for Test 3' })->store();
79
$b3_new->set({ firstname => 'Some first name for Test 3' })->store();
79
$b3_new = Koha::Patrons->find( $b3->borrowernumber() );
80
$b3_new = Koha::Patrons->find( $b3->borrowernumber() );
80
is( dt_from_string($b3_new->updated_on), dt_from_string, "borrowers.updated_on should have been set to now on updating" );
81
t::lib::Dates::compare( $b3_new->updated_on, $now, "borrowers.updated_on should have been set to now on updating" );
81
82
82
my @patrons = Koha::Patrons->search( { branchcode => $branchcode } );
83
my @patrons = Koha::Patrons->search( { branchcode => $branchcode } );
83
is( @patrons, 3, "Found 3 patrons with Search" );
84
is( @patrons, 3, "Found 3 patrons with Search" );
(-)a/t/db_dependent/Virtualshelves.t (-4 / +5 lines)
Lines 10-15 use Koha::Virtualshelves; Link Here
10
use Koha::Virtualshelfshares;
10
use Koha::Virtualshelfshares;
11
use Koha::Virtualshelfcontents;
11
use Koha::Virtualshelfcontents;
12
12
13
use t::lib::Dates;
13
use t::lib::TestBuilder;
14
use t::lib::TestBuilder;
14
15
15
my $builder = t::lib::TestBuilder->new;
16
my $builder = t::lib::TestBuilder->new;
Lines 41-47 subtest 'CRUD' => sub { Link Here
41
    is( $number_of_shelves, 1, '1 shelf should have been inserted' );
42
    is( $number_of_shelves, 1, '1 shelf should have been inserted' );
42
    is( $shelf->allow_change_from_owner, 1, 'The default value for allow_change_from_owner should be 1' );
43
    is( $shelf->allow_change_from_owner, 1, 'The default value for allow_change_from_owner should be 1' );
43
    is( $shelf->allow_change_from_others, 0, 'The default value for allow_change_from_others should be 0' );
44
    is( $shelf->allow_change_from_others, 0, 'The default value for allow_change_from_others should be 0' );
44
    is( output_pref($shelf->created_on), output_pref(dt_from_string), 'The creation time should have been set to today' );
45
    t::lib::Dates::compare( $shelf->created_on, dt_from_string, 'The creation time should have been set to today' );
45
46
46
    # Test if creation date will not be overwritten by store
47
    # Test if creation date will not be overwritten by store
47
    my $created = dt_from_string->subtract( hours => 1 );
48
    my $created = dt_from_string->subtract( hours => 1 );
Lines 51-57 subtest 'CRUD' => sub { Link Here
51
    my $retrieved_shelf = Koha::Virtualshelves->find( $shelf->shelfnumber );
52
    my $retrieved_shelf = Koha::Virtualshelves->find( $shelf->shelfnumber );
52
53
53
    is( $retrieved_shelf->shelfname, $shelf->shelfname, 'Find should correctly return the shelfname' );
54
    is( $retrieved_shelf->shelfname, $shelf->shelfname, 'Find should correctly return the shelfname' );
54
    is( dt_from_string($retrieved_shelf->created_on), $created, 'Creation date is the same after update (Bug 18672)' );
55
    t::lib::Dates::compare( $retrieved_shelf->created_on, $created, 'Creation date is the same after update (Bug 18672)' );
55
56
56
    # Insert with the same name
57
    # Insert with the same name
57
    eval {
58
    eval {
Lines 181-191 subtest 'Shelf content' => sub { Link Here
181
    )->store;
182
    )->store;
182
183
183
    $shelf = Koha::Virtualshelves->find( $shelf->shelfnumber );
184
    $shelf = Koha::Virtualshelves->find( $shelf->shelfnumber );
184
    is( output_pref( dt_from_string $shelf->lastmodified ), output_pref($dt_yesterday), 'The lastmodified has been set to yesterday, will be useful for another test later' );
185
    t::lib::Dates::compare( $shelf->lastmodified, $dt_yesterday, 'The lastmodified has been set to yesterday, will be useful for another test later' );
185
    my $content1 = $shelf->add_biblio( $biblio1->{biblionumber}, $patron1->{borrowernumber} );
186
    my $content1 = $shelf->add_biblio( $biblio1->{biblionumber}, $patron1->{borrowernumber} );
186
    is( ref($content1), 'Koha::Virtualshelfcontent', 'add_biblio to a shelf should return a Koha::Virtualshelfcontent object if inserted' );
187
    is( ref($content1), 'Koha::Virtualshelfcontent', 'add_biblio to a shelf should return a Koha::Virtualshelfcontent object if inserted' );
187
    $shelf = Koha::Virtualshelves->find( $shelf->shelfnumber );
188
    $shelf = Koha::Virtualshelves->find( $shelf->shelfnumber );
188
    is( output_pref( dt_from_string( $shelf->lastmodified ) ), output_pref(dt_from_string), 'Adding a biblio to a shelf should update the lastmodified for the shelf' );
189
    t::lib::Dates::compare( $shelf->lastmodified, dt_from_string, 'Adding a biblio to a shelf should update the lastmodified for the shelf' );
189
    my $content2 = $shelf->add_biblio( $biblio2->{biblionumber}, $patron1->{borrowernumber} );
190
    my $content2 = $shelf->add_biblio( $biblio2->{biblionumber}, $patron1->{borrowernumber} );
190
    $number_of_contents = Koha::Virtualshelfcontents->search->count;
191
    $number_of_contents = Koha::Virtualshelfcontents->search->count;
191
    is( $number_of_contents, 2, '2 biblio should have been inserted' );
192
    is( $number_of_contents, 2, '2 biblio should have been inserted' );
(-)a/t/lib/Dates.pm (-1 / +25 lines)
Line 0 Link Here
0
- 
1
package t::lib::Dates;
2
3
use Modern::Perl;
4
use Test::More;
5
use Koha::DateUtils;
6
7
=head2 compare
8
9
  compare( $got_dt, $expected_dt, $test_description );
10
11
Will execute a test and compare the 2 dates given in parameters
12
The date will be compared truncated to minutes
13
14
=cut
15
16
sub compare {
17
    my ( $got, $expected, $description ) = @_;
18
    my $dt_got = dt_from_string( $got );
19
    my $dt_expected = dt_from_string( $expected );
20
    my $diff = $dt_got->clone->subtract_datetime( $dt_expected );
21
    my $diff_seconds = $diff->minutes * 60 + $diff->seconds;
22
    ok( $diff_seconds < 60, $description . "(in $diff_seconds seconds)" );
23
}
24
25
1;

Return to bug 19176