Bug 33214: Make tests use random data and clear the cache

This trivial patch removes some wrongly hardcoded bits, and makes the
tests also clear the cache before and after being run.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Tomas Cohen Arazi 2023-03-13 14:29:18 -03:00
parent a8daacac2c
commit db8261ef5e
No known key found for this signature in database
GPG Key ID: 0A272EA1B2F3C15F
1 changed files with 8 additions and 13 deletions

View File

@ -718,6 +718,8 @@ subtest 'get_marc_notes() MARC21 tests' => sub {
t::lib::Mocks::mock_preference( 'NotesToHide', '520' );
my $av = $builder->build_object( { class => 'Koha::AuthorisedValues' } );
my $biblio = $builder->build_sample_biblio;
my $record = $biblio->metadata->record;
$record->append_fields(
@ -726,21 +728,12 @@ subtest 'get_marc_notes() MARC21 tests' => sub {
MARC::Field->new( '520', '', '', a => 'Note3 skipped' ),
MARC::Field->new( '541', '0', '', a => 'Note4 skipped on opac' ),
MARC::Field->new( '544', '', '', a => 'Note5' ),
MARC::Field->new( '590', '', '', a => 'CODE' ),
MARC::Field->new( '590', '', '', a => $av->authorised_value ),
MARC::Field->new( '545', '', '', a => 'Invisible on OPAC' ),
);
Koha::AuthorisedValueCategory->new({ category_name => 'TEST' })->store;
Koha::AuthorisedValue->new(
{
category => 'TEST',
authorised_value => 'CODE',
lib => 'Description should show',
lib_opac => 'Description should show OPAC'
}
)->store;
my $mss = Koha::MarcSubfieldStructures->find({tagfield => "590", tagsubfield => "a", frameworkcode => $biblio->frameworkcode });
$mss->update({ authorised_value => "TEST" });
$mss->update({ authorised_value => $av->category });
$mss = Koha::MarcSubfieldStructures->find({tagfield => "545", tagsubfield => "a", frameworkcode => $biblio->frameworkcode });
$mss->update({ hidden => 1 });
@ -749,6 +742,7 @@ subtest 'get_marc_notes() MARC21 tests' => sub {
$cache->clear_from_cache("MarcStructure-0-");
$cache->clear_from_cache("MarcStructure-1-");
$cache->clear_from_cache("MarcSubfieldStructure-");
$cache->clear_from_cache("MarcCodedFields-");
C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
$biblio = Koha::Biblios->find( $biblio->biblionumber);
@ -759,7 +753,7 @@ subtest 'get_marc_notes() MARC21 tests' => sub {
is( $notes->[2]->{marcnote}, 'http://someserver.com', 'URL separated' );
is( $notes->[3]->{marcnote}, 'Note4 skipped on opac',"Note shows if not opac (Hidden by Indicator)" );
is( $notes->[4]->{marcnote}, 'Note5', 'Fifth note' );
is( $notes->[5]->{marcnote}, 'Description should show', 'Authorised value is correctly parsed to show description rather than code' );
is( $notes->[5]->{marcnote}, $av->lib, 'Authorised value is correctly parsed to show description rather than code' );
is( $notes->[6]->{marcnote}, 'Invisible on OPAC', 'Note shows if not opac (Hidden by framework)' );
is( @$notes, 7, 'No more notes' );
$notes = $biblio->get_marc_notes({ opac => 1 });
@ -767,12 +761,13 @@ subtest 'get_marc_notes() MARC21 tests' => sub {
is( $notes->[1]->{marcnote}, 'Note2', 'Second note' );
is( $notes->[2]->{marcnote}, 'http://someserver.com', 'URL separated' );
is( $notes->[3]->{marcnote}, 'Note5', 'Fifth note shows after fourth skipped' );
is( $notes->[4]->{marcnote}, 'Description should show OPAC', 'Authorised value is correctly parsed for OPAC to show description rather than code' );
is( $notes->[4]->{marcnote}, $av->lib_opac, 'Authorised value is correctly parsed for OPAC to show description rather than code' );
is( @$notes, 5, 'No more notes' );
$cache->clear_from_cache("MarcStructure-0-");
$cache->clear_from_cache("MarcStructure-1-");
$cache->clear_from_cache("MarcSubfieldStructure-");
$cache->clear_from_cache("MarcCodedFields-");
$schema->storage->txn_rollback;
};