Bug 17499: Replace test subroutines with build_object
This patch replaces subroutines used to build test objects with call to $builder->build_object. To test prove that tests are still running with: prove t/db_dependent/Koha/Patron/Message/* Sponsored-by: Koha-Suomi Oy Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de> Signed-off-by: Michal Denar <black23@gmail.com> Signed-off-by: Sam Lau <samalau@gmail.com> Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
parent
5ed051b114
commit
325e998048
3 changed files with 27 additions and 122 deletions
|
@ -51,9 +51,9 @@ subtest 'Test Koha::Patron::Message::Preferences' => sub {
|
||||||
|
|
||||||
$schema->storage->txn_begin;
|
$schema->storage->txn_begin;
|
||||||
|
|
||||||
my $attribute = build_a_test_attribute();
|
my $attribute = $builder->build_object({ class => 'Koha::Patron::Message::Attributes' });
|
||||||
my $letter = build_a_test_letter();
|
my $letter = build_a_test_letter();
|
||||||
my $mtt = build_a_test_transport_type();
|
my $mtt = $builder->build_object({ class => 'Koha::Patron::Message::Transport::Types' });
|
||||||
Koha::Patron::Message::Transport->new({
|
Koha::Patron::Message::Transport->new({
|
||||||
message_attribute_id => $attribute->message_attribute_id,
|
message_attribute_id => $attribute->message_attribute_id,
|
||||||
message_transport_type => $mtt->message_transport_type,
|
message_transport_type => $mtt->message_transport_type,
|
||||||
|
@ -65,7 +65,7 @@ subtest 'Test Koha::Patron::Message::Preferences' => sub {
|
||||||
subtest 'Test for a patron' => sub {
|
subtest 'Test for a patron' => sub {
|
||||||
plan tests => 3;
|
plan tests => 3;
|
||||||
|
|
||||||
my $patron = build_a_test_patron();
|
my $patron = $builder->build_object({ class => 'Koha::Patrons' });
|
||||||
Koha::Patron::Message::Preference->new({
|
Koha::Patron::Message::Preference->new({
|
||||||
borrowernumber => $patron->borrowernumber,
|
borrowernumber => $patron->borrowernumber,
|
||||||
message_attribute_id => $attribute->message_attribute_id,
|
message_attribute_id => $attribute->message_attribute_id,
|
||||||
|
@ -99,7 +99,7 @@ subtest 'Test Koha::Patron::Message::Preferences' => sub {
|
||||||
};
|
};
|
||||||
|
|
||||||
subtest 'Test for a category' => sub {
|
subtest 'Test for a category' => sub {
|
||||||
my $category = build_a_test_category();
|
my $category = $builder->build_object({ class => 'Koha::Patron::Categories' });
|
||||||
Koha::Patron::Message::Preference->new({
|
Koha::Patron::Message::Preference->new({
|
||||||
categorycode => $category->categorycode,
|
categorycode => $category->categorycode,
|
||||||
message_attribute_id => $attribute->message_attribute_id,
|
message_attribute_id => $attribute->message_attribute_id,
|
||||||
|
@ -167,7 +167,7 @@ subtest 'Add preferences from defaults' => sub {
|
||||||
|
|
||||||
$schema->storage->txn_begin;
|
$schema->storage->txn_begin;
|
||||||
|
|
||||||
my $patron = build_a_test_patron();
|
my $patron = $builder->build_object({ class => 'Koha::Patrons' });
|
||||||
my ($default, $mtt1, $mtt2) = build_a_test_category_preference({
|
my ($default, $mtt1, $mtt2) = build_a_test_category_preference({
|
||||||
patron => $patron,
|
patron => $patron,
|
||||||
});
|
});
|
||||||
|
@ -198,7 +198,7 @@ subtest 'Test Koha::Patron::Message::Preference->message_transport_types' => sub
|
||||||
|
|
||||||
$schema->storage->txn_begin;
|
$schema->storage->txn_begin;
|
||||||
|
|
||||||
my $patron = build_a_test_patron();
|
my $patron = $builder->build_object({ class => 'Koha::Patrons' });
|
||||||
my ($preference, $mtt1, $mtt2) = build_a_test_complete_preference({
|
my ($preference, $mtt1, $mtt2) = build_a_test_complete_preference({
|
||||||
patron => $patron
|
patron => $patron
|
||||||
});
|
});
|
||||||
|
@ -261,7 +261,7 @@ HERE
|
||||||
my $transports = $pref->message_transport_types;
|
my $transports = $pref->message_transport_types;
|
||||||
is($appender, undef, 'Nothing in buffer yet');
|
is($appender, undef, 'Nothing in buffer yet');
|
||||||
|
|
||||||
my $mtt_new = build_a_test_transport_type();
|
my $mtt_new = $builder->build_object({ class => 'Koha::Patron::Message::Transport::Types' });
|
||||||
Koha::Patron::Message::Transport::Preference->new({
|
Koha::Patron::Message::Transport::Preference->new({
|
||||||
borrower_message_preference_id =>
|
borrower_message_preference_id =>
|
||||||
$pref->borrower_message_preference_id,
|
$pref->borrower_message_preference_id,
|
||||||
|
@ -286,7 +286,7 @@ HERE
|
||||||
|
|
||||||
$schema->storage->txn_begin;
|
$schema->storage->txn_begin;
|
||||||
|
|
||||||
my $patron = build_a_test_patron();
|
my $patron = $builder->build_object({ class => 'Koha::Patrons' });
|
||||||
my ($preference, $mtt1, $mtt2) = build_a_test_complete_preference({
|
my ($preference, $mtt1, $mtt2) = build_a_test_complete_preference({
|
||||||
patron => $patron
|
patron => $patron
|
||||||
});
|
});
|
||||||
|
@ -386,10 +386,10 @@ HERE
|
||||||
|
|
||||||
$schema->storage->txn_begin;
|
$schema->storage->txn_begin;
|
||||||
|
|
||||||
my $patron = build_a_test_patron();
|
my $patron = $builder->build_object({ class => 'Koha::Patrons' });
|
||||||
my $letter = build_a_test_letter();
|
my $letter = build_a_test_letter();
|
||||||
my $attribute = build_a_test_attribute();
|
my $attribute = $builder->build_object({ class => 'Koha::Patron::Message::Attributes' });
|
||||||
my $mtt = build_a_test_transport_type();
|
my $mtt = $builder->build_object({ class => 'Koha::Patron::Message::Transport::Types' });
|
||||||
Koha::Patron::Message::Transport->new({
|
Koha::Patron::Message::Transport->new({
|
||||||
message_attribute_id => $attribute->message_attribute_id,
|
message_attribute_id => $attribute->message_attribute_id,
|
||||||
message_transport_type => $mtt->message_transport_type,
|
message_transport_type => $mtt->message_transport_type,
|
||||||
|
@ -421,8 +421,8 @@ subtest 'Test Koha::Patron::Message::Preference->message_name' => sub {
|
||||||
|
|
||||||
$schema->storage->txn_begin;
|
$schema->storage->txn_begin;
|
||||||
|
|
||||||
my $patron = build_a_test_patron();
|
my $patron = $builder->build_object({ class => 'Koha::Patrons' });
|
||||||
my $attribute = build_a_test_attribute();
|
my $attribute = $builder->build_object({ class => 'Koha::Patron::Message::Attributes' });
|
||||||
my ($preference, $mtt1, $mtt2) = build_a_test_complete_preference({
|
my ($preference, $mtt1, $mtt2) = build_a_test_complete_preference({
|
||||||
patron => $patron,
|
patron => $patron,
|
||||||
attr => $attribute,
|
attr => $attribute,
|
||||||
|
@ -453,7 +453,7 @@ subtest 'Test adding a new preference with invalid parameters' => sub {
|
||||||
|
|
||||||
$schema->storage->txn_begin;
|
$schema->storage->txn_begin;
|
||||||
|
|
||||||
my $patron = build_a_test_patron();
|
my $patron = $builder->build_object({ class => 'Koha::Patrons' });
|
||||||
eval { Koha::Patron::Message::Preference->new({
|
eval { Koha::Patron::Message::Preference->new({
|
||||||
borrowernumber => $patron->borrowernumber,
|
borrowernumber => $patron->borrowernumber,
|
||||||
categorycode => $patron->categorycode,
|
categorycode => $patron->categorycode,
|
||||||
|
@ -489,7 +489,7 @@ subtest 'Test adding a new preference with invalid parameters' => sub {
|
||||||
.' was the categorycode.');
|
.' was the categorycode.');
|
||||||
|
|
||||||
my $attribute = build_a_test_attribute({ takes_days => 0 });
|
my $attribute = build_a_test_attribute({ takes_days => 0 });
|
||||||
my $patron = build_a_test_patron();
|
my $patron = $builder->build_object({ class => 'Koha::Patrons' });
|
||||||
eval { Koha::Patron::Message::Preference->new({
|
eval { Koha::Patron::Message::Preference->new({
|
||||||
borrowernumber => $patron->borrowernumber,
|
borrowernumber => $patron->borrowernumber,
|
||||||
message_attribute_id => $attribute->message_attribute_id,
|
message_attribute_id => $attribute->message_attribute_id,
|
||||||
|
@ -523,7 +523,7 @@ subtest 'Test adding a new preference with invalid parameters' => sub {
|
||||||
is ($@->parameter, 'message_transport_types', 'The previous exception '
|
is ($@->parameter, 'message_transport_types', 'The previous exception '
|
||||||
.'tells us it was the message_transport_types.');
|
.'tells us it was the message_transport_types.');
|
||||||
|
|
||||||
my $mtt_new = build_a_test_transport_type();
|
my $mtt_new = $builder->build_object({ class => 'Koha::Patron::Message::Transport::Types' });
|
||||||
eval {
|
eval {
|
||||||
Koha::Patron::Message::Preference->new({
|
Koha::Patron::Message::Preference->new({
|
||||||
borrowernumber => $patron->borrowernumber,
|
borrowernumber => $patron->borrowernumber,
|
||||||
|
@ -591,9 +591,9 @@ subtest 'Test adding a new preference with invalid parameters' => sub {
|
||||||
|
|
||||||
$schema->storage->txn_begin;
|
$schema->storage->txn_begin;
|
||||||
|
|
||||||
my $attribute = build_a_test_attribute();
|
my $attribute = $builder->build_object({ class => 'Koha::Patron::Message::Attributes' });
|
||||||
my $letter = build_a_test_letter();
|
my $letter = build_a_test_letter();
|
||||||
my $mtt = build_a_test_transport_type();
|
my $mtt = $builder->build_object({ class => 'Koha::Patron::Message::Transport::Types' });
|
||||||
Koha::Patron::Message::Transport->new({
|
Koha::Patron::Message::Transport->new({
|
||||||
message_attribute_id => $attribute->message_attribute_id,
|
message_attribute_id => $attribute->message_attribute_id,
|
||||||
message_transport_type => $mtt->message_transport_type,
|
message_transport_type => $mtt->message_transport_type,
|
||||||
|
@ -601,7 +601,7 @@ subtest 'Test adding a new preference with invalid parameters' => sub {
|
||||||
letter_module => $letter->module,
|
letter_module => $letter->module,
|
||||||
letter_code => $letter->code,
|
letter_code => $letter->code,
|
||||||
})->store;
|
})->store;
|
||||||
my $patron = build_a_test_patron();
|
my $patron = $builder->build_object({ class => 'Koha::Patrons' });
|
||||||
my $preference = Koha::Patron::Message::Preference->new({
|
my $preference = Koha::Patron::Message::Preference->new({
|
||||||
borrowernumber => $patron->borrowernumber,
|
borrowernumber => $patron->borrowernumber,
|
||||||
message_attribute_id => $attribute->message_attribute_id,
|
message_attribute_id => $attribute->message_attribute_id,
|
||||||
|
@ -640,13 +640,6 @@ sub build_a_test_attribute {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub build_a_test_category {
|
|
||||||
my $categorycode = $builder->build({
|
|
||||||
source => 'Category' })->{categorycode};
|
|
||||||
|
|
||||||
return Koha::Patron::Categories->find($categorycode);
|
|
||||||
}
|
|
||||||
|
|
||||||
sub build_a_test_letter {
|
sub build_a_test_letter {
|
||||||
my ($params) = @_;
|
my ($params) = @_;
|
||||||
|
|
||||||
|
@ -669,26 +662,6 @@ sub build_a_test_letter {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
sub build_a_test_patron {
|
|
||||||
my $categorycode = $builder->build({
|
|
||||||
source => 'Category' })->{categorycode};
|
|
||||||
my $branchcode = $builder->build({
|
|
||||||
source => 'Branch' })->{branchcode};
|
|
||||||
my $borrowernumber = $builder->build({
|
|
||||||
source => 'Borrower' })->{borrowernumber};
|
|
||||||
|
|
||||||
return Koha::Patrons->find($borrowernumber);
|
|
||||||
}
|
|
||||||
|
|
||||||
sub build_a_test_transport_type {
|
|
||||||
my $mtt = $builder->build({
|
|
||||||
source => 'MessageTransportType' });
|
|
||||||
|
|
||||||
return Koha::Patron::Message::Transport::Types->find(
|
|
||||||
$mtt->{message_transport_type}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
sub build_a_test_category_preference {
|
sub build_a_test_category_preference {
|
||||||
my ($params) = @_;
|
my ($params) = @_;
|
||||||
|
|
||||||
|
@ -698,8 +671,8 @@ sub build_a_test_category_preference {
|
||||||
: build_a_test_attribute($params->{days_in_advance});
|
: build_a_test_attribute($params->{days_in_advance});
|
||||||
|
|
||||||
my $letter = $params->{letter} ? $params->{letter} : build_a_test_letter();
|
my $letter = $params->{letter} ? $params->{letter} : build_a_test_letter();
|
||||||
my $mtt1 = $params->{mtt1} ? $params->{mtt1} : build_a_test_transport_type();
|
my $mtt1 = $params->{mtt1} ? $params->{mtt1} : $builder->build_object({ class => 'Koha::Patron::Message::Transport::Types' });
|
||||||
my $mtt2 = $params->{mtt2} ? $params->{mtt2} : build_a_test_transport_type();
|
my $mtt2 = $params->{mtt2} ? $params->{mtt2} : $builder->build_object({ class => 'Koha::Patron::Message::Transport::Types' });
|
||||||
|
|
||||||
Koha::Patron::Message::Transport->new({
|
Koha::Patron::Message::Transport->new({
|
||||||
message_attribute_id => $attr->message_attribute_id,
|
message_attribute_id => $attr->message_attribute_id,
|
||||||
|
|
|
@ -47,8 +47,8 @@ subtest 'Test Koha::Patron::Message::Transport::Preferences' => sub {
|
||||||
|
|
||||||
$schema->storage->txn_begin;
|
$schema->storage->txn_begin;
|
||||||
|
|
||||||
my $attribute = build_a_test_attribute();
|
my $attribute = $builder->build_object({ class => 'Koha::Patron::Message::Attributes' });
|
||||||
my $mtt = build_a_test_transport_type();
|
my $mtt = $builder->build_object({ class => 'Koha::Patron::Message::Transport::Types' });
|
||||||
my $letter = build_a_test_letter({
|
my $letter = build_a_test_letter({
|
||||||
mtt => $mtt->message_transport_type
|
mtt => $mtt->message_transport_type
|
||||||
});
|
});
|
||||||
|
@ -61,7 +61,7 @@ subtest 'Test Koha::Patron::Message::Transport::Preferences' => sub {
|
||||||
})->store;
|
})->store;
|
||||||
|
|
||||||
subtest 'For a patron' => sub {
|
subtest 'For a patron' => sub {
|
||||||
my $patron = build_a_test_patron();
|
my $patron = $builder->build_object({ class => 'Koha::Patrons' });
|
||||||
my $preference = Koha::Patron::Message::Preference->new({
|
my $preference = Koha::Patron::Message::Preference->new({
|
||||||
borrowernumber => $patron->borrowernumber,
|
borrowernumber => $patron->borrowernumber,
|
||||||
message_attribute_id => $attribute->message_attribute_id,
|
message_attribute_id => $attribute->message_attribute_id,
|
||||||
|
@ -85,7 +85,7 @@ subtest 'Test Koha::Patron::Message::Transport::Preferences' => sub {
|
||||||
};
|
};
|
||||||
|
|
||||||
subtest 'For a category' => sub {
|
subtest 'For a category' => sub {
|
||||||
my $category = build_a_test_category();
|
my $category = $builder->build_object({ class => 'Koha::Patron::Categories' });
|
||||||
my $preference = Koha::Patron::Message::Preference->new({
|
my $preference = Koha::Patron::Message::Preference->new({
|
||||||
categorycode => $category->categorycode,
|
categorycode => $category->categorycode,
|
||||||
message_attribute_id => $attribute->message_attribute_id,
|
message_attribute_id => $attribute->message_attribute_id,
|
||||||
|
@ -111,29 +111,6 @@ subtest 'Test Koha::Patron::Message::Transport::Preferences' => sub {
|
||||||
$schema->storage->txn_rollback;
|
$schema->storage->txn_rollback;
|
||||||
};
|
};
|
||||||
|
|
||||||
sub build_a_test_attribute {
|
|
||||||
my ($params) = @_;
|
|
||||||
|
|
||||||
$params->{takes_days} = $params->{takes_days} && $params->{takes_days} > 0
|
|
||||||
? 1 : 0;
|
|
||||||
|
|
||||||
my $attribute = $builder->build({
|
|
||||||
source => 'MessageAttribute',
|
|
||||||
value => $params,
|
|
||||||
});
|
|
||||||
|
|
||||||
return Koha::Patron::Message::Attributes->find(
|
|
||||||
$attribute->{message_attribute_id}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
sub build_a_test_category {
|
|
||||||
my $categorycode = $builder->build({
|
|
||||||
source => 'Category' })->{categorycode};
|
|
||||||
|
|
||||||
return Koha::Patron::Categories->find($categorycode);
|
|
||||||
}
|
|
||||||
|
|
||||||
sub build_a_test_letter {
|
sub build_a_test_letter {
|
||||||
my ($params) = @_;
|
my ($params) = @_;
|
||||||
|
|
||||||
|
@ -156,24 +133,4 @@ sub build_a_test_letter {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
sub build_a_test_patron {
|
|
||||||
my $categorycode = $builder->build({
|
|
||||||
source => 'Category' })->{categorycode};
|
|
||||||
my $branchcode = $builder->build({
|
|
||||||
source => 'Branch' })->{branchcode};
|
|
||||||
my $borrowernumber = $builder->build({
|
|
||||||
source => 'Borrower' })->{borrowernumber};
|
|
||||||
|
|
||||||
return Koha::Patrons->find($borrowernumber);
|
|
||||||
}
|
|
||||||
|
|
||||||
sub build_a_test_transport_type {
|
|
||||||
my $mtt = $builder->build({
|
|
||||||
source => 'MessageTransportType' });
|
|
||||||
|
|
||||||
return Koha::Patron::Message::Transport::Types->find(
|
|
||||||
$mtt->{message_transport_type}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
@ -42,8 +42,8 @@ subtest 'Test Koha::Patron::Message::Transports' => sub {
|
||||||
|
|
||||||
$schema->storage->txn_begin;
|
$schema->storage->txn_begin;
|
||||||
|
|
||||||
my $attribute = build_a_test_attribute();
|
my $attribute = $builder->build_object({ class => 'Koha::Patron::Message::Attributes' });
|
||||||
my $mtt = build_a_test_transport_type();
|
my $mtt = $builder->build_object({ class => 'Koha::Patron::Message::Transport::Types' });
|
||||||
my $letter = build_a_test_letter({
|
my $letter = build_a_test_letter({
|
||||||
mtt => $mtt->message_transport_type
|
mtt => $mtt->message_transport_type
|
||||||
});
|
});
|
||||||
|
@ -69,22 +69,6 @@ subtest 'Test Koha::Patron::Message::Transports' => sub {
|
||||||
$schema->storage->txn_rollback;
|
$schema->storage->txn_rollback;
|
||||||
};
|
};
|
||||||
|
|
||||||
sub build_a_test_attribute {
|
|
||||||
my ($params) = @_;
|
|
||||||
|
|
||||||
$params->{takes_days} = $params->{takes_days} && $params->{takes_days} > 0
|
|
||||||
? 1 : 0;
|
|
||||||
|
|
||||||
my $attribute = $builder->build({
|
|
||||||
source => 'MessageAttribute',
|
|
||||||
value => $params,
|
|
||||||
});
|
|
||||||
|
|
||||||
return Koha::Patron::Message::Attributes->find(
|
|
||||||
$attribute->{message_attribute_id}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
sub build_a_test_letter {
|
sub build_a_test_letter {
|
||||||
my ($params) = @_;
|
my ($params) = @_;
|
||||||
|
|
||||||
|
@ -107,13 +91,4 @@ sub build_a_test_letter {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
sub build_a_test_transport_type {
|
|
||||||
my $mtt = $builder->build({
|
|
||||||
source => 'MessageTransportType' });
|
|
||||||
|
|
||||||
return Koha::Patron::Message::Transport::Types->find(
|
|
||||||
$mtt->{message_transport_type}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
Loading…
Reference in a new issue