|
Lines 44-65
Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" );
Link Here
|
| 44 |
my $builder = t::lib::TestBuilder->new; |
44 |
my $builder = t::lib::TestBuilder->new; |
| 45 |
|
45 |
|
| 46 |
subtest 'AddBiblio' => sub { |
46 |
subtest 'AddBiblio' => sub { |
| 47 |
plan tests => 5; |
47 |
plan tests => 9; |
| 48 |
|
48 |
|
| 49 |
my $marcflavour = 'MARC21'; |
49 |
my $marcflavour = 'MARC21'; |
| 50 |
t::lib::Mocks::mock_preference( 'marcflavour', $marcflavour ); |
50 |
t::lib::Mocks::mock_preference( 'marcflavour', $marcflavour ); |
| 51 |
my $record = MARC::Record->new(); |
|
|
| 52 |
|
51 |
|
| 53 |
my ( $f, $sf ) = GetMarcFromKohaField('biblioitems.lccn'); |
52 |
my ( $f, $sf ) = GetMarcFromKohaField('biblioitems.cn_item'); |
| 54 |
my $lccn_field = MARC::Field->new( $f, ' ', ' ', |
53 |
my $cn_item_field = MARC::Field->new( $f, ' ', ' ', |
| 55 |
$sf => 'ThisisgoingtobetoomanycharactersfortheLCCNfield' ); |
54 |
$sf => 'Thisisgoingtobetoomanycharactersforthe.cn_item.field' ); |
| 56 |
$record->append_fields($lccn_field); |
55 |
my $record = MARC::Record->new(); |
|
|
56 |
$record->append_fields($cn_item_field); |
| 57 |
|
57 |
|
| 58 |
my $nb_biblios = Koha::Biblios->count; |
58 |
my $nb_biblios = Koha::Biblios->count; |
| 59 |
my ( $biblionumber, $biblioitemnumber ); |
59 |
my ( $biblionumber, $biblioitemnumber ); |
| 60 |
warnings_like { ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio( $record, '' ) } |
60 |
warnings_like { ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio( $record, '' ) } |
| 61 |
[ qr/Data too long for column 'lccn'/, qr/Data too long for column 'lccn'/ ], |
61 |
[ qr/Data too long for column 'cn_item'/, qr/Data too long for column 'cn_item'/ ], |
| 62 |
"expected warnings when adding too long LCCN"; |
62 |
"expected warnings when adding too long cn_item"; |
| 63 |
is( $biblionumber, undef, |
63 |
is( $biblionumber, undef, |
| 64 |
'AddBiblio returns undef for biblionumber if something went wrong' ); |
64 |
'AddBiblio returns undef for biblionumber if something went wrong' ); |
| 65 |
is( $biblioitemnumber, undef, |
65 |
is( $biblioitemnumber, undef, |
|
Lines 68-73
subtest 'AddBiblio' => sub {
Link Here
|
| 68 |
is( Koha::Biblios->count, $nb_biblios, |
68 |
is( Koha::Biblios->count, $nb_biblios, |
| 69 |
'No biblio should have been added if something went wrong' ); |
69 |
'No biblio should have been added if something went wrong' ); |
| 70 |
|
70 |
|
|
|
71 |
( $f, $sf ) = GetMarcFromKohaField('biblioitems.lccn'); |
| 72 |
my $lccn_field = MARC::Field->new( $f, ' ', ' ', |
| 73 |
$sf => 'ThisisNOTgoingtobetoomanycharactersfortheLCCNfield' ); |
| 74 |
$record = MARC::Record->new(); |
| 75 |
$record->append_fields($lccn_field); |
| 76 |
|
| 77 |
warnings_like { ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio( $record, '' ) } |
| 78 |
[], |
| 79 |
"No warning expected when adding a long LCCN"; |
| 80 |
isnt( $biblionumber, undef, |
| 81 |
'AddBiblio returns the biblionumber' ); |
| 82 |
isnt( $biblioitemnumber, undef, |
| 83 |
'AddBiblio returns the biblioitemnumber' |
| 84 |
); |
| 85 |
is( Koha::Biblios->count, $nb_biblios + 1, |
| 86 |
'The biblio should have been added if nothing went wrong' ); |
| 87 |
|
| 71 |
t::lib::Mocks::mock_preference( 'AutoLinkBiblios', $marcflavour ); |
88 |
t::lib::Mocks::mock_preference( 'AutoLinkBiblios', $marcflavour ); |
| 72 |
t::lib::Mocks::mock_preference( 'AutoCreateAuthorities', $marcflavour ); |
89 |
t::lib::Mocks::mock_preference( 'AutoCreateAuthorities', $marcflavour ); |
| 73 |
t::lib::Mocks::mock_preference( 'autoControlNumber', "OFF" ); |
90 |
t::lib::Mocks::mock_preference( 'autoControlNumber', "OFF" ); |
| 74 |
- |
|
|