|
Lines 20-26
Link Here
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Data::Dumper; |
22 |
use Data::Dumper; |
| 23 |
use Test::More tests => 24; |
23 |
use Test::More tests => 13; |
| 24 |
|
24 |
|
| 25 |
use t::lib::Mocks; |
25 |
use t::lib::Mocks; |
| 26 |
use t::lib::TestBuilder; |
26 |
use t::lib::TestBuilder; |
|
Lines 40-93
BEGIN {
Link Here
|
| 40 |
my $database = Koha::Database->new(); |
40 |
my $database = Koha::Database->new(); |
| 41 |
my $schema = $database->schema(); |
41 |
my $schema = $database->schema(); |
| 42 |
$schema->txn_begin; |
42 |
$schema->txn_begin; |
| 43 |
Koha::ItemTypes->delete; |
|
|
| 44 |
|
43 |
|
| 45 |
Koha::ItemType->new( |
44 |
my $builder = t::lib::TestBuilder->new; |
| 46 |
{ |
45 |
my $initial_count = Koha::ItemTypes->search->count; |
| 47 |
itemtype => 'type1', |
46 |
|
| 48 |
description => 'description', |
47 |
my $parent1 = $builder->build_object({ class => 'Koha::ItemTypes', value => { description => 'description' } }); |
| 49 |
rentalcharge => '0.00', |
48 |
my $child1 = $builder->build_object({ |
| 50 |
imageurl => 'imageurl', |
49 |
class => 'Koha::ItemTypes', |
| 51 |
summary => 'summary', |
50 |
value => { |
| 52 |
checkinmsg => 'checkinmsg', |
51 |
parent_type => $parent1->itemtype, |
| 53 |
checkinmsgtype => 'checkinmsgtype', |
52 |
description => 'description', |
| 54 |
processfee => '0.00', |
53 |
} |
| 55 |
defaultreplacecost => '0.00', |
54 |
}); |
| 56 |
} |
55 |
my $child2 = $builder->build_object({ |
| 57 |
)->store; |
56 |
class => 'Koha::ItemTypes', |
| 58 |
|
57 |
value => { |
| 59 |
Koha::ItemType->new( |
58 |
parent_type => $parent1->itemtype, |
| 60 |
{ |
59 |
description => 'description', |
| 61 |
itemtype => 'type2', |
60 |
} |
| 62 |
description => 'description', |
61 |
}); |
| 63 |
rentalcharge => '0.00', |
62 |
my $child3 = $builder->build_object({ |
| 64 |
imageurl => 'imageurl', |
63 |
class => 'Koha::ItemTypes', |
| 65 |
summary => 'summary', |
64 |
value => { |
| 66 |
checkinmsg => 'checkinmsg', |
65 |
parent_type => $parent1->itemtype, |
| 67 |
checkinmsgtype => 'checkinmsgtype', |
66 |
description => 'description', |
| 68 |
processfee => '0.00', |
67 |
} |
| 69 |
defaultreplacecost => '0.00', |
68 |
}); |
| 70 |
} |
|
|
| 71 |
)->store; |
| 72 |
|
| 73 |
Koha::ItemType->new( |
| 74 |
{ |
| 75 |
itemtype => 'type3', |
| 76 |
description => 'description', |
| 77 |
rentalcharge => '0.00', |
| 78 |
imageurl => 'imageurl', |
| 79 |
summary => 'summary', |
| 80 |
checkinmsg => 'checkinmsg', |
| 81 |
checkinmsgtype => 'checkinmsgtype', |
| 82 |
processfee => '0.00', |
| 83 |
defaultreplacecost => '0.00', |
| 84 |
} |
| 85 |
)->store; |
| 86 |
|
69 |
|
| 87 |
Koha::Localization->new( |
70 |
Koha::Localization->new( |
| 88 |
{ |
71 |
{ |
| 89 |
entity => 'itemtypes', |
72 |
entity => 'itemtypes', |
| 90 |
code => 'type1', |
73 |
code => $child1->itemtype, |
| 91 |
lang => 'en', |
74 |
lang => 'en', |
| 92 |
translation => 'b translated itemtype desc' |
75 |
translation => 'b translated itemtype desc' |
| 93 |
} |
76 |
} |
|
Lines 95-101
Koha::Localization->new(
Link Here
|
| 95 |
Koha::Localization->new( |
78 |
Koha::Localization->new( |
| 96 |
{ |
79 |
{ |
| 97 |
entity => 'itemtypes', |
80 |
entity => 'itemtypes', |
| 98 |
code => 'type2', |
81 |
code => $child2->itemtype, |
| 99 |
lang => 'en', |
82 |
lang => 'en', |
| 100 |
translation => 'a translated itemtype desc' |
83 |
translation => 'a translated itemtype desc' |
| 101 |
} |
84 |
} |
|
Lines 103-138
Koha::Localization->new(
Link Here
|
| 103 |
Koha::Localization->new( |
86 |
Koha::Localization->new( |
| 104 |
{ |
87 |
{ |
| 105 |
entity => 'something_else', |
88 |
entity => 'something_else', |
| 106 |
code => 'type2', |
89 |
code => $child2->itemtype, |
| 107 |
lang => 'en', |
90 |
lang => 'en', |
| 108 |
translation => 'another thing' |
91 |
translation => 'another thing' |
| 109 |
} |
92 |
} |
| 110 |
)->store; |
93 |
)->store; |
| 111 |
|
94 |
|
| 112 |
my $type = Koha::ItemTypes->find('type1'); |
95 |
my $type = Koha::ItemTypes->find($child1->itemtype); |
| 113 |
ok( defined($type), 'first result' ); |
96 |
ok( defined($type), 'first result' ); |
| 114 |
is( $type->itemtype, 'type1', 'itemtype/code' ); |
97 |
is_deeply( $type->unblessed, $child1->unblessed, "We got back the same object" ); |
| 115 |
is( $type->description, 'description', 'description' ); |
98 |
|
| 116 |
is( $type->rentalcharge, '0.000000', 'rentalcharge' ); |
99 |
$type = Koha::ItemTypes->find($child2->itemtype); |
| 117 |
is( $type->imageurl, 'imageurl', 'imageurl' ); |
|
|
| 118 |
is( $type->summary, 'summary', 'summary' ); |
| 119 |
is( $type->checkinmsg, 'checkinmsg', 'checkinmsg' ); |
| 120 |
is( $type->checkinmsgtype, 'checkinmsgtype', 'checkinmsgtype' ); |
| 121 |
|
| 122 |
$type = Koha::ItemTypes->find('type2'); |
| 123 |
ok( defined($type), 'second result' ); |
100 |
ok( defined($type), 'second result' ); |
| 124 |
is( $type->itemtype, 'type2', 'itemtype/code' ); |
101 |
is_deeply( $type->unblessed, $child2->unblessed, "We got back the same object" ); |
| 125 |
is( $type->description, 'description', 'description' ); |
|
|
| 126 |
is( $type->rentalcharge, '0.000000', 'rentalcharge' ); |
| 127 |
is( $type->imageurl, 'imageurl', 'imageurl' ); |
| 128 |
is( $type->summary, 'summary', 'summary' ); |
| 129 |
is( $type->checkinmsg, 'checkinmsg', 'checkinmsg' ); |
| 130 |
is( $type->checkinmsgtype, 'checkinmsgtype', 'checkinmsgtype' ); |
| 131 |
|
102 |
|
| 132 |
t::lib::Mocks::mock_preference('language', 'en'); |
103 |
t::lib::Mocks::mock_preference('language', 'en'); |
| 133 |
t::lib::Mocks::mock_preference('opaclanguages', 'en'); |
104 |
t::lib::Mocks::mock_preference('opaclanguages', 'en'); |
| 134 |
my $itemtypes = Koha::ItemTypes->search_with_localization; |
105 |
my $itemtypes = Koha::ItemTypes->search_with_localization; |
| 135 |
is( $itemtypes->count, 3, 'There are 3 item types' ); |
106 |
is( $itemtypes->count, $initial_count + 4, 'We added 4 item types' ); |
| 136 |
my $first_itemtype = $itemtypes->next; |
107 |
my $first_itemtype = $itemtypes->next; |
| 137 |
is( |
108 |
is( |
| 138 |
$first_itemtype->translated_description, |
109 |
$first_itemtype->translated_description, |
|
Lines 140-146
is(
Link Here
|
| 140 |
'item types should be sorted by translated description' |
111 |
'item types should be sorted by translated description' |
| 141 |
); |
112 |
); |
| 142 |
|
113 |
|
| 143 |
my $builder = t::lib::TestBuilder->new; |
114 |
my $children = $parent1->children_with_localization; |
|
|
115 |
my $first_child = $children->next; |
| 116 |
is( |
| 117 |
$first_child->translated_description, |
| 118 |
'a translated itemtype desc', |
| 119 |
'item types should be sorted by translated description' |
| 120 |
); |
| 121 |
|
| 144 |
my $item_type = $builder->build_object({ class => 'Koha::ItemTypes' }); |
122 |
my $item_type = $builder->build_object({ class => 'Koha::ItemTypes' }); |
| 145 |
|
123 |
|
| 146 |
is( $item_type->can_be_deleted, 1, 'An item type that is not used can be deleted'); |
124 |
is( $item_type->can_be_deleted, 1, 'An item type that is not used can be deleted'); |
| 147 |
- |
|
|