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

(-)a/Koha/AdditionalContents.pm (-17 / +17 lines)
Lines 83-89 sub search_for_display { Link Here
83
    $search_params->{category} = $params->{category} if $params->{category};
83
    $search_params->{category} = $params->{category} if $params->{category};
84
84
85
    my $contents = $self->SUPER::search( $search_params, { order_by => 'number' } );
85
    my $contents = $self->SUPER::search( $search_params, { order_by => 'number' } );
86
    my @all_content_id = $contents->get_column('id');
86
87
88
    my @translated_content_id;
87
    if ( $params->{lang} ) {
89
    if ( $params->{lang} ) {
88
        my $translated_contents = Koha::AdditionalContentsLocalizations->search(
90
        my $translated_contents = Koha::AdditionalContentsLocalizations->search(
89
            {
91
            {
Lines 91-114 sub search_for_display { Link Here
91
                lang => $params->{lang},
93
                lang => $params->{lang},
92
            }
94
            }
93
        );
95
        );
94
        my @all_content_id = $contents->get_column('id');
96
        @translated_content_id = $translated_contents->get_column('additional_content_id');
95
        my @translated_content_id = $translated_contents->get_column('additional_content_id');
96
        my $default_contents    = Koha::AdditionalContentsLocalizations->search(
97
            {
98
                additional_content_id => [array_minus(@all_content_id, @translated_content_id)],
99
                lang                  => 'default',
100
            }
101
        );
102
        return Koha::AdditionalContentsLocalizations->search(
103
            {
104
                id => [
105
                    $translated_contents->get_column('id'),
106
                    $default_contents->get_column('id'),
107
                ]
108
            },
109
        );
110
    }
97
    }
111
    return $contents->search( { lang => 'default' }, { order_by => 'number' } )->translated_contents;
98
99
    my $default_contents    = Koha::AdditionalContentsLocalizations->search(
100
        {
101
            additional_content_id => [array_minus(@all_content_id, @translated_content_id)],
102
            lang                  => 'default',
103
        }
104
    );
105
106
    return Koha::AdditionalContentsLocalizations->search(
107
        {
108
            id => [@translated_content_id, $default_contents->get_column('id')]
109
        },
110
    );
111
112
}
112
}
113
113
114
=head3 find_best_match
114
=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 79-86 my $hold = $builder->build_object( Link Here
79
79
80
my $news = $builder->build_object(
80
my $news = $builder->build_object(
81
    {
81
    {
82
        class => 'Koha::AdditionalContents',
82
        class => 'Koha::AdditionalContentsLocalizations',
83
        value => { title => 'a news title', content => 'a news content' }
83
        value => { title => 'a news title', content => 'a news content', lang => 'default' }
84
    }
84
    }
85
);
85
);
86
my $serial       = $builder->build_object( { class => 'Koha::Serials' } );
86
my $serial       = $builder->build_object( { class => 'Koha::Serials' } );
Lines 653-666 EOF Link Here
653
            {
653
            {
654
                class => 'Koha::AdditionalContents',
654
                class => 'Koha::AdditionalContents',
655
                value => {
655
                value => {
656
                    category        => 'news',
656
                    category       => 'news',
657
                    location        => "slip",
657
                    location       => "slip",
658
                    branchcode      => $branchcode,
658
                    branchcode     => $branchcode,
659
                    lang            => 'default',
659
                    expirationdate => undef,
660
                    title           => "A wonderful news",
660
                    published_on   => $one_minute_ago
661
                    content         => "This is the wonderful news.",
661
                }
662
                    expirationdate  => undef,
662
            }
663
                    published_on    => $one_minute_ago
663
        );
664
        my $content = $builder->build_object(
665
            {
666
                class => 'Koha::AdditionalContentsLocalizations',
667
                value => {
668
                    additional_content_id => $news_item->id,
669
                    lang                  => 'default',
670
                    title                 => "A wonderful news",
671
                    content               => "This is the wonderful news.",
664
                }
672
                }
665
            }
673
            }
666
        );
674
        );
Lines 693-707 Date due: <<issues.date_due | dateonly>><br /> Link Here
693
701
694
<hr>
702
<hr>
695
703
704
[% IF additional_contents.count %]
696
<h4 style="text-align: center; font-style:italic;">News</h4>
705
<h4 style="text-align: center; font-style:italic;">News</h4>
697
<news>
706
[% FOR content IN additional_contents %]
698
<div class="newsitem">
707
<div class="newsitem">
699
<h5 style="margin-bottom: 1px; margin-top: 1px"><b><<additional_contents.title>></b></h5>
708
<h5 style="margin-bottom: 1px; margin-top: 1px"><b>[% content.title %]</b></h5>
700
<p style="margin-bottom: 1px; margin-top: 1px"><<additional_contents.content>></p>
709
<p style="margin-bottom: 1px; margin-top: 1px">[% content.content %]</p>
701
<p class="newsfooter" style="font-size: 8pt; font-style:italic; margin-bottom: 1px; margin-top: 1px">Posted on <<additional_contents.published_on>></p>
710
<p class="newsfooter" style="font-size: 8pt; font-style:italic; margin-bottom: 1px; margin-top: 1px">Posted on [% content.published_on | \$KohaDates %]</p>
702
<hr />
711
<hr />
703
</div>
712
</div>
704
</news>
713
[% END %]
714
[% END %]
705
EOF
715
EOF
706
716
707
        reset_template( { template => $template, code => $code, module => 'circulation' } );
717
        reset_template( { template => $template, code => $code, module => 'circulation' } );
Lines 753-758 Date due: [% overdue.date_due | \$KohaDates %]<br /> Link Here
753
763
754
<hr>
764
<hr>
755
765
766
[% IF additional_contents.count %]
756
<h4 style="text-align: center; font-style:italic;">News</h4>
767
<h4 style="text-align: center; font-style:italic;">News</h4>
757
[% FOREACH n IN additional_contents %]
768
[% FOREACH n IN additional_contents %]
758
<div class="newsitem">
769
<div class="newsitem">
Lines 762-767 Date due: [% overdue.date_due | \$KohaDates %]<br /> Link Here
762
<hr />
773
<hr />
763
</div>
774
</div>
764
[% END %]
775
[% END %]
776
[% END %]
765
EOF
777
EOF
766
778
767
        reset_template( { template => $tt_template, code => $code, module => 'circulation' } );
779
        reset_template( { template => $tt_template, code => $code, module => 'circulation' } );
Lines 778-784 EOF Link Here
778
        # There is too many line breaks generated by the historic syntax
790
        # There is too many line breaks generated by the historic syntax
779
        $second_slip->{content} =~ s|</p>\n\n\n<p>|</p>\n\n<p>|s;
791
        $second_slip->{content} =~ s|</p>\n\n\n<p>|</p>\n\n<p>|s;
780
792
781
        my $news_item_title = $news_item->title;
793
        my $news_item_title = $content->title;
782
        like( $first_slip->{content}, qr{$news_item_title} );
794
        like( $first_slip->{content}, qr{$news_item_title} );
783
        is( $first_tt_slip->{content}, $first_slip->{content}, );
795
        is( $first_tt_slip->{content}, $first_slip->{content}, );
784
        is( $second_tt_slip->{content}, $second_slip->{content}, );
796
        is( $second_tt_slip->{content}, $second_slip->{content}, );
785
- 

Return to bug 31383