View | Details | Raw Unified | Return to bug 31383
Collapse All | Expand All

(-)a/Koha/AdditionalContents.pm (-17 / +17 lines)
Lines 85-91 sub search_for_display { Link Here
85
    $search_params->{category} = $params->{category} if $params->{category};
85
    $search_params->{category} = $params->{category} if $params->{category};
86
86
87
    my $contents = $self->SUPER::search( $search_params, { order_by => 'number' } );
87
    my $contents = $self->SUPER::search( $search_params, { order_by => 'number' } );
88
    my @all_content_id = $contents->get_column('id');
88
89
90
    my @translated_content_id;
89
    if ( $params->{lang} ) {
91
    if ( $params->{lang} ) {
90
        my $translated_contents = Koha::AdditionalContentsLocalizations->search(
92
        my $translated_contents = Koha::AdditionalContentsLocalizations->search(
91
            {
93
            {
Lines 93-116 sub search_for_display { Link Here
93
                lang => $params->{lang},
95
                lang => $params->{lang},
94
            }
96
            }
95
        );
97
        );
96
        my @all_content_id = $contents->get_column('id');
98
        @translated_content_id = $translated_contents->get_column('additional_content_id');
97
        my @translated_content_id = $translated_contents->get_column('additional_content_id');
98
        my $default_contents    = Koha::AdditionalContentsLocalizations->search(
99
            {
100
                additional_content_id => [array_minus(@all_content_id, @translated_content_id)],
101
                lang                  => 'default',
102
            }
103
        );
104
        return Koha::AdditionalContentsLocalizations->search(
105
            {
106
                id => [
107
                    $translated_contents->get_column('id'),
108
                    $default_contents->get_column('id'),
109
                ]
110
            },
111
        );
112
    }
99
    }
113
    return $contents->search( { lang => 'default' }, { order_by => 'number' } )->translated_contents;
100
101
    my $default_contents    = Koha::AdditionalContentsLocalizations->search(
102
        {
103
            additional_content_id => [array_minus(@all_content_id, @translated_content_id)],
104
            lang                  => 'default',
105
        }
106
    );
107
108
    return Koha::AdditionalContentsLocalizations->search(
109
        {
110
            id => [@translated_content_id, $default_contents->get_column('id')]
111
        },
112
    );
113
114
}
114
}
115
115
116
=head3 find_best_match
116
=head3 find_best_match
(-)a/t/db_dependent/Koha/AdditionalContents.t (-24 / +45 lines)
Lines 33-39 my $builder = t::lib::TestBuilder->new; Link Here
33
33
34
subtest 'Koha::AdditionalContents basic test' => sub {
34
subtest 'Koha::AdditionalContents basic test' => sub {
35
35
36
    plan tests => 5;
36
    plan tests => 9;
37
37
38
    $schema->storage->txn_begin;
38
    $schema->storage->txn_begin;
39
39
Lines 45-73 subtest 'Koha::AdditionalContents basic test' => sub { Link Here
45
            code       => 'news_1',
45
            code       => 'news_1',
46
            location   => 'staff_only',
46
            location   => 'staff_only',
47
            branchcode => $library->{branchcode},
47
            branchcode => $library->{branchcode},
48
            title      => 'a news',
49
            content    => 'content for news 1',
50
        }
48
        }
51
    )->store;
49
    )->store;
50
    my $content_1 = {
51
        title   => 'a news',
52
        content => 'content for news 1',
53
        lang    => 'default',
54
    };
55
    $new_news_item_1->translated_contents([$content_1]);
52
    my $new_news_item_2 = Koha::AdditionalContent->new(
56
    my $new_news_item_2 = Koha::AdditionalContent->new(
53
        {
57
        {
54
            category   => 'news',
58
            category   => 'news',
55
            code       => 'news_2',
59
            code       => 'news_2',
56
            location   => 'staff_only',
60
            location   => 'staff_only',
57
            branchcode => $library->{branchcode},
61
            branchcode => $library->{branchcode},
58
            title      => 'another news',
59
            content    => 'content for news 2',
60
        }
62
        }
61
    )->store;
63
    )->store;
62
64
    my $content_2 = {
63
    like( $new_news_item_1->idnew, qr|^\d+$|, 'Adding a new news_item should have set the idnew');
65
        title   => 'another news',
66
        content => 'content for news 2',
67
        lang    => 'default',
68
    };
69
    $new_news_item_2->translated_contents([$content_2]);
70
71
    like( $new_news_item_1->id, qr|^\d+$|, 'Adding a new news_item should have set the id');
64
    is( Koha::AdditionalContents->search->count, $nb_of_news + 2, 'The 2 news should have been added' );
72
    is( Koha::AdditionalContents->search->count, $nb_of_news + 2, 'The 2 news should have been added' );
65
73
66
    my $retrieved_news_item_1 = Koha::AdditionalContents->find( $new_news_item_1->idnew );
74
    my $retrieved_news_item_1 = Koha::AdditionalContents->find( $new_news_item_1->id )->translated_contents->next;
67
    is( $retrieved_news_item_1->title, $new_news_item_1->title, 'Find a news_item by id should return the correct news_item' );
75
    is( $retrieved_news_item_1->title, $content_1->{title}, 'Find a news_item by id should return the correct news_item' );
68
    is( $retrieved_news_item_1->content, $new_news_item_1->content, 'The content method return the content of the news');
76
    is( $retrieved_news_item_1->content, $content_1->{content}, 'The content method return the content of the news');
69
77
70
    $retrieved_news_item_1->delete;
78
    my $default_content = $new_news_item_2->default_localization;
79
    is( $default_content->content, $content_2->{content}, 'default_localization return the default content' );
80
    my $translated_content = { lang => 'nl-NL', content => 'translated_content' };
81
    $new_news_item_2->translated_contents( [ $translated_content, $content_2 ] )->as_list;
82
    $default_content = $new_news_item_2->default_localization;
83
    is( $default_content->content, $content_2->{content}, 'default_localization still return the default content' );
84
    my $retrieved_translated_content = $new_news_item_2->translated_content('en');
85
    is( $retrieved_translated_content->content, $content_2->{content}, 'default content is returned for non-existing translated interface' );
86
    $retrieved_translated_content = $new_news_item_2->translated_content('nl-NL');
87
    is( $retrieved_translated_content->content, $translated_content->{content}, 'translated content is returned if it existsOB' );
88
89
    $new_news_item_1->delete;
71
    is( Koha::AdditionalContents->search->count, $nb_of_news + 1, 'Delete should have deleted the news_item' );
90
    is( Koha::AdditionalContents->search->count, $nb_of_news + 1, 'Delete should have deleted the news_item' );
72
91
73
    $schema->storage->txn_rollback;
92
    $schema->storage->txn_rollback;
Lines 148-154 subtest '->author' => sub { Link Here
148
167
149
    $author->delete;
168
    $author->delete;
150
169
151
    $news_item = Koha::AdditionalContents->find($news_item->idnew);
170
    $news_item = Koha::AdditionalContents->find($news_item->id);
152
    is( ref($news_item), 'Koha::AdditionalContent', 'News are not deleted alongwith the author' );
171
    is( ref($news_item), 'Koha::AdditionalContent', 'News are not deleted alongwith the author' );
153
    is( $news_item->author, undef, '->author returns undef is the author has been deleted' );
172
    is( $news_item->author, undef, '->author returns undef is the author has been deleted' );
154
173
Lines 176-186 subtest '->search_for_display' => sub { Link Here
176
            published_on => $today,
195
            published_on => $today,
177
            category => 'news',
196
            category => 'news',
178
            location => 'staff_and_opac',
197
            location => 'staff_and_opac',
179
            lang => 'default',
180
            branchcode => undef,
198
            branchcode => undef,
181
            number => 1,
199
            number => 1,
182
        }
200
        }
183
    });
201
    });
202
    $new_expired->translated_contents( [ { lang => 'default', content => ''} ] );
184
    my $new_not_expired = $builder->build_object({
203
    my $new_not_expired = $builder->build_object({
185
        class => 'Koha::AdditionalContents',
204
        class => 'Koha::AdditionalContents',
186
        value => {
205
        value => {
Lines 188-198 subtest '->search_for_display' => sub { Link Here
188
            published_on => $today,
207
            published_on => $today,
189
            category => 'news',
208
            category => 'news',
190
            location => 'staff_and_opac',
209
            location => 'staff_and_opac',
191
            lang => 'default',
192
            branchcode => undef,
210
            branchcode => undef,
193
            number => 2,
211
            number => 2,
194
        }
212
        }
195
    });
213
    });
214
    $new_not_expired->translated_contents( [ { lang => 'default', content => '' } ] );
196
    my $new_not_active = $builder->build_object({
215
    my $new_not_active = $builder->build_object({
197
        class => 'Koha::AdditionalContents',
216
        class => 'Koha::AdditionalContents',
198
        value => {
217
        value => {
Lines 200-210 subtest '->search_for_display' => sub { Link Here
200
            published_on => $tomorrow,
219
            published_on => $tomorrow,
201
            category => 'news',
220
            category => 'news',
202
            location => 'staff_and_opac',
221
            location => 'staff_and_opac',
203
            lang => 'default',
204
            branchcode => undef,
222
            branchcode => undef,
205
            number => 3,
223
            number => 3,
206
        }
224
        }
207
    });
225
    });
226
    $new_not_active->translated_contents( [ { lang => 'default', content => '' } ] );
208
    my $new_slip= $builder->build_object({
227
    my $new_slip= $builder->build_object({
209
        class => 'Koha::AdditionalContents',
228
        class => 'Koha::AdditionalContents',
210
        value => {
229
        value => {
Lines 212-222 subtest '->search_for_display' => sub { Link Here
212
            published_on => $today,
231
            published_on => $today,
213
            category => 'news',
232
            category => 'news',
214
            location => 'staff_only',
233
            location => 'staff_only',
215
            lang => 'default',
216
            branchcode => $library1->branchcode,
234
            branchcode => $library1->branchcode,
217
            number => 4,
235
            number => 4,
218
        }
236
        }
219
    });
237
    });
238
    $new_slip->translated_contents( [ { lang => 'default', content => '' } ] );
220
    my $new_intra = $builder->build_object({
239
    my $new_intra = $builder->build_object({
221
        class => 'Koha::AdditionalContents',
240
        class => 'Koha::AdditionalContents',
222
        value => {
241
        value => {
Lines 224-234 subtest '->search_for_display' => sub { Link Here
224
            published_on => $today,
243
            published_on => $today,
225
            category => 'news',
244
            category => 'news',
226
            location => 'staff_only',
245
            location => 'staff_only',
227
            lang => 'default',
228
            branchcode => $library2->branchcode,
246
            branchcode => $library2->branchcode,
229
            number => 5,
247
            number => 5,
230
        }
248
        }
231
    });
249
    });
250
    $new_intra->translated_contents( [ { lang => 'default', content => '' } ] );
232
    my $new_intra2 = $builder->build_object({
251
    my $new_intra2 = $builder->build_object({
233
        class => 'Koha::AdditionalContents',
252
        class => 'Koha::AdditionalContents',
234
        value => {
253
        value => {
Lines 236-246 subtest '->search_for_display' => sub { Link Here
236
            published_on => $today,
255
            published_on => $today,
237
            category => 'news',
256
            category => 'news',
238
            location => 'staff_only',
257
            location => 'staff_only',
239
            lang => 'default',
240
            branchcode => undef,
258
            branchcode => undef,
241
            number => 5,
259
            number => 5,
242
        }
260
        }
243
    });
261
    });
262
    $new_intra2->translated_contents( [ { lang => 'default', content => '' } ] );
244
263
245
    my $news = Koha::AdditionalContents->search_for_display({ location => 'staff_only' });
264
    my $news = Koha::AdditionalContents->search_for_display({ location => 'staff_only' });
246
    is($news->count, 1, "There is 1 news for all staff");
265
    is($news->count, 1, "There is 1 news for all staff");
Lines 267-286 subtest 'find_best_match' => sub { Link Here
267
    my $library01 = $builder->build_object({ class => 'Koha::Libraries' });
286
    my $library01 = $builder->build_object({ class => 'Koha::Libraries' });
268
    my $html01 = $builder->build_object({
287
    my $html01 = $builder->build_object({
269
        class => 'Koha::AdditionalContents',
288
        class => 'Koha::AdditionalContents',
270
        value => { category => 'html_customizations', location => 'test_best_match', branchcode => undef, lang => 'default' },
289
        value => { category => 'html_customizations', location => 'test_best_match', branchcode => undef },
271
    });
290
    });
291
    my ( $default_content ) = $html01->translated_contents( [ { lang => 'default', content => '' } ] )->as_list;
272
    my $params = { category => 'html_customizations', location => 'test_best_match', lang => 'nl-NL' };
292
    my $params = { category => 'html_customizations', location => 'test_best_match', lang => 'nl-NL' };
273
    is( Koha::AdditionalContents->find_best_match($params)->idnew, $html01->idnew, 'Found all branches, lang default' );
293
    is( Koha::AdditionalContents->find_best_match($params)->id, $default_content->id, 'Found all branches, lang default' );
274
294
275
    my $html02 = $builder->build_object({
295
    my $html02 = $builder->build_object({
276
        class => 'Koha::AdditionalContents',
296
        class => 'Koha::AdditionalContents',
277
        value => { category => 'html_customizations', location => 'test_best_match', branchcode => undef, lang => 'nl-NL' },
297
        value => { category => 'html_customizations', location => 'test_best_match', branchcode => undef },
278
    });
298
    });
279
    is( Koha::AdditionalContents->find_best_match($params)->idnew, $html02->idnew, 'Found all branches, lang nl-NL' );
299
    my ( $translated_content ) = $html02->translated_contents( [ { lang => 'nl-NL', content => '' } ] )->as_list;
300
    is( Koha::AdditionalContents->find_best_match($params)->id, $translated_content->id, 'Found all branches, lang nl-NL' );
280
301
281
    $params->{ library_id } = $library01->id;
302
    $params->{ library_id } = $library01->id;
282
    $html02->branchcode( $library01->id )->store;
303
    $html02->branchcode( $library01->id )->store;
283
    is( Koha::AdditionalContents->find_best_match($params)->idnew, $html02->idnew, 'Found library01, lang nl-NL' );
304
    is( Koha::AdditionalContents->find_best_match($params)->id, $translated_content->id, 'Found library01, lang nl-NL' );
284
305
285
    # Note: find_best_match is tested further via $libary->opac_info; see t/db_dependent/Koha/Library.t
306
    # Note: find_best_match is tested further via $libary->opac_info; see t/db_dependent/Koha/Library.t
286
307
(-)a/t/db_dependent/Koha/Library.t (-16 / +46 lines)
Lines 101-122 subtest 'opac_info tests' => sub { Link Here
101
    my $library01 = $builder->build_object({ class => 'Koha::Libraries' });
101
    my $library01 = $builder->build_object({ class => 'Koha::Libraries' });
102
    my $library02 = $builder->build_object({ class => 'Koha::Libraries' });
102
    my $library02 = $builder->build_object({ class => 'Koha::Libraries' });
103
103
104
    my $html01 = $builder->build_object({
104
    my $html01 = $builder->build_object(
105
        class => 'Koha::AdditionalContents',
105
        {
106
        value => { category => 'html_customizations', location => 'OpacLibraryInfo', branchcode => undef, lang => 'default', content => '1', expirationdate => undef },
106
            class => 'Koha::AdditionalContents',
107
    });
107
            value => { category => 'html_customizations', location => 'OpacLibraryInfo', branchcode => undef, expirationdate => undef },
108
    my $html02 = $builder->build_object({
108
        }
109
        class => 'Koha::AdditionalContents',
109
    );
110
        value => { category => 'html_customizations', location => 'OpacLibraryInfo', branchcode => $library01->id, lang => 'default', content => '2', expirationdate => undef },
110
    $html01->translated_contents(
111
    });
111
        [
112
    my $html03 = $builder->build_object({
112
            {
113
        class => 'Koha::AdditionalContents',
113
                lang    => 'default',
114
        value => { category => 'html_customizations', location => 'OpacLibraryInfo', branchcode => $library01->id, lang => 'nl-NL', content => '3', expirationdate => undef },
114
                content => '1',
115
    });
115
            }
116
    my $html04 = $builder->build_object({
116
        ]
117
        class => 'Koha::AdditionalContents',
117
    );
118
        value => { category => 'html_customizations', location => 'OpacLibraryInfo', branchcode => undef, lang => 'fr-FR', content => '4', expirationdate => undef },
118
    my $html02 = $builder->build_object(
119
    });
119
        {
120
            class => 'Koha::AdditionalContents',
121
            value => { category => 'html_customizations', location => 'OpacLibraryInfo', branchcode => $library01->id, expirationdate => undef },
122
        }
123
    );
124
    $html02->translated_contents(
125
        [
126
            {
127
                lang    => 'default',
128
                content => '2',
129
            },
130
            {
131
                lang    => 'nl-NL',
132
                content => '3',
133
            }
134
        ]
135
    );
136
    my $html04 = $builder->build_object(
137
        {
138
            class => 'Koha::AdditionalContents',
139
            value => { category => 'html_customizations', location => 'OpacLibraryInfo', branchcode => undef, expirationdate => undef },
140
        }
141
    );
142
    $html04->translated_contents(
143
        [
144
            {
145
                lang    => 'fr-FR',
146
                content => '4',
147
            }
148
        ]
149
    );
120
150
121
    # Start testing
151
    # Start testing
122
    is( $library01->opac_info->content, '2', 'specific library, default language' );
152
    is( $library01->opac_info->content, '2', 'specific library, default language' );
(-)a/t/db_dependent/Letters/TemplateToolkit.t (-17 / +28 lines)
Lines 80-87 my $hold = $builder->build_object( Link Here
80
80
81
my $news = $builder->build_object(
81
my $news = $builder->build_object(
82
    {
82
    {
83
        class => 'Koha::AdditionalContents',
83
        class => 'Koha::AdditionalContentsLocalizations',
84
        value => { title => 'a news title', content => 'a news content' }
84
        value => { title => 'a news title', content => 'a news content', lang => 'default' }
85
    }
85
    }
86
);
86
);
87
my $serial       = $builder->build_object( { class => 'Koha::Serials' } );
87
my $serial       = $builder->build_object( { class => 'Koha::Serials' } );
Lines 662-675 EOF Link Here
662
            {
662
            {
663
                class => 'Koha::AdditionalContents',
663
                class => 'Koha::AdditionalContents',
664
                value => {
664
                value => {
665
                    category        => 'news',
665
                    category       => 'news',
666
                    location        => "slip",
666
                    location       => "slip",
667
                    branchcode      => $branchcode,
667
                    branchcode     => $branchcode,
668
                    lang            => 'default',
668
                    expirationdate => undef,
669
                    title           => "A wonderful news",
669
                    published_on   => $one_minute_ago
670
                    content         => "This is the wonderful news.",
670
                }
671
                    expirationdate  => undef,
671
            }
672
                    published_on    => $one_minute_ago
672
        );
673
        my $content = $builder->build_object(
674
            {
675
                class => 'Koha::AdditionalContentsLocalizations',
676
                value => {
677
                    additional_content_id => $news_item->id,
678
                    lang                  => 'default',
679
                    title                 => "A wonderful news",
680
                    content               => "This is the wonderful news.",
673
                }
681
                }
674
            }
682
            }
675
        );
683
        );
Lines 702-716 Date due: <<issues.date_due | dateonly>><br /> Link Here
702
710
703
<hr>
711
<hr>
704
712
713
[% IF additional_contents.count %]
705
<h4 style="text-align: center; font-style:italic;">News</h4>
714
<h4 style="text-align: center; font-style:italic;">News</h4>
706
<news>
715
[% FOR content IN additional_contents %]
707
<div class="newsitem">
716
<div class="newsitem">
708
<h5 style="margin-bottom: 1px; margin-top: 1px"><b><<additional_contents.title>></b></h5>
717
<h5 style="margin-bottom: 1px; margin-top: 1px"><b>[% content.title %]</b></h5>
709
<p style="margin-bottom: 1px; margin-top: 1px"><<additional_contents.content>></p>
718
<p style="margin-bottom: 1px; margin-top: 1px">[% content.content %]</p>
710
<p class="newsfooter" style="font-size: 8pt; font-style:italic; margin-bottom: 1px; margin-top: 1px">Posted on <<additional_contents.published_on>></p>
719
<p class="newsfooter" style="font-size: 8pt; font-style:italic; margin-bottom: 1px; margin-top: 1px">Posted on [% content.published_on | \$KohaDates %]</p>
711
<hr />
720
<hr />
712
</div>
721
</div>
713
</news>
722
[% END %]
723
[% END %]
714
EOF
724
EOF
715
725
716
        reset_template( { template => $template, code => $code, module => 'circulation' } );
726
        reset_template( { template => $template, code => $code, module => 'circulation' } );
Lines 762-767 Date due: [% overdue.date_due | \$KohaDates %]<br /> Link Here
762
772
763
<hr>
773
<hr>
764
774
775
[% IF additional_contents.count %]
765
<h4 style="text-align: center; font-style:italic;">News</h4>
776
<h4 style="text-align: center; font-style:italic;">News</h4>
766
[% FOREACH n IN additional_contents %]
777
[% FOREACH n IN additional_contents %]
767
<div class="newsitem">
778
<div class="newsitem">
Lines 771-776 Date due: [% overdue.date_due | \$KohaDates %]<br /> Link Here
771
<hr />
782
<hr />
772
</div>
783
</div>
773
[% END %]
784
[% END %]
785
[% END %]
774
EOF
786
EOF
775
787
776
        reset_template( { template => $tt_template, code => $code, module => 'circulation' } );
788
        reset_template( { template => $tt_template, code => $code, module => 'circulation' } );
Lines 787-793 EOF Link Here
787
        # There is too many line breaks generated by the historic syntax
799
        # There is too many line breaks generated by the historic syntax
788
        $second_slip->{content} =~ s|</p>\n\n\n<p>|</p>\n\n<p>|s;
800
        $second_slip->{content} =~ s|</p>\n\n\n<p>|</p>\n\n<p>|s;
789
801
790
        my $news_item_title = $news_item->title;
802
        my $news_item_title = $content->title;
791
        like( $first_slip->{content}, qr{$news_item_title} );
803
        like( $first_slip->{content}, qr{$news_item_title} );
792
        is( $first_tt_slip->{content}, $first_slip->{content}, );
804
        is( $first_tt_slip->{content}, $first_slip->{content}, );
793
        is( $second_tt_slip->{content}, $second_slip->{content}, );
805
        is( $second_tt_slip->{content}, $second_slip->{content}, );
794
- 

Return to bug 31383