Bug 30830: Add Koha Objects for Koha Import Items
To test: prove -v t/db_dependent/Koha/Import/Record/Items.t Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
parent
3c0c375d8e
commit
6cd0249725
5 changed files with 156 additions and 0 deletions
44
Koha/Import/Record/Item.pm
Normal file
44
Koha/Import/Record/Item.pm
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
package Koha::Import::Record::Item;
|
||||||
|
|
||||||
|
# This file is part of Koha.
|
||||||
|
#
|
||||||
|
# Koha is free software; you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# Koha is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Koha; if not, see <http://www.gnu.org/licenses>.
|
||||||
|
|
||||||
|
use Modern::Perl;
|
||||||
|
|
||||||
|
use Carp;
|
||||||
|
|
||||||
|
use Koha::Database;
|
||||||
|
|
||||||
|
use base qw(Koha::Object);
|
||||||
|
|
||||||
|
=head1 NAME
|
||||||
|
|
||||||
|
Koha::Import::Record::Item - Koha Import Record Item Object class
|
||||||
|
|
||||||
|
=head1 API
|
||||||
|
|
||||||
|
=head2 Internal methods
|
||||||
|
|
||||||
|
=head3 _type
|
||||||
|
|
||||||
|
Returns name of corresponding DBIC resultset
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub _type {
|
||||||
|
return 'ImportItem';
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
56
Koha/Import/Record/Items.pm
Normal file
56
Koha/Import/Record/Items.pm
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
package Koha::Import::Record::Items;
|
||||||
|
|
||||||
|
# This file is part of Koha.
|
||||||
|
#
|
||||||
|
# Koha is free software; you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# Koha is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Koha; if not, see <http://www.gnu.org/licenses>.
|
||||||
|
|
||||||
|
use Modern::Perl;
|
||||||
|
|
||||||
|
use Carp;
|
||||||
|
|
||||||
|
use Koha::Database;
|
||||||
|
|
||||||
|
use Koha::Import::Record::Item;
|
||||||
|
|
||||||
|
use base qw(Koha::Objects);
|
||||||
|
|
||||||
|
=head1 NAME
|
||||||
|
|
||||||
|
Koha::Import::Record::Items - Koha Import Record Items Object set class
|
||||||
|
|
||||||
|
=head1 API
|
||||||
|
|
||||||
|
=head2 Class Methods
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
=head3 type
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub _type {
|
||||||
|
return 'ImportItem';
|
||||||
|
}
|
||||||
|
|
||||||
|
=head3 object_class
|
||||||
|
|
||||||
|
Koha::Object class
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub object_class {
|
||||||
|
return 'Koha::Import::Record::Item';
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
|
@ -120,6 +120,12 @@ __PACKAGE__->belongs_to(
|
||||||
# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-02-16 17:54:53
|
# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-02-16 17:54:53
|
||||||
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:GaUyqPnOhETQO8YuuKvfNQ
|
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:GaUyqPnOhETQO8YuuKvfNQ
|
||||||
|
|
||||||
|
sub koha_object_class {
|
||||||
|
'Koha::Import::Record::Item';
|
||||||
|
}
|
||||||
|
sub koha_objects_class {
|
||||||
|
'Koha::Import::Record::Items';
|
||||||
|
}
|
||||||
|
|
||||||
# You can replace this text with custom content, and it will be preserved on regeneration
|
# You can replace this text with custom content, and it will be preserved on regeneration
|
||||||
1;
|
1;
|
||||||
|
|
46
t/db_dependent/Koha/Import/Record/Items.t
Executable file
46
t/db_dependent/Koha/Import/Record/Items.t
Executable file
|
@ -0,0 +1,46 @@
|
||||||
|
#!/usr/bin/perl
|
||||||
|
|
||||||
|
# Copyright 2020 Koha Development team
|
||||||
|
#
|
||||||
|
# This file is part of Koha
|
||||||
|
#
|
||||||
|
# Koha is free software; you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# Koha is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Koha; if not, see <http://www.gnu.org/licenses>.
|
||||||
|
|
||||||
|
use Modern::Perl;
|
||||||
|
|
||||||
|
use Test::More tests => 3;
|
||||||
|
|
||||||
|
use Koha::Import::Record::Items;
|
||||||
|
use Koha::Database;
|
||||||
|
|
||||||
|
use t::lib::TestBuilder;
|
||||||
|
|
||||||
|
my $schema = Koha::Database->new->schema;
|
||||||
|
$schema->storage->txn_begin;
|
||||||
|
|
||||||
|
my $builder = t::lib::TestBuilder->new;
|
||||||
|
my $nb_of_record_items = Koha::Import::Record::Items->search->count;
|
||||||
|
|
||||||
|
my $record_item_1 = $builder->build({ source => 'ImportItem' });
|
||||||
|
my $record_item_2 = $builder->build({ source => 'ImportItem' });
|
||||||
|
|
||||||
|
is( Koha::Import::Record::Items->search->count, $nb_of_record_items + 2, 'The 2 record items should have been added' );
|
||||||
|
|
||||||
|
my $retrieved_record_item_1 = Koha::Import::Record::Items->search({ import_items_id => $record_item_1->{import_items_id}})->next;
|
||||||
|
is_deeply( $retrieved_record_item_1->unblessed, $record_item_1, 'Find a record item by import items id should return the correct record item' );
|
||||||
|
|
||||||
|
$retrieved_record_item_1->delete;
|
||||||
|
is( Koha::Import::Record::Items->search->count, $nb_of_record_items + 1, 'Delete should have deleted the record item' );
|
||||||
|
|
||||||
|
$schema->storage->txn_rollback;
|
|
@ -605,6 +605,10 @@ sub _gen_default_values {
|
||||||
issue_id => undef, # It should be a FK but we removed it
|
issue_id => undef, # It should be a FK but we removed it
|
||||||
# We don't want to generate a random value
|
# We don't want to generate a random value
|
||||||
},
|
},
|
||||||
|
ImportItem => {
|
||||||
|
status => 'staged',
|
||||||
|
import_error => undef
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue