Bugzilla – Attachment 148068 Details for
Bug 33161
Implement +strings for GET /items and GET /items/:item_id
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 33161: Unit tests
Bug-33161-Unit-tests.patch (text/plain), 7.69 KB, created by
Tomás Cohen Arazi (tcohen)
on 2023-03-10 12:45:38 UTC
(
hide
)
Description:
Bug 33161: Unit tests
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2023-03-10 12:45:38 UTC
Size:
7.69 KB
patch
obsolete
>From 2c4f06a337687c5f6200ca2b2d504f93f3139f90 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Thu, 9 Mar 2023 19:23:03 -0300 >Subject: [PATCH] Bug 33161: Unit tests > >To test: >1. Apply this patch >2. Run: > $ ktd --shell > k$ prove t/db_dependent/Koha/Item.t >=> SUCCESS: Tests pass! >3. Sign off :-D > >Edit: added missing test for unmapped attribute > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > t/db_dependent/Koha/Item.t | 198 ++++++++++++++++++++++++++++++++++++- > 1 file changed, 197 insertions(+), 1 deletion(-) > >diff --git a/t/db_dependent/Koha/Item.t b/t/db_dependent/Koha/Item.t >index 98c9844d6e2..f42f8b03a11 100755 >--- a/t/db_dependent/Koha/Item.t >+++ b/t/db_dependent/Koha/Item.t >@@ -20,7 +20,7 @@ > use Modern::Perl; > use utf8; > >-use Test::More tests => 27; >+use Test::More tests => 28; > use Test::Exception; > use Test::MockModule; > >@@ -1441,6 +1441,202 @@ subtest 'columns_to_str' => sub { > > }; > >+subtest 'strings_map() tests' => sub { >+ >+ plan tests => 6; >+ >+ $schema->storage->txn_begin; >+ >+ my ( $itemtag, $itemsubfield ) = C4::Biblio::GetMarcFromKohaField("items.itemnumber"); >+ >+ my $cache = Koha::Caches->get_instance(); >+ $cache->clear_from_cache("MarcStructure-0-"); >+ $cache->clear_from_cache("MarcStructure-1-"); >+ $cache->clear_from_cache("MarcSubfieldStructure-"); >+ >+ # Recreating subfields just to be sure tests will be ok >+ # 1 => av (LOST) >+ # 3 => no link >+ # a => branches >+ # y => itemtypes >+ Koha::MarcSubfieldStructures->search( >+ { >+ frameworkcode => '', >+ tagfield => $itemtag, >+ tagsubfield => [ '1', '2', '3', 'a', 'y' ], >+ } >+ )->delete; # In case it exist already >+ >+ Koha::MarcSubfieldStructure->new( >+ { >+ authorised_value => 'LOST', >+ defaultvalue => '', >+ frameworkcode => '', >+ kohafield => 'items.itemlost', >+ repeatable => 1, >+ tab => 10, >+ tagfield => $itemtag, >+ tagsubfield => '1', >+ } >+ )->store; >+ Koha::MarcSubfieldStructure->new( >+ { >+ authorised_value => 'cn_source', >+ defaultvalue => '', >+ frameworkcode => '', >+ kohafield => 'items.cn_source', >+ repeatable => 1, >+ tab => 10, >+ tagfield => $itemtag, >+ tagsubfield => '2', >+ } >+ )->store; >+ Koha::MarcSubfieldStructure->new( >+ { >+ authorised_value => '', >+ defaultvalue => '', >+ frameworkcode => '', >+ kohafield => 'items.materials', >+ repeatable => 1, >+ tab => 10, >+ tagfield => $itemtag, >+ tagsubfield => '3', >+ } >+ )->store; >+ Koha::MarcSubfieldStructure->new( >+ { >+ authorised_value => 'branches', >+ defaultvalue => '', >+ frameworkcode => '', >+ kohafield => 'items.homebranch', >+ repeatable => 1, >+ tab => 10, >+ tagfield => $itemtag, >+ tagsubfield => 'a', >+ } >+ )->store; >+ Koha::MarcSubfieldStructure->new( >+ { >+ authorised_value => 'itemtypes', >+ defaultvalue => '', >+ frameworkcode => '', >+ kohafield => 'items.itype', >+ repeatable => 1, >+ tab => 10, >+ tagfield => $itemtag, >+ tagsubfield => 'y', >+ } >+ )->store; >+ >+ my $itype = $builder->build_object( { class => 'Koha::ItemTypes' } ); >+ my $library = $builder->build_object( { class => 'Koha::Libraries' } ); >+ my $biblio = $builder->build_sample_biblio( { frameworkcode => '' } ); >+ my $item = $builder->build_sample_item( >+ { >+ biblionumber => $biblio->id, >+ library => $library->id >+ } >+ ); >+ >+ Koha::AuthorisedValues->search( { authorised_value => 3, category => 'LOST' } )->delete; >+ my $lost_av = $builder->build_object( >+ { >+ class => 'Koha::AuthorisedValues', >+ value => { >+ authorised_value => 3, >+ category => 'LOST', >+ lib => 'internal description', >+ lib_opac => 'public description', >+ } >+ } >+ ); >+ >+ my $class_sort_rule = $builder->build_object( { class => 'Koha::ClassSortRules', value => { sort_routine => 'Generic' } } ); >+ my $class_split_rule = $builder->build_object( { class => 'Koha::ClassSplitRules' } ); >+ my $class_source = $builder->build_object( >+ { >+ class => 'Koha::ClassSources', >+ value => { >+ class_sort_rule => $class_sort_rule->class_sort_rule, >+ class_split_rule => $class_split_rule->class_split_rule, >+ } >+ } >+ ); >+ >+ $item->set( >+ { >+ cn_source => $class_source->id, >+ itemlost => $lost_av->authorised_value, >+ itype => $itype->itemtype, >+ materials => 'Suff', >+ } >+ )->store->discard_changes; >+ >+ my $strings = $item->strings_map; >+ >+ subtest 'unmapped field tests' => sub { >+ >+ plan tests => 1; >+ >+ ok( !exists $strings->{materials}, "Unmapped field not present" ); >+ }; >+ >+ subtest 'av handling' => sub { >+ >+ plan tests => 4; >+ >+ ok( exists $strings->{itemlost}, "'itemlost' entry exists" ); >+ is( $strings->{itemlost}->{str}, $lost_av->lib, "'str' set to av->lib" ); >+ is( $strings->{itemlost}->{type}, 'av', "'type' is 'av'" ); >+ is( $strings->{itemlost}->{category}, 'LOST', "'category' exists and set to 'LOST'" ); >+ }; >+ >+ subtest 'cn_source handling' => sub { >+ >+ plan tests => 3; >+ >+ ok( exists $strings->{cn_source}, "'cn_source' entry exists" ); >+ is( $strings->{cn_source}->{str}, $class_source->description, "'str' set to \$class_source->description" ); >+ is( $strings->{cn_source}->{type}, 'call_number_source', "type is 'library'" ); >+ }; >+ >+ subtest 'branches handling' => sub { >+ >+ plan tests => 3; >+ >+ ok( exists $strings->{homebranch}, "'homebranch' entry exists" ); >+ is( $strings->{homebranch}->{str}, $library->branchname, "'str' set to 'branchname'" ); >+ is( $strings->{homebranch}->{type}, 'library', "type is 'library'" ); >+ }; >+ >+ subtest 'itemtype handling' => sub { >+ >+ plan tests => 3; >+ >+ ok( exists $strings->{itype}, "'itype' entry exists" ); >+ is( $strings->{itype}->{str}, $itype->description, "'str' correctly set" ); >+ is( $strings->{itype}->{type}, 'item_type', "'type' is 'item_type'" ); >+ }; >+ >+ subtest 'public flag tests' => sub { >+ >+ plan tests => 4; >+ >+ $strings = $item->strings_map( { public => 1 } ); >+ >+ ok( exists $strings->{itemlost}, "'itemlost' entry exists" ); >+ is( $strings->{itemlost}->{str}, $lost_av->lib_opac, "'str' set to av->lib" ); >+ is( $strings->{itemlost}->{type}, 'av', "'type' is 'av'" ); >+ is( $strings->{itemlost}->{category}, 'LOST', "'category' exists and set to 'LOST'" ); >+ }; >+ >+ $cache->clear_from_cache("MarcStructure-0-"); >+ $cache->clear_from_cache("MarcStructure-1-"); >+ $cache->clear_from_cache("MarcSubfieldStructure-"); >+ >+ $schema->storage->txn_rollback; >+}; >+ > subtest 'store() tests' => sub { > > plan tests => 3; >-- >2.34.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 33161
:
147888
|
147973
|
147977
|
147995
|
147998
|
147999
|
148010
|
148011
|
148012
|
148013
|
148014
|
148039
|
148040
|
148041
|
148042
|
148043
|
148059
|
148060
|
148061
|
148062
|
148063
| 148068 |
148075