Bugzilla – Attachment 88427 Details for
Bug 18823
Advanced editor - Rancor - add ability to edit records in import batches
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 18823: add unit tests for added/changed subroutines
Bug-18823-add-unit-tests-for-addedchanged-subrouti.patch (text/plain), 6.59 KB, created by
Alex Arnaud
on 2019-04-23 08:36:11 UTC
(
hide
)
Description:
Bug 18823: add unit tests for added/changed subroutines
Filename:
MIME Type:
Creator:
Alex Arnaud
Created:
2019-04-23 08:36:11 UTC
Size:
6.59 KB
patch
obsolete
>From 5ed200a27ff6c6798a302fe51b4d663ff925f8fb Mon Sep 17 00:00:00 2001 >From: Alex Arnaud <alex.arnaud@biblibre.com> >Date: Tue, 16 Apr 2019 17:57:57 +0200 >Subject: [PATCH] Bug 18823: add unit tests for added/changed subroutines > >--- > C4/ImportBatch.pm | 20 +++++-- > t/db_dependent/Biblio/MarcTimestamp.t | 99 +++++++++++++++++++++++++++++++++++ > t/db_dependent/ImportBatch.t | 35 ++++++++++++- > 3 files changed, 148 insertions(+), 6 deletions(-) > create mode 100644 t/db_dependent/Biblio/MarcTimestamp.t > >diff --git a/C4/ImportBatch.pm b/C4/ImportBatch.pm >index b2d53ae..7ca7384 100644 >--- a/C4/ImportBatch.pm >+++ b/C4/ImportBatch.pm >@@ -1608,6 +1608,16 @@ sub _create_import_record { > return $import_record_id; > } > >+=head2 _get_import_record_timestamp >+ >+ my $timestamp = C4::ImportBatch::_get_import_record_timestamp($record); >+ >+Get the date in field 005 and return it formatted as a timestamp. >+ >+The argument is a C<MARC::Record> object >+ >+=cut >+ > sub _get_import_record_timestamp { > my ( $marc_record ) = @_; > my $upload_timestamp = DateTime->now(); >@@ -1616,12 +1626,12 @@ sub _get_import_record_timestamp { > # tenth-of-a-second ourselves. > my $f005 = $marc_record->field('005'); > if ($f005 && $f005->data =~ /(\d{8}\d{6})\.(\d)/ ) { >- my $parser = DateTime::Format::Strptime->new( pattern => '%Y%m%d%H%M%S' ); >- my $parsed_timestamp = $parser->parse_datetime($1); >+ my $parser = DateTime::Format::Strptime->new( pattern => '%Y%m%d%H%M%S' ); >+ my $parsed_timestamp = $parser->parse_datetime($1); > >- # We still check for success because we only did enough validation above to extract the >- # tenth-of-a-second; the timestamp could still be some nonsense like the 50th of Jantober. >- if ( $parsed_timestamp ) { >+ # We still check for success because we only did enough validation above to extract the >+ # tenth-of-a-second; the timestamp could still be some nonsense like the 50th of Jantober. >+ if ( $parsed_timestamp ) { > $parsed_timestamp->set_nanosecond( $2 * 100_000_000 ); > $upload_timestamp = $parsed_timestamp; > } >diff --git a/t/db_dependent/Biblio/MarcTimestamp.t b/t/db_dependent/Biblio/MarcTimestamp.t >new file mode 100644 >index 0000000..8fb2b1f >--- /dev/null >+++ b/t/db_dependent/Biblio/MarcTimestamp.t >@@ -0,0 +1,99 @@ >+#!/usr/bin/perl >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+# >+use Modern::Perl; >+ >+use Test::More tests => 5; >+ >+use t::lib::TestBuilder; >+use t::lib::Mocks; >+use MARC::Record; >+use C4::Biblio; >+use C4::ImportBatch; >+use DateTime; >+use Koha::Database; >+ >+my $schema = Koha::Database->new->schema; >+$schema->storage->txn_begin; >+ >+my $builder = t::lib::TestBuilder->new(); >+ >+t::lib::Mocks::mock_preference( 'marcflavour', 'NORMARC' ); >+ >+my $record = MARC::Record->new; >+$record->append_fields( >+ MARC::Field->new( '100', '', '', a => 'My title' ), >+ MARC::Field->new( '005', '20140508101202.0' ), >+); >+ >+C4::Biblio::UpdateMarcTimestamp( $record ); >+ >+my $f005 = $record->field('005')->data; >+ >+is($f005, '20140508101202.0', "Field 005 didn't change because of the normarc marc flavour."); >+ >+t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' ); >+ >+my $dt = DateTime->now; >+my $expected = $dt->ymd(''); >+ >+C4::Biblio::UpdateMarcTimestamp( $record ); >+ >+$f005 = $record->field('005')->data; >+ok($f005 =~ /^$expected\d{6}\.\d/); >+ >+$record->field('005')->update('20140508101202.0'); >+ >+my $timestamp = C4::ImportBatch::_get_import_record_timestamp($record); >+ >+is($timestamp, '2014-05-08T10:12:02', "Get correct record's timestamp"); >+ >+my $import_batch = $builder->build( >+ { >+ source => 'ImportBatch', >+ } >+); >+ >+my $import_record_id = C4::ImportBatch::_create_import_record( >+ $import_batch->{import_batch_id}, >+ 1, $record, 'biblio', 'UTF-8', >+); >+ >+$timestamp = get_import_record_timestamp($import_record_id); >+ok($f005 =~ /^$expected\d{6}\.\d/); >+ >+ >+C4::ImportBatch::_update_import_record_marc($import_record_id, $record); >+ >+$timestamp = get_import_record_timestamp($import_record_id); >+is($timestamp, '2014-05-08 10:12:02', "import_records.upload_timestamp correctly updated."); >+ >+ >+sub get_import_record_timestamp { >+ my $import_record_id = shift; >+ >+ my $dbh = C4::Context->dbh; >+ my $timestamp = $dbh->selectrow_array(q| >+ SELECT upload_timestamp >+ FROM import_records >+ WHERE import_record_id = ? >+ |, undef, $import_record_id ); >+ >+ return $timestamp; >+} >+ >+$schema->storage->txn_rollback; >diff --git a/t/db_dependent/ImportBatch.t b/t/db_dependent/ImportBatch.t >index f42e0d8..90571c2 100644 >--- a/t/db_dependent/ImportBatch.t >+++ b/t/db_dependent/ImportBatch.t >@@ -1,7 +1,7 @@ > #!/usr/bin/perl > > use Modern::Perl; >-use Test::More tests => 14; >+use Test::More tests => 15; > use File::Basename; > use File::Temp qw/tempfile/; > >@@ -198,4 +198,37 @@ subtest "RecordsFromMarcPlugin" => sub { > 'Checked one field in second record' ); > }; > >+subtest "add_biblio_fields to import record" => sub { >+ >+my $record = MARC::Record->new; >+ plan tests => 4; >+ >+ $record->append_fields( >+ MARC::Field->new( '100', '', '', a => 'My author' ), >+ MARC::Field->new( '245', '', '', a => 'My title' ), >+ MARC::Field->new( '001', '111' ), >+ ); >+ >+ my $import_batch = $builder->build( >+ { >+ source => 'ImportBatch', >+ } >+ ); >+ >+ my $import_record_id = C4::ImportBatch::_create_import_record( >+ $import_batch->{import_batch_id}, >+ 1, $record, 'biblio', 'UTF-8', >+ ); >+ >+ my $import_biblios = GetImportBiblios($import_record_id); >+ is(scalar(@$import_biblios), 0, 'No import_biblios yet'); >+ >+ C4::ImportBatch::_add_biblio_fields($import_record_id, $record); >+ >+ $import_biblios = GetImportBiblios($import_record_id); >+ is($import_biblios->[0]{title}, 'My title', 'Import biblio title'); >+ is($import_biblios->[0]{author}, 'My author', 'Import biblio author'); >+ is($import_biblios->[0]{control_number}, 111, 'Import biblio control number'); >+}; >+ > $schema->storage->txn_rollback; >-- >2.7.4
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 18823
:
64434
|
66882
|
66883
|
66884
|
66885
|
66919
|
77240
|
77241
|
77242
|
77243
|
77244
|
79240
|
79241
|
79242
|
79243
|
79244
|
80519
|
80536
|
80604
|
80606
|
80608
|
80613
|
80626
|
80627
|
80628
|
80637
|
80639
|
80651
|
80861
|
80866
|
80868
|
80869
|
80870
|
80871
|
80872
|
80873
|
80947
|
85355
|
85356
|
85357
|
85358
|
85359
|
85376
|
85719
|
85720
|
85785
|
85828
|
86087
|
86173
|
86174
|
86175
|
86176
|
86177
|
86178
|
86179
|
86180
|
86181
|
86182
|
86183
|
86791
|
86792
|
86793
|
86794
|
86795
|
86796
|
86797
|
86798
|
86799
|
88417
|
88418
|
88419
|
88420
|
88421
|
88422
|
88423
|
88424
|
88425
|
88426
|
88427
|
88428
|
88429
|
88430
|
88431
|
88432
|
88493
|
88494
|
88495
|
88496
|
88497
|
88498
|
88499
|
88500
|
88501
|
88502
|
88503
|
88504
|
88505
|
88506
|
88507
|
88508
|
91205
|
91206
|
91207
|
91208
|
91209
|
91210
|
91211
|
91212
|
91213
|
91214
|
91215
|
91216
|
91217
|
91218
|
91219
|
92051
|
92120
|
92124
|
94436
|
94437
|
94438
|
94439
|
94440
|
94441
|
94442
|
94443
|
94444
|
94445
|
94446
|
94447
|
94448
|
94449
|
94450
|
94451
|
94452
|
99092
|
99093
|
99094
|
99095
|
99096
|
99097
|
99098
|
99099
|
99100
|
99101
|
99102
|
99103
|
99104
|
99105
|
99106
|
99107
|
99108
|
99109