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

(-)a/t/db_dependent/Koha/Items.t (-2 / +48 lines)
Lines 21-26 use Modern::Perl; Link Here
21
21
22
use Test::More tests => 11;
22
use Test::More tests => 11;
23
use Test::Exception;
23
use Test::Exception;
24
use Time::Fake;
24
25
25
use C4::Circulation;
26
use C4::Circulation;
26
use C4::Context;
27
use C4::Context;
Lines 64-70 my $retrieved_item_1 = Koha::Items->find( $new_item_1->itemnumber ); Link Here
64
is( $retrieved_item_1->barcode, $new_item_1->barcode, 'Find a item by id should return the correct item' );
65
is( $retrieved_item_1->barcode, $new_item_1->barcode, 'Find a item by id should return the correct item' );
65
66
66
subtest 'store' => sub {
67
subtest 'store' => sub {
67
    plan tests => 4;
68
    plan tests => 5;
69
68
    my $biblio = $builder->build_sample_biblio;
70
    my $biblio = $builder->build_sample_biblio;
69
    my $today = dt_from_string->set( hour => 0, minute => 0, second => 0 );
71
    my $today = dt_from_string->set( hour => 0, minute => 0, second => 0 );
70
    my $item = Koha::Item->new(
72
    my $item = Koha::Item->new(
Lines 82-87 subtest 'store' => sub { Link Here
82
    is( $item->itype, $biblio->biblioitem->itemtype, 'items.itype must have been set to biblioitem.itemtype is not given');
84
    is( $item->itype, $biblio->biblioitem->itemtype, 'items.itype must have been set to biblioitem.itemtype is not given');
83
    is( $item->permanent_location, $item->location, 'permanent_location must have been set to location if not given' );
85
    is( $item->permanent_location, $item->location, 'permanent_location must have been set to location if not given' );
84
    $item->delete;
86
    $item->delete;
87
88
    subtest '*_on updates' => sub {
89
        plan tests => 9;
90
91
        # Once the '_on' value is set (triggered by the related field turning from false to true)
92
        # it should not be re-set for any changes outside of the related field being 'unset'.
93
94
        my @fields = qw( itemlost withdrawn damaged );
95
        my $today = dt_from_string();
96
        my $yesterday = $today->clone()->subtract( days => 1 );
97
98
        for my $field ( @fields ) {
99
            my $item = $builder->build_sample_item(
100
                {
101
                    itemlost     => 0,
102
                    itemlost_on  => undef,
103
                    withdrawn    => 0,
104
                    withdrawn_on => undef,
105
                    damaged      => 0,
106
                    damaged_on   => undef
107
                }
108
            );
109
            my $field_on = $field . '_on';
110
111
            # Set field for the first time
112
            Time::Fake->offset( $yesterday->epoch );
113
            $item->$field(1)->store;
114
            $item->get_from_storage;
115
            is($item->$field_on, DateTime::Format::MySQL->format_datetime($yesterday), $field_on . " was set upon first truthy setting");
116
117
            # Update the field to a new 'true' value
118
            Time::Fake->offset( $today->epoch );
119
            $item->$field(2)->store;
120
            $item->get_from_storage;
121
            is($item->$field_on, DateTime::Format::MySQL->format_datetime($yesterday), $field_on . " was not updated upon second truthy setting");
122
123
            # Update the field to a new 'false' value
124
            $item->$field(0)->store;
125
            $item->get_from_storage;
126
            is($item->$field_on, undef, $field_on . " was unset upon untruthy setting");
127
128
            Time::Fake->reset;
129
        }
130
    };
131
85
};
132
};
86
133
87
subtest 'get_transfer' => sub {
134
subtest 'get_transfer' => sub {
88
- 

Return to bug 18501