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