Lines 19-25
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 10; |
22 |
use Test::More tests => 11; |
23 |
|
23 |
|
24 |
use Koha::Import::Records; |
24 |
use Koha::Import::Records; |
25 |
use Koha::Database; |
25 |
use Koha::Database; |
Lines 86-89
is_deeply( $matches->next->unblessed, $match_2->unblessed, "Match 2 is the chose
Link Here
|
86 |
$retrieved_record_1->delete; |
86 |
$retrieved_record_1->delete; |
87 |
is( Koha::Import::Records->search->count, $nb_of_records + 1, 'Delete should have deleted the record' ); |
87 |
is( Koha::Import::Records->search->count, $nb_of_records + 1, 'Delete should have deleted the record' ); |
88 |
|
88 |
|
|
|
89 |
subtest 'replace' => sub { |
90 |
plan tests => 4; |
91 |
|
92 |
|
93 |
# Replace biblio |
94 |
my $import_record = $builder->build_object({ class => 'Koha::Import::Records' }); |
95 |
my $import_record_biblio = $builder->build_object({ |
96 |
class => 'Koha::Import::Record::Biblios', |
97 |
value => { |
98 |
import_record_id => $import_record->id |
99 |
} |
100 |
}); |
101 |
|
102 |
my $koha_biblio = $builder->build_sample_biblio({ title => "The before" }); |
103 |
my $koha_xml = $koha_biblio->metadata->record->as_xml; |
104 |
my $import_biblio = $builder->build_sample_biblio({ title => "The after" }); |
105 |
$import_record->marcxml( $import_biblio->metadata->record->as_xml )->store->discard_changes; |
106 |
|
107 |
$import_record->replace({ biblio => $koha_biblio }); |
108 |
$koha_biblio->discard_changes; |
109 |
$import_record->discard_changes; |
110 |
is( $koha_biblio->title, "The after", "The Koha biblio is successfully updated" ); |
111 |
is( $import_record->marcxml_old, $koha_xml, "The old marcxml in import records is correctly updated" ); |
112 |
|
113 |
# Replace authority |
114 |
my $auth_record = MARC::Record->new; |
115 |
$auth_record->append_fields( |
116 |
MARC::Field->new( '100', '', '', a => 'Author' ), |
117 |
); |
118 |
my $auth_id = C4::AuthoritiesMarc::AddAuthority($auth_record, undef, 'PERSO_NAME'); |
119 |
my $koha_auth = Koha::Authorities->find( $auth_id ); |
120 |
$koha_xml = $koha_auth->marcxml; |
121 |
$import_record = $builder->build_object({ class => 'Koha::Import::Records' }); |
122 |
my $import_record_auth = $builder->build_object({ |
123 |
class => 'Koha::Import::Record::Auths', |
124 |
value => { |
125 |
import_record_id => $import_record->id |
126 |
} |
127 |
}); |
128 |
|
129 |
|
130 |
my $field = $auth_record->field('100'); |
131 |
$field->update( 'a' => 'Other author' ); |
132 |
$import_record->marcxml( $auth_record->as_xml )->store->discard_changes; |
133 |
|
134 |
$import_record->replace({ authority => $koha_auth }); |
135 |
$koha_auth->discard_changes; |
136 |
$import_record->discard_changes; |
137 |
my $updated_record = MARC::Record->new_from_xml( $koha_auth->marcxml, 'UTF-8'); |
138 |
is( $updated_record->field('100')->as_string, $auth_record->field('100')->as_string, "The Koha auhtority record is correctly updated" ); |
139 |
is( $import_record->marcxml_old, $koha_xml, "The old marcxml in import record is correctly updated" ); |
140 |
|
141 |
}; |
142 |
|
89 |
$schema->storage->txn_rollback; |
143 |
$schema->storage->txn_rollback; |
90 |
- |
|
|