View | Details | Raw Unified | Return to bug 11844
Collapse All | Expand All

(-)a/Koha/Object/Mixin/AdditionalFields.pm (+1 lines)
Lines 1-6 Link Here
1
package Koha::Object::Mixin::AdditionalFields;
1
package Koha::Object::Mixin::AdditionalFields;
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
use Koha::AdditionalFields;
4
use Koha::AdditionalFieldValues;
5
use Koha::AdditionalFieldValues;
5
6
6
=head1 NAME
7
=head1 NAME
(-)a/t/db_dependent/Acquisition/TransferOrder.t (-1 / +37 lines)
Lines 2-8 Link Here
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
4
5
use Test::More tests => 13;
5
use Test::More tests => 14;
6
use C4::Context;
6
use C4::Context;
7
use C4::Acquisition qw( NewBasket GetOrders GetOrder TransferOrder SearchOrders ModReceiveOrder CancelReceipt );
7
use C4::Acquisition qw( NewBasket GetOrders GetOrder TransferOrder SearchOrders ModReceiveOrder CancelReceipt );
8
use C4::Biblio;
8
use C4::Biblio;
Lines 14-19 use Koha::Acquisition::Booksellers; Link Here
14
use Koha::Acquisition::Orders;
14
use Koha::Acquisition::Orders;
15
use t::lib::TestBuilder;
15
use t::lib::TestBuilder;
16
use MARC::Record;
16
use MARC::Record;
17
use String::Random qw(random_string);
17
18
18
my $schema = Koha::Database->new()->schema();
19
my $schema = Koha::Database->new()->schema();
19
$schema->storage->txn_begin();
20
$schema->storage->txn_begin();
Lines 110-113 $order = GetOrder( $newordernumber ); Link Here
110
is ( $order->{ordernumber}, $newordernumber, 'Regression test Bug 11549: After a transfer, receive and cancel the receive should be possible.' );
111
is ( $order->{ordernumber}, $newordernumber, 'Regression test Bug 11549: After a transfer, receive and cancel the receive should be possible.' );
111
is ( $order->{basketno}, $basketno2, 'Regression test Bug 11549: The order still exist in the basket where the transfer has been done.');
112
is ( $order->{basketno}, $basketno2, 'Regression test Bug 11549: The order still exist in the basket where the transfer has been done.');
112
113
114
subtest 'TransferOrder should copy additional fields' => sub {
115
    plan tests => 2;
116
117
    my $field = Koha::AdditionalField->new(
118
        {
119
            tablename => 'aqorders',
120
            name => random_string('c' x 100),
121
        }
122
    );
123
    $field->store()->discard_changes();
124
    my $order = Koha::Acquisition::Order->new(
125
        {
126
            basketno => $basketno1,
127
            quantity => 2,
128
            biblionumber => $biblionumber,
129
            budget_id => $budget->{budget_id},
130
        }
131
    )->store;
132
    $order->set_additional_fields(
133
        [
134
            {
135
                id => $field->id,
136
                value => 'additional field value',
137
            },
138
        ]
139
    );
140
141
    my $newordernumber = TransferOrder($order->ordernumber, $basketno2);
142
    my $neworder = Koha::Acquisition::Orders->find($newordernumber);
143
    my $field_values = $neworder->additional_field_values()->as_list;
144
145
    is(scalar @$field_values, 1, 'transfered order has one additional field value');
146
    is($field_values->[0]->value, 'additional field value', 'transfered order additional field has the correct value');
147
};
148
113
$schema->storage->txn_rollback();
149
$schema->storage->txn_rollback();
(-)a/t/db_dependent/Koha/AdditionalField.t (+82 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
5
use Test::More tests => 2;
6
use String::Random qw(random_string);
7
8
use Koha::AuthorisedValueCategory;
9
10
BEGIN {
11
    use_ok('Koha::AdditionalField');
12
}
13
14
my $schema = Koha::Database->schema;
15
16
subtest 'effective_authorised_value_category' => sub {
17
    plan tests => 4;
18
19
    $schema->txn_begin;
20
21
    my $av_category_name = random_string('C' x 32);
22
    my $av_category = Koha::AuthorisedValueCategory->new({ category_name => $av_category_name });
23
    $av_category->store()->discard_changes();
24
25
    my $field = Koha::AdditionalField->new(
26
        {
27
            tablename => random_string('c' x 100),
28
            name => random_string('c' x 100),
29
        }
30
    );
31
    $field->store()->discard_changes();
32
33
    is($field->effective_authorised_value_category, '', 'no default category');
34
35
    $field = Koha::AdditionalField->new(
36
        {
37
            tablename => random_string('c' x 100),
38
            name => random_string('c' x 100),
39
            authorised_value_category => $av_category_name,
40
        }
41
    );
42
    $field->store()->discard_changes();
43
44
    is($field->effective_authorised_value_category, $av_category_name, 'returns authorised_value_category if set');
45
46
    my $mss = Koha::MarcSubfieldStructure->new(
47
        {
48
            frameworkcode => '',
49
            tagfield => '999',
50
            tagsubfield => 'Z',
51
            authorised_value => $av_category_name,
52
        }
53
    );
54
    $mss->store();
55
    $field = Koha::AdditionalField->new(
56
        {
57
            tablename => random_string('c' x 100),
58
            name => random_string('c' x 100),
59
            marcfield => '999$Z',
60
        }
61
    );
62
    $field->store()->discard_changes();
63
64
    is($field->effective_authorised_value_category, $av_category_name, 'returns MARC subfield authorised value category if set');
65
66
    my $av2_category_name = random_string('C' x 32);
67
    my $av2_category = Koha::AuthorisedValueCategory->new({ category_name => $av2_category_name });
68
    $av2_category->store()->discard_changes();
69
    $field = Koha::AdditionalField->new(
70
        {
71
            tablename => random_string('c' x 100),
72
            name => random_string('c' x 100),
73
            authorised_value_category => $av2_category_name,
74
            marcfield => '999$Z',
75
        }
76
    );
77
    $field->store()->discard_changes();
78
79
    is($field->effective_authorised_value_category, $av2_category_name, 'returns authorised_value_category if both authorised_value_category and marcfield are set');
80
81
    $schema->txn_rollback;
82
};
(-)a/t/db_dependent/Koha/Object/Mixin/AdditionalFields.t (-1 / +91 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
use Test::More tests => 2;
5
use t::lib::TestBuilder;
6
use String::Random qw(random_string);
7
use Koha::Database;
8
use Koha::Subscription;
9
use Koha::AdditionalField;
10
use C4::Context;
11
12
my $builder = t::lib::TestBuilder->new;
13
my $schema = Koha::Database->schema;
14
15
subtest 'set_additional_fields with marcfield_mode = "get"' => sub {
16
    plan tests => 1;
17
18
    $schema->txn_begin;
19
20
    my $biblio = $builder->build_sample_biblio();
21
    my $record = $biblio->record;
22
    $record->append_fields(
23
        MARC::Field->new('999', '', '', 'Z' => 'some value'),
24
    );
25
    $biblio->metadata->metadata($record->as_xml_record(C4::Context->preference('marcflavour')));
26
    $biblio->metadata->store()->discard_changes();
27
    my $subscription = Koha::Subscription->new(
28
        {
29
            biblionumber => $biblio->biblionumber,
30
        }
31
    );
32
    $subscription->store()->discard_changes();
33
34
    my $field = Koha::AdditionalField->new(
35
        {
36
            tablename => 'subscription',
37
            name => random_string('c' x 100),
38
            marcfield => '999$Z',
39
            marcfield_mode => 'get',
40
        }
41
    );
42
    $field->store()->discard_changes();
43
    $subscription->set_additional_fields(
44
        [
45
            { id => $field->id },
46
        ]
47
    );
48
49
    my $values = $subscription->additional_field_values()->as_list();
50
51
    is($values->[0]->value, 'some value', 'value was copied from the biblio record to the field');
52
53
    $schema->txn_rollback;
54
};
55
56
subtest 'set_additional_fields with marcfield_mode = "set"' => sub {
57
    plan tests => 1;
58
59
    $schema->txn_begin;
60
61
    my $biblio = $builder->build_sample_biblio();
62
    my $subscription = Koha::Subscription->new(
63
        {
64
            biblionumber => $biblio->biblionumber,
65
        }
66
    );
67
    $subscription->store()->discard_changes();
68
69
    my $field = Koha::AdditionalField->new(
70
        {
71
            tablename => 'subscription',
72
            name => random_string('c' x 100),
73
            marcfield => '999$Z',
74
            marcfield_mode => 'set',
75
        }
76
    );
77
    $field->store()->discard_changes();
78
    $subscription->set_additional_fields(
79
        [
80
            {
81
                id => $field->id,
82
                value => 'some value',
83
            },
84
        ]
85
    );
86
87
    my $record = $biblio->record;
88
    is($record->subfield('999', 'Z'), 'some value', 'value was copied from the field to the biblio record');
89
90
    $schema->txn_rollback;
91
};

Return to bug 11844