From: Andrew Moore Date: Mon, 7 Jul 2008 17:54:50 +0000 (-0500) Subject: bug 2295 [3/4]: moving C4::Items tests into t/lib/KohaTest X-Git-Tag: ffzg~216 X-Git-Url: http://git.rot13.org/?a=commitdiff_plain;h=e11d5407252195ea3d8a2b89f209db8bce4347b8;p=koha.git 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 Signed-off-by: Joshua Ferraro --- diff --git a/t/Items.t b/t/Items.t deleted file mode 100644 index e9513bdbe8..0000000000 --- a/t/Items.t +++ /dev/null @@ -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'); - diff --git a/t/lib/KohaTest/Items.pm b/t/lib/KohaTest/Items.pm new file mode 100644 index 0000000000..7dcd9ab9ef --- /dev/null +++ b/t/lib/KohaTest/Items.pm @@ -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; diff --git a/t/lib/KohaTest/Items/ColumnFixes.pm b/t/lib/KohaTest/Items/ColumnFixes.pm new file mode 100644 index 0000000000..aca4f73425 --- /dev/null +++ b/t/lib/KohaTest/Items/ColumnFixes.pm @@ -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; diff --git a/t/lib/KohaTest/Items/SetDefaults.pm b/t/lib/KohaTest/Items/SetDefaults.pm new file mode 100644 index 0000000000..fd622a7402 --- /dev/null +++ b/t/lib/KohaTest/Items/SetDefaults.pm @@ -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;