bug 2295 [3/4]: moving C4::Items tests into t/lib/KohaTest
The t/Items.t tests were actually dependent on the database, so I'm moving them into t/lib/KohaTest. Signed-off-by: Galen Charlton <galen.charlton@liblime.com> Signed-off-by: Joshua Ferraro <jmf@liblime.com>
This commit is contained in:
parent
599b3b5999
commit
e11d540725
100
t/Items.t
100
t/Items.t
|
|
@ -1,100 +0,0 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Test::More tests => 28;
|
||||
BEGIN {
|
||||
use FindBin;
|
||||
use lib $FindBin::Bin;
|
||||
# use override_context_prefs;
|
||||
use_ok('C4::Items');
|
||||
}
|
||||
|
||||
my $item_mod_fixes_1 = {
|
||||
notforloan => undef,
|
||||
damaged => undef,
|
||||
wthdrawn => undef,
|
||||
itemlost => undef,
|
||||
};
|
||||
|
||||
my $item_mod_fixes_2 = {
|
||||
notforloan => '',
|
||||
damaged => '',
|
||||
wthdrawn => '',
|
||||
itemlost => '',
|
||||
};
|
||||
|
||||
my $item_mod_fixes_3 = {
|
||||
notforloan => 1,
|
||||
damaged => 2,
|
||||
wthdrawn => 3,
|
||||
itemlost => 4,
|
||||
};
|
||||
|
||||
C4::Items::_do_column_fixes_for_mod($item_mod_fixes_1);
|
||||
is($item_mod_fixes_1->{'notforloan'}, 0, 'null notforloan fixed during mod');
|
||||
is($item_mod_fixes_1->{'damaged'}, 0, 'null damaged fixed during mod');
|
||||
is($item_mod_fixes_1->{'wthdrawn'}, 0, 'null wthdrawn fixed during mod');
|
||||
is($item_mod_fixes_1->{'itemlost'}, 0, 'null itemlost fixed during mod');
|
||||
|
||||
C4::Items::_do_column_fixes_for_mod($item_mod_fixes_2);
|
||||
is($item_mod_fixes_2->{'notforloan'}, 0, 'empty notforloan fixed during mod');
|
||||
is($item_mod_fixes_2->{'damaged'}, 0, 'empty damaged fixed during mod');
|
||||
is($item_mod_fixes_2->{'wthdrawn'}, 0, 'empty wthdrawn fixed during mod');
|
||||
is($item_mod_fixes_2->{'itemlost'}, 0, 'empty itemlost fixed during mod');
|
||||
|
||||
C4::Items::_do_column_fixes_for_mod($item_mod_fixes_3);
|
||||
is($item_mod_fixes_3->{'notforloan'}, 1, 'do not clobber notforloan during mod');
|
||||
is($item_mod_fixes_3->{'damaged'}, 2, 'do not clobber damaged during mod');
|
||||
is($item_mod_fixes_3->{'wthdrawn'}, 3, 'do not clobber wthdrawn during mod');
|
||||
is($item_mod_fixes_3->{'itemlost'}, 4, 'do not clobber itemlost during mod');
|
||||
|
||||
my $item_to_add_1 = {
|
||||
itemnotes => 'newitem',
|
||||
};
|
||||
|
||||
C4::Items::_set_defaults_for_add($item_to_add_1);
|
||||
ok(exists $item_to_add_1->{'dateaccessioned'}, 'dateaccessioned added to new item');
|
||||
like($item_to_add_1->{'dateaccessioned'}, qr/^\d\d\d\d-\d\d-\d\d$/ , 'new dateaccessioned is dddd-dd-dd');
|
||||
is($item_to_add_1->{'itemnotes'}, 'newitem', 'itemnotes not clobbered');
|
||||
|
||||
my $item_add_fixes_1 = {
|
||||
notforloan => undef,
|
||||
damaged => undef,
|
||||
wthdrawn => undef,
|
||||
itemlost => undef,
|
||||
};
|
||||
|
||||
my $item_add_fixes_2 = {
|
||||
notforloan => '',
|
||||
damaged => '',
|
||||
wthdrawn => '',
|
||||
itemlost => '',
|
||||
};
|
||||
|
||||
my $item_add_fixes_3 = {
|
||||
notforloan => 1,
|
||||
damaged => 2,
|
||||
wthdrawn => 3,
|
||||
itemlost => 4,
|
||||
};
|
||||
|
||||
C4::Items::_set_defaults_for_add($item_add_fixes_1);
|
||||
is($item_add_fixes_1->{'notforloan'}, 0, 'null notforloan fixed during add');
|
||||
is($item_add_fixes_1->{'damaged'}, 0, 'null damaged fixed during add');
|
||||
is($item_add_fixes_1->{'wthdrawn'}, 0, 'null wthdrawn fixed during add');
|
||||
is($item_add_fixes_1->{'itemlost'}, 0, 'null itemlost fixed during add');
|
||||
|
||||
C4::Items::_set_defaults_for_add($item_add_fixes_2);
|
||||
is($item_add_fixes_2->{'notforloan'}, 0, 'empty notforloan fixed during add');
|
||||
is($item_add_fixes_2->{'damaged'}, 0, 'empty damaged fixed during add');
|
||||
is($item_add_fixes_2->{'wthdrawn'}, 0, 'empty wthdrawn fixed during add');
|
||||
is($item_add_fixes_2->{'itemlost'}, 0, 'empty itemlost fixed during add');
|
||||
|
||||
C4::Items::_set_defaults_for_add($item_add_fixes_3);
|
||||
is($item_add_fixes_3->{'notforloan'}, 1, 'do not clobber notforloan during mod');
|
||||
is($item_add_fixes_3->{'damaged'}, 2, 'do not clobber damaged during mod');
|
||||
is($item_add_fixes_3->{'wthdrawn'}, 3, 'do not clobber wthdrawn during mod');
|
||||
is($item_add_fixes_3->{'itemlost'}, 4, 'do not clobber itemlost during mod');
|
||||
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
package KohaTest::Items;
|
||||
use base qw( KohaTest );
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Test::More;
|
||||
|
||||
use C4::Items;
|
||||
sub testing_class { 'C4::Items' }
|
||||
|
||||
sub methods : Test( 1 ) {
|
||||
my $self = shift;
|
||||
my @methods = qw(
|
||||
|
||||
GetItem
|
||||
AddItemFromMarc
|
||||
AddItem
|
||||
AddItemBatchFromMarc
|
||||
ModItemFromMarc
|
||||
ModItem
|
||||
ModItemTransfer
|
||||
ModDateLastSeen
|
||||
DelItem
|
||||
CheckItemPreSave
|
||||
GetItemStatus
|
||||
GetItemLocation
|
||||
GetLostItems
|
||||
GetItemsForInventory
|
||||
GetItemsCount
|
||||
GetItemInfosOf
|
||||
GetItemsByBiblioitemnumber
|
||||
GetItemsInfo
|
||||
get_itemnumbers_of
|
||||
GetItemnumberFromBarcode
|
||||
get_item_authorised_values
|
||||
get_authorised_value_images
|
||||
GetMarcItem
|
||||
_set_derived_columns_for_add
|
||||
_set_derived_columns_for_mod
|
||||
_do_column_fixes_for_mod
|
||||
_get_single_item_column
|
||||
_calc_items_cn_sort
|
||||
_set_defaults_for_add
|
||||
_koha_new_item
|
||||
_koha_modify_item
|
||||
_koha_delete_item
|
||||
_marc_from_item_hash
|
||||
_add_item_field_to_biblio
|
||||
_replace_item_field_in_biblio
|
||||
_repack_item_errors
|
||||
_get_unlinked_item_subfields
|
||||
_get_unlinked_subfields_xml
|
||||
_parse_unlinked_item_subfields_from_xml
|
||||
);
|
||||
|
||||
can_ok( $self->testing_class, @methods );
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
package KohaTest::Items::ColumnFixes;
|
||||
use base qw( KohaTest::Items );
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Test::More;
|
||||
|
||||
use C4::Items;
|
||||
|
||||
=head2 STARTUP METHODS
|
||||
|
||||
These get run once, before the main test methods in this module
|
||||
|
||||
=cut
|
||||
|
||||
=head2 TEST METHODS
|
||||
|
||||
standard test methods
|
||||
|
||||
=head3 not_defined
|
||||
|
||||
|
||||
=cut
|
||||
|
||||
sub not_defined : Test( 4 ) {
|
||||
|
||||
my $item_mod_fixes_1 = {
|
||||
notforloan => undef,
|
||||
damaged => undef,
|
||||
wthdrawn => undef,
|
||||
itemlost => undef,
|
||||
};
|
||||
|
||||
C4::Items::_do_column_fixes_for_mod($item_mod_fixes_1);
|
||||
is( $item_mod_fixes_1->{'notforloan'}, 0, 'null notforloan fixed during mod' );
|
||||
is( $item_mod_fixes_1->{'damaged'}, 0, 'null damaged fixed during mod' );
|
||||
is( $item_mod_fixes_1->{'wthdrawn'}, 0, 'null wthdrawn fixed during mod' );
|
||||
is( $item_mod_fixes_1->{'itemlost'}, 0, 'null itemlost fixed during mod' );
|
||||
|
||||
}
|
||||
|
||||
sub empty : Test( 4 ) {
|
||||
|
||||
my $item_mod_fixes_2 = {
|
||||
notforloan => '',
|
||||
damaged => '',
|
||||
wthdrawn => '',
|
||||
itemlost => '',
|
||||
};
|
||||
|
||||
C4::Items::_do_column_fixes_for_mod($item_mod_fixes_2);
|
||||
is( $item_mod_fixes_2->{'notforloan'}, 0, 'empty notforloan fixed during mod' );
|
||||
is( $item_mod_fixes_2->{'damaged'}, 0, 'empty damaged fixed during mod' );
|
||||
is( $item_mod_fixes_2->{'wthdrawn'}, 0, 'empty wthdrawn fixed during mod' );
|
||||
is( $item_mod_fixes_2->{'itemlost'}, 0, 'empty itemlost fixed during mod' );
|
||||
|
||||
}
|
||||
|
||||
sub not_clobbered : Test( 4 ) {
|
||||
|
||||
my $item_mod_fixes_3 = {
|
||||
notforloan => 1,
|
||||
damaged => 2,
|
||||
wthdrawn => 3,
|
||||
itemlost => 4,
|
||||
};
|
||||
|
||||
C4::Items::_do_column_fixes_for_mod($item_mod_fixes_3);
|
||||
is( $item_mod_fixes_3->{'notforloan'}, 1, 'do not clobber notforloan during mod' );
|
||||
is( $item_mod_fixes_3->{'damaged'}, 2, 'do not clobber damaged during mod' );
|
||||
is( $item_mod_fixes_3->{'wthdrawn'}, 3, 'do not clobber wthdrawn during mod' );
|
||||
is( $item_mod_fixes_3->{'itemlost'}, 4, 'do not clobber itemlost during mod' );
|
||||
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
package KohaTest::Items::SetDefaults;
|
||||
use base qw( KohaTest::Items );
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Test::More;
|
||||
|
||||
use C4::Items;
|
||||
|
||||
=head2 STARTUP METHODS
|
||||
|
||||
These get run once, before the main test methods in this module
|
||||
|
||||
=cut
|
||||
|
||||
=head2 TEST METHODS
|
||||
|
||||
standard test methods
|
||||
|
||||
=head3
|
||||
|
||||
|
||||
=cut
|
||||
|
||||
sub add_some_items : Test( 3 ) {
|
||||
|
||||
my $item_to_add_1 = { itemnotes => 'newitem', };
|
||||
|
||||
C4::Items::_set_defaults_for_add($item_to_add_1);
|
||||
ok( exists $item_to_add_1->{'dateaccessioned'}, 'dateaccessioned added to new item' );
|
||||
like( $item_to_add_1->{'dateaccessioned'}, qr/^\d\d\d\d-\d\d-\d\d$/, 'new dateaccessioned is dddd-dd-dd' );
|
||||
is( $item_to_add_1->{'itemnotes'}, 'newitem', 'itemnotes not clobbered' );
|
||||
|
||||
}
|
||||
|
||||
sub undefined : Test( 4 ) {
|
||||
my $item_add_fixes_1 = {
|
||||
notforloan => undef,
|
||||
damaged => undef,
|
||||
wthdrawn => undef,
|
||||
itemlost => undef,
|
||||
};
|
||||
|
||||
C4::Items::_set_defaults_for_add($item_add_fixes_1);
|
||||
is( $item_add_fixes_1->{'notforloan'}, 0, 'null notforloan fixed during add' );
|
||||
is( $item_add_fixes_1->{'damaged'}, 0, 'null damaged fixed during add' );
|
||||
is( $item_add_fixes_1->{'wthdrawn'}, 0, 'null wthdrawn fixed during add' );
|
||||
is( $item_add_fixes_1->{'itemlost'}, 0, 'null itemlost fixed during add' );
|
||||
}
|
||||
|
||||
sub empty_gets_fixed : Test( 4 ) {
|
||||
|
||||
my $item_add_fixes_2 = {
|
||||
notforloan => '',
|
||||
damaged => '',
|
||||
wthdrawn => '',
|
||||
itemlost => '',
|
||||
};
|
||||
|
||||
C4::Items::_set_defaults_for_add($item_add_fixes_2);
|
||||
is( $item_add_fixes_2->{'notforloan'}, 0, 'empty notforloan fixed during add' );
|
||||
is( $item_add_fixes_2->{'damaged'}, 0, 'empty damaged fixed during add' );
|
||||
is( $item_add_fixes_2->{'wthdrawn'}, 0, 'empty wthdrawn fixed during add' );
|
||||
is( $item_add_fixes_2->{'itemlost'}, 0, 'empty itemlost fixed during add' );
|
||||
|
||||
}
|
||||
|
||||
sub do_not_clobber : Test( 4 ) {
|
||||
|
||||
my $item_add_fixes_3 = {
|
||||
notforloan => 1,
|
||||
damaged => 2,
|
||||
wthdrawn => 3,
|
||||
itemlost => 4,
|
||||
};
|
||||
|
||||
C4::Items::_set_defaults_for_add($item_add_fixes_3);
|
||||
is( $item_add_fixes_3->{'notforloan'}, 1, 'do not clobber notforloan during mod' );
|
||||
is( $item_add_fixes_3->{'damaged'}, 2, 'do not clobber damaged during mod' );
|
||||
is( $item_add_fixes_3->{'wthdrawn'}, 3, 'do not clobber wthdrawn during mod' );
|
||||
is( $item_add_fixes_3->{'itemlost'}, 4, 'do not clobber itemlost during mod' );
|
||||
|
||||
}
|
||||
|
||||
1;
|
||||
Loading…
Reference in New Issue