|
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 |
|
23 |
|
| 24 |
use t::lib::TestBuilder; |
24 |
use t::lib::TestBuilder; |
| 25 |
use t::lib::Mocks; |
25 |
use t::lib::Mocks; |
|
Lines 69-74
subtest 'new() tests' => sub {
Link Here
|
| 69 |
$schema->storage->txn_rollback; |
69 |
$schema->storage->txn_rollback; |
| 70 |
}; |
70 |
}; |
| 71 |
|
71 |
|
|
|
72 |
subtest 'store' => sub { |
| 73 |
|
| 74 |
plan tests => 4; |
| 75 |
|
| 76 |
$schema->storage->txn_begin; |
| 77 |
|
| 78 |
# Create 2 attribute types without restrictions: |
| 79 |
# Repeatable and can have the same values |
| 80 |
my $attr_type_1 = $builder->build_object( |
| 81 |
{ |
| 82 |
class => 'Koha::Patron::Attribute::Types', |
| 83 |
value => { repeatable => 1, unique_id => 0 } |
| 84 |
} |
| 85 |
); |
| 86 |
my $attr_type_2 = $builder->build_object( |
| 87 |
{ |
| 88 |
class => 'Koha::Patron::Attribute::Types', |
| 89 |
value => { repeatable => 1, unique_id => 0 } |
| 90 |
} |
| 91 |
); |
| 92 |
|
| 93 |
# Patron 1 has twice the attribute 1 and attribute 2 |
| 94 |
# Patron 2 has attribute 1 and attribute 2="42" |
| 95 |
# Patron 3 has attribute 2="42" |
| 96 |
# Attribute 1 cannot remove repeatable |
| 97 |
# Attribute 2 cannot set unique_id |
| 98 |
my $patron_1 = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 99 |
my $patron_2 = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 100 |
my $patron_3 = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 101 |
|
| 102 |
my $attribute_111 = $builder->build_object( |
| 103 |
{ |
| 104 |
class => 'Koha::Patron::Attributes', |
| 105 |
value => { |
| 106 |
borrowernumber => $patron_1->borrowernumber, |
| 107 |
code => $attr_type_1->code |
| 108 |
} |
| 109 |
} |
| 110 |
); |
| 111 |
my $attribute_112 = $builder->build_object( |
| 112 |
{ |
| 113 |
class => 'Koha::Patron::Attributes', |
| 114 |
value => { |
| 115 |
borrowernumber => $patron_1->borrowernumber, |
| 116 |
code => $attr_type_1->code |
| 117 |
} |
| 118 |
} |
| 119 |
); |
| 120 |
|
| 121 |
my $attribute_211 = $builder->build_object( |
| 122 |
{ |
| 123 |
class => 'Koha::Patron::Attributes', |
| 124 |
value => { |
| 125 |
borrowernumber => $patron_2->borrowernumber, |
| 126 |
code => $attr_type_1->code |
| 127 |
} |
| 128 |
} |
| 129 |
); |
| 130 |
my $attribute_221 = $builder->build_object( |
| 131 |
{ |
| 132 |
class => 'Koha::Patron::Attributes', |
| 133 |
value => { |
| 134 |
borrowernumber => $patron_2->borrowernumber, |
| 135 |
code => $attr_type_2->code, |
| 136 |
attribute => '42', |
| 137 |
} |
| 138 |
} |
| 139 |
); |
| 140 |
|
| 141 |
my $attribute_321 = $builder->build_object( |
| 142 |
{ |
| 143 |
class => 'Koha::Patron::Attributes', |
| 144 |
value => { |
| 145 |
borrowernumber => $patron_3->borrowernumber, |
| 146 |
code => $attr_type_2->code, |
| 147 |
attribute => '42', |
| 148 |
} |
| 149 |
} |
| 150 |
); |
| 151 |
|
| 152 |
throws_ok { |
| 153 |
$attr_type_1->repeatable(0)->store; |
| 154 |
} |
| 155 |
'Koha::Exceptions::Patron::Attribute::Type::CannotChangeProperty', ""; |
| 156 |
|
| 157 |
$attribute_112->delete; |
| 158 |
ok($attr_type_1->set({ unique_id => 1, repeatable => 0 })->store); |
| 159 |
|
| 160 |
throws_ok { |
| 161 |
$attr_type_2->unique_id(1)->store; |
| 162 |
} |
| 163 |
'Koha::Exceptions::Patron::Attribute::Type::CannotChangeProperty', ""; |
| 164 |
|
| 165 |
$attribute_321->attribute(43)->store; |
| 166 |
ok($attr_type_2->set({ unique_id => 1, repeatable => 0 })->store); |
| 167 |
|
| 168 |
$schema->storage->txn_rollback; |
| 169 |
|
| 170 |
}; |
| 171 |
|
| 72 |
subtest 'library_limits() tests' => sub { |
172 |
subtest 'library_limits() tests' => sub { |
| 73 |
|
173 |
|
| 74 |
plan tests => 13; |
174 |
plan tests => 13; |
| 75 |
- |
|
|