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

(-)a/Koha/Item.pm (-2 / +3 lines)
Lines 99-106 sub store { Link Here
99
        }
99
        }
100
100
101
        my $default_location = C4::Context->preference('NewItemsDefaultLocation');
101
        my $default_location = C4::Context->preference('NewItemsDefaultLocation');
102
        if ( $default_location ) {
102
        unless ( $self->location || !$default_location ) {
103
            $self->permanent_location( $self->location ); # FIXME To confirm - even if passed?
103
            $self->permanent_location( $self->location || $default_location )
104
              unless $self->permanent_location;
104
            $self->location($default_location);
105
            $self->location($default_location);
105
        }
106
        }
106
107
(-)a/t/db_dependent/Koha/Items.t (-54 / +109 lines)
Lines 92-154 subtest 'store' => sub { Link Here
92
    $item->delete;
92
    $item->delete;
93
93
94
    subtest 'permanent_location' => sub {
94
    subtest 'permanent_location' => sub {
95
        plan tests => 7;
95
        plan tests => 2;
96
96
97
        my $location = 'my_loc';
97
        subtest 'location passed to ->store' => sub {
98
        my $attributes = {
98
            plan tests => 7;
99
            homebranch    => $library->{branchcode},
99
100
            holdingbranch => $library->{branchcode},
100
            my $location = 'my_loc';
101
            biblionumber  => $biblio->biblionumber,
101
            my $attributes = {
102
            location      => $location,
102
                homebranch    => $library->{branchcode},
103
                holdingbranch => $library->{branchcode},
104
                biblionumber  => $biblio->biblionumber,
105
                location      => $location,
106
            };
107
108
            {
109
                # NewItemsDefaultLocation not set
110
                t::lib::Mocks::mock_preference( 'NewItemsDefaultLocation', '' );
111
112
                # Not passing permanent_location on creating the item
113
                my $item = Koha::Item->new($attributes)->store->get_from_storage;
114
                is( $item->location, $location,
115
                    'location must have been set to location if given' );
116
                is( $item->permanent_location, $item->location,
117
                    'permanent_location must have been set to location if not given' );
118
                $item->delete;
119
120
                # Passing permanent_location on creating the item
121
                $item = Koha::Item->new(
122
                    { %$attributes, permanent_location => 'perm_loc' } )
123
                  ->store->get_from_storage;
124
                is( $item->permanent_location, 'perm_loc',
125
                    'permanent_location must have been kept if given' );
126
                $item->delete;
127
            }
128
129
            {
130
                # NewItemsDefaultLocation set
131
                my $default_location = 'default_location';
132
                t::lib::Mocks::mock_preference( 'NewItemsDefaultLocation', $default_location );
133
134
                # Not passing permanent_location on creating the item
135
                my $item = Koha::Item->new($attributes)->store->get_from_storage;
136
                is( $item->location, $location,
137
                    'location must have been kept if given' );
138
                is( $item->permanent_location, $location,
139
                    'permanent_location must have been set to the location given' );
140
                $item->delete;
141
142
                # Passing permanent_location on creating the item
143
                $item = Koha::Item->new(
144
                    { %$attributes, permanent_location => 'perm_loc' } )
145
                  ->store->get_from_storage;
146
                is( $item->location, $location,
147
                    'location must have been kept if given' );
148
                is( $item->permanent_location, 'perm_loc',
149
                    'permanent_location must have been kept if given' );
150
                $item->delete;
151
            }
103
        };
152
        };
104
153
105
        {
154
        subtest 'location NOT passed to ->store' => sub {
106
            # NewItemsDefaultLocation not set
155
            plan tests => 7;
107
            t::lib::Mocks::mock_preference( 'NewItemsDefaultLocation', '' );
108
109
            # Not passing permanent_location on creating the item
110
            my $item = Koha::Item->new($attributes)->store->get_from_storage;
111
            is( $item->location, $location,
112
                'location must have been set to location if given' );
113
            is( $item->permanent_location, $item->location,
114
                'permanent_location must have been set to location if not given' );
115
            $item->delete;
116
117
            # Passing permanent_location on creating the item
118
            $item = Koha::Item->new(
119
                { %$attributes, permanent_location => 'perm_loc' } )
120
              ->store->get_from_storage;
121
            is( $item->permanent_location, 'perm_loc',
122
                'permanent_location must have been kept if given' );
123
            $item->delete;
124
        }
125
156
126
        {
157
            my $attributes = {
127
            # NewItemsDefaultLocation set
158
                homebranch    => $library->{branchcode},
128
            my $default_location = 'default_location';
159
                holdingbranch => $library->{branchcode},
129
            t::lib::Mocks::mock_preference( 'NewItemsDefaultLocation', $default_location );
160
                biblionumber  => $biblio->biblionumber,
130
161
            };
131
            # Not passing permanent_location on creating the item
162
132
            my $item = Koha::Item->new($attributes)->store->get_from_storage;
163
            {
133
            is( $item->location, $default_location,
164
                # NewItemsDefaultLocation not set
134
                'location must have been set to default_location even if given' # FIXME this sounds wrong! Must be done in any cases?
165
                t::lib::Mocks::mock_preference( 'NewItemsDefaultLocation', '' );
135
            );
166
136
            is( $item->permanent_location, $location,
167
                # Not passing permanent_location on creating the item
137
                'permanent_location must have been set to the location given' );
168
                my $item = Koha::Item->new($attributes)->store->get_from_storage;
138
            $item->delete;
169
                is( $item->location, undef,
139
170
                    'location not passed and no default, it is undef' );
140
            # Passing permanent_location on creating the item
171
                is( $item->permanent_location, $item->location,
141
            $item = Koha::Item->new(
172
                    'permanent_location must have been set to location if not given' );
142
                { %$attributes, permanent_location => 'perm_loc' } )
173
                $item->delete;
143
              ->store->get_from_storage;
174
144
            is( $item->location, $default_location,
175
                # Passing permanent_location on creating the item
145
                'location must have been set to default_location even if given' # FIXME this sounds wrong! Must be done in any cases?
176
                $item = Koha::Item->new(
146
            );
177
                    { %$attributes, permanent_location => 'perm_loc' } )
147
            is( $item->permanent_location, $location,
178
                  ->store->get_from_storage;
148
                'permanent_location must have been set to the location given'
179
                is( $item->permanent_location, 'perm_loc',
149
            );
180
                    'permanent_location must have been kept if given' );
150
            $item->delete;
181
                $item->delete;
151
        }
182
            }
183
184
            {
185
                # NewItemsDefaultLocation set
186
                my $default_location = 'default_location';
187
                t::lib::Mocks::mock_preference( 'NewItemsDefaultLocation', $default_location );
188
189
                # Not passing permanent_location on creating the item
190
                my $item = Koha::Item->new($attributes)->store->get_from_storage;
191
                is( $item->location, $default_location,
192
                    'location must have been set to default location if not given' );
193
                is( $item->permanent_location, $default_location,
194
                    'permanent_location must have been set to the default location as well' );
195
                $item->delete;
196
197
                # Passing permanent_location on creating the item
198
                $item = Koha::Item->new(
199
                    { %$attributes, permanent_location => 'perm_loc' } )
200
                  ->store->get_from_storage;
201
                is( $item->location, $default_location,
202
                    'location must have been set to default location if not given' );
203
                is( $item->permanent_location, 'perm_loc',
204
                    'permanent_location must have been kept if given' );
205
                $item->delete;
206
            }
207
        };
152
208
153
    };
209
    };
154
210
155
- 

Return to bug 27545