Lines 19-25
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 6; |
22 |
use Test::More tests => 7; |
23 |
use Test::Exception; |
23 |
use Test::Exception; |
24 |
|
24 |
|
25 |
use Koha::Database; |
25 |
use Koha::Database; |
Lines 77-82
subtest 'add_guarantor() tests' => sub {
Link Here
|
77 |
$schema->storage->txn_rollback; |
77 |
$schema->storage->txn_rollback; |
78 |
}; |
78 |
}; |
79 |
|
79 |
|
|
|
80 |
subtest 'takeout' => sub { |
81 |
|
82 |
plan tests => 66; |
83 |
|
84 |
$schema->storage->txn_begin; |
85 |
|
86 |
my $test_objects = {}; |
87 |
|
88 |
my $patron = $builder->build_object( |
89 |
{ |
90 |
class => 'Koha::Patrons', |
91 |
} |
92 |
); |
93 |
|
94 |
my $someone_else = $builder->build_object( |
95 |
{ |
96 |
class => 'Koha::Patrons', |
97 |
} |
98 |
); |
99 |
|
100 |
my $result_source = Koha::Patron->new->_result()->result_source; |
101 |
foreach my $rel ( Koha::Patron->new->_result()->relationships() ) { |
102 |
my $related_source = $result_source->related_source($rel); |
103 |
|
104 |
# relationships() returns related columns, not tables, and therefore |
105 |
# we could arrive multiple times into the same table and had already |
106 |
# generated test data for that object. next; in such case. |
107 |
if ($test_objects->{$related_source->source_name}) { |
108 |
next; |
109 |
} |
110 |
|
111 |
my $rs = $related_source->resultset; |
112 |
my $info = $result_source->relationship_info($rel); |
113 |
|
114 |
# We are not interested in the "belongs_to" relationship of borrowers. |
115 |
# These are tables like branches, categories, sms_provider etc. |
116 |
if ($info->{'attrs'}->{'is_depends_on'}) { |
117 |
next; |
118 |
} |
119 |
|
120 |
my $source_name = $related_source->source_name; |
121 |
(my $rel_col = (keys %{$info->{'cond'}})[0]) =~ s/^foreign\.//; |
122 |
|
123 |
my $built = $builder->build( |
124 |
{ |
125 |
source => $source_name, |
126 |
value => { $rel_col => $patron->borrowernumber } |
127 |
} |
128 |
); |
129 |
|
130 |
$test_objects->{$related_source->source_name} = [ $built ]; |
131 |
|
132 |
# Create test data for someone else, to ensure we are only returning |
133 |
# this patron's data |
134 |
$builder->build( |
135 |
{ |
136 |
source => $source_name, |
137 |
value => { $rel_col => $someone_else->borrowernumber } |
138 |
} |
139 |
); |
140 |
|
141 |
} |
142 |
|
143 |
my $takeout = $patron->takeout; |
144 |
|
145 |
foreach my $rel ( Koha::Patron->new->_result()->relationships() ) { |
146 |
my $related_source = $result_source->related_source($rel); |
147 |
is_deeply( |
148 |
$takeout->{$related_source->source_name}, |
149 |
$test_objects->{$related_source->source_name}, |
150 |
"$rel included in takeout" |
151 |
); |
152 |
} |
153 |
|
154 |
$schema->storage->txn_rollback; |
155 |
}; |
156 |
|
80 |
subtest 'relationships_debt() tests' => sub { |
157 |
subtest 'relationships_debt() tests' => sub { |
81 |
|
158 |
|
82 |
plan tests => 168; |
159 |
plan tests => 168; |
83 |
- |
|
|