Bugzilla – Attachment 156266 Details for
Bug 31383
Additional contents: We need a parent and child table
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 31383: Adjust and add tests
Bug-31383-Adjust-and-add-tests.patch (text/plain), 18.45 KB, created by
Martin Renvoize (ashimema)
on 2023-09-27 10:01:21 UTC
(
hide
)
Description:
Bug 31383: Adjust and add tests
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2023-09-27 10:01:21 UTC
Size:
18.45 KB
patch
obsolete
>From 454b2fe091f3dfcb64317e70184b4fdd77250582 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Fri, 3 Mar 2023 12:13:05 +0100 >Subject: [PATCH] Bug 31383: Adjust and add tests > >Sponsored-by: Rijksmuseum, Netherlands >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > Koha/AdditionalContents.pm | 34 ++++++------ > t/db_dependent/Koha/AdditionalContents.t | 69 +++++++++++++++--------- > t/db_dependent/Koha/Library.t | 62 +++++++++++++++------ > t/db_dependent/Letters/TemplateToolkit.t | 44 +++++++++------ > 4 files changed, 136 insertions(+), 73 deletions(-) > >diff --git a/Koha/AdditionalContents.pm b/Koha/AdditionalContents.pm >index cd3b00b8968..a866aa71d0d 100644 >--- a/Koha/AdditionalContents.pm >+++ b/Koha/AdditionalContents.pm >@@ -85,7 +85,9 @@ sub search_for_display { > $search_params->{category} = $params->{category} if $params->{category}; > > my $contents = $self->SUPER::search( $search_params, { order_by => 'number' } ); >+ my @all_content_id = $contents->get_column('id'); > >+ my @translated_content_id; > if ( $params->{lang} ) { > my $translated_contents = Koha::AdditionalContentsLocalizations->search( > { >@@ -93,24 +95,22 @@ sub search_for_display { > lang => $params->{lang}, > } > ); >- my @all_content_id = $contents->get_column('id'); >- my @translated_content_id = $translated_contents->get_column('additional_content_id'); >- my $default_contents = Koha::AdditionalContentsLocalizations->search( >- { >- additional_content_id => [array_minus(@all_content_id, @translated_content_id)], >- lang => 'default', >- } >- ); >- return Koha::AdditionalContentsLocalizations->search( >- { >- id => [ >- $translated_contents->get_column('id'), >- $default_contents->get_column('id'), >- ] >- }, >- ); >+ @translated_content_id = $translated_contents->get_column('additional_content_id'); > } >- return $contents->search( { lang => 'default' }, { order_by => 'number' } )->translated_contents; >+ >+ my $default_contents = Koha::AdditionalContentsLocalizations->search( >+ { >+ additional_content_id => [array_minus(@all_content_id, @translated_content_id)], >+ lang => 'default', >+ } >+ ); >+ >+ return Koha::AdditionalContentsLocalizations->search( >+ { >+ id => [@translated_content_id, $default_contents->get_column('id')] >+ }, >+ ); >+ > } > > =head3 find_best_match >diff --git a/t/db_dependent/Koha/AdditionalContents.t b/t/db_dependent/Koha/AdditionalContents.t >index 67094cd48b4..f3a05c67ad9 100755 >--- a/t/db_dependent/Koha/AdditionalContents.t >+++ b/t/db_dependent/Koha/AdditionalContents.t >@@ -33,7 +33,7 @@ my $builder = t::lib::TestBuilder->new; > > subtest 'Koha::AdditionalContents basic test' => sub { > >- plan tests => 5; >+ plan tests => 9; > > $schema->storage->txn_begin; > >@@ -45,29 +45,48 @@ subtest 'Koha::AdditionalContents basic test' => sub { > code => 'news_1', > location => 'staff_only', > branchcode => $library->{branchcode}, >- title => 'a news', >- content => 'content for news 1', > } > )->store; >+ my $content_1 = { >+ title => 'a news', >+ content => 'content for news 1', >+ lang => 'default', >+ }; >+ $new_news_item_1->translated_contents([$content_1]); > my $new_news_item_2 = Koha::AdditionalContent->new( > { > category => 'news', > code => 'news_2', > location => 'staff_only', > branchcode => $library->{branchcode}, >- title => 'another news', >- content => 'content for news 2', > } > )->store; >- >- like( $new_news_item_1->idnew, qr|^\d+$|, 'Adding a new news_item should have set the idnew'); >+ my $content_2 = { >+ title => 'another news', >+ content => 'content for news 2', >+ lang => 'default', >+ }; >+ $new_news_item_2->translated_contents([$content_2]); >+ >+ like( $new_news_item_1->id, qr|^\d+$|, 'Adding a new news_item should have set the id'); > is( Koha::AdditionalContents->search->count, $nb_of_news + 2, 'The 2 news should have been added' ); > >- my $retrieved_news_item_1 = Koha::AdditionalContents->find( $new_news_item_1->idnew ); >- is( $retrieved_news_item_1->title, $new_news_item_1->title, 'Find a news_item by id should return the correct news_item' ); >- is( $retrieved_news_item_1->content, $new_news_item_1->content, 'The content method return the content of the news'); >- >- $retrieved_news_item_1->delete; >+ my $retrieved_news_item_1 = Koha::AdditionalContents->find( $new_news_item_1->id )->translated_contents->next; >+ is( $retrieved_news_item_1->title, $content_1->{title}, 'Find a news_item by id should return the correct news_item' ); >+ is( $retrieved_news_item_1->content, $content_1->{content}, 'The content method return the content of the news'); >+ >+ my $default_content = $new_news_item_2->default_localization; >+ is( $default_content->content, $content_2->{content}, 'default_localization return the default content' ); >+ my $translated_content = { lang => 'nl-NL', content => 'translated_content' }; >+ $new_news_item_2->translated_contents( [ $translated_content, $content_2 ] )->as_list; >+ $default_content = $new_news_item_2->default_localization; >+ is( $default_content->content, $content_2->{content}, 'default_localization still return the default content' ); >+ my $retrieved_translated_content = $new_news_item_2->translated_content('en'); >+ is( $retrieved_translated_content->content, $content_2->{content}, 'default content is returned for non-existing translated interface' ); >+ $retrieved_translated_content = $new_news_item_2->translated_content('nl-NL'); >+ is( $retrieved_translated_content->content, $translated_content->{content}, 'translated content is returned if it existsîOB' ); >+ >+ $new_news_item_1->delete; > is( Koha::AdditionalContents->search->count, $nb_of_news + 1, 'Delete should have deleted the news_item' ); > > $schema->storage->txn_rollback; >@@ -148,7 +167,7 @@ subtest '->author' => sub { > > $author->delete; > >- $news_item = Koha::AdditionalContents->find($news_item->idnew); >+ $news_item = Koha::AdditionalContents->find($news_item->id); > is( ref($news_item), 'Koha::AdditionalContent', 'News are not deleted alongwith the author' ); > is( $news_item->author, undef, '->author returns undef is the author has been deleted' ); > >@@ -176,11 +195,11 @@ subtest '->search_for_display' => sub { > published_on => $today, > category => 'news', > location => 'staff_and_opac', >- lang => 'default', > branchcode => undef, > number => 1, > } > }); >+ $new_expired->translated_contents( [ { lang => 'default', content => ''} ] ); > my $new_not_expired = $builder->build_object({ > class => 'Koha::AdditionalContents', > value => { >@@ -188,11 +207,11 @@ subtest '->search_for_display' => sub { > published_on => $today, > category => 'news', > location => 'staff_and_opac', >- lang => 'default', > branchcode => undef, > number => 2, > } > }); >+ $new_not_expired->translated_contents( [ { lang => 'default', content => '' } ] ); > my $new_not_active = $builder->build_object({ > class => 'Koha::AdditionalContents', > value => { >@@ -200,11 +219,11 @@ subtest '->search_for_display' => sub { > published_on => $tomorrow, > category => 'news', > location => 'staff_and_opac', >- lang => 'default', > branchcode => undef, > number => 3, > } > }); >+ $new_not_active->translated_contents( [ { lang => 'default', content => '' } ] ); > my $new_slip= $builder->build_object({ > class => 'Koha::AdditionalContents', > value => { >@@ -212,11 +231,11 @@ subtest '->search_for_display' => sub { > published_on => $today, > category => 'news', > location => 'staff_only', >- lang => 'default', > branchcode => $library1->branchcode, > number => 4, > } > }); >+ $new_slip->translated_contents( [ { lang => 'default', content => '' } ] ); > my $new_intra = $builder->build_object({ > class => 'Koha::AdditionalContents', > value => { >@@ -224,11 +243,11 @@ subtest '->search_for_display' => sub { > published_on => $today, > category => 'news', > location => 'staff_only', >- lang => 'default', > branchcode => $library2->branchcode, > number => 5, > } > }); >+ $new_intra->translated_contents( [ { lang => 'default', content => '' } ] ); > my $new_intra2 = $builder->build_object({ > class => 'Koha::AdditionalContents', > value => { >@@ -236,11 +255,11 @@ subtest '->search_for_display' => sub { > published_on => $today, > category => 'news', > location => 'staff_only', >- lang => 'default', > branchcode => undef, > number => 5, > } > }); >+ $new_intra2->translated_contents( [ { lang => 'default', content => '' } ] ); > > my $news = Koha::AdditionalContents->search_for_display({ location => 'staff_only' }); > is($news->count, 1, "There is 1 news for all staff"); >@@ -267,20 +286,22 @@ subtest 'find_best_match' => sub { > my $library01 = $builder->build_object({ class => 'Koha::Libraries' }); > my $html01 = $builder->build_object({ > class => 'Koha::AdditionalContents', >- value => { category => 'html_customizations', location => 'test_best_match', branchcode => undef, lang => 'default' }, >+ value => { category => 'html_customizations', location => 'test_best_match', branchcode => undef }, > }); >+ my ( $default_content ) = $html01->translated_contents( [ { lang => 'default', content => '' } ] )->as_list; > my $params = { category => 'html_customizations', location => 'test_best_match', lang => 'nl-NL' }; >- is( Koha::AdditionalContents->find_best_match($params)->idnew, $html01->idnew, 'Found all branches, lang default' ); >+ is( Koha::AdditionalContents->find_best_match($params)->id, $default_content->id, 'Found all branches, lang default' ); > > my $html02 = $builder->build_object({ > class => 'Koha::AdditionalContents', >- value => { category => 'html_customizations', location => 'test_best_match', branchcode => undef, lang => 'nl-NL' }, >+ value => { category => 'html_customizations', location => 'test_best_match', branchcode => undef }, > }); >- is( Koha::AdditionalContents->find_best_match($params)->idnew, $html02->idnew, 'Found all branches, lang nl-NL' ); >+ my ( $translated_content ) = $html02->translated_contents( [ { lang => 'nl-NL', content => '' } ] )->as_list; >+ is( Koha::AdditionalContents->find_best_match($params)->id, $translated_content->id, 'Found all branches, lang nl-NL' ); > > $params->{ library_id } = $library01->id; > $html02->branchcode( $library01->id )->store; >- is( Koha::AdditionalContents->find_best_match($params)->idnew, $html02->idnew, 'Found library01, lang nl-NL' ); >+ is( Koha::AdditionalContents->find_best_match($params)->id, $translated_content->id, 'Found library01, lang nl-NL' ); > > # Note: find_best_match is tested further via $libary->opac_info; see t/db_dependent/Koha/Library.t > >diff --git a/t/db_dependent/Koha/Library.t b/t/db_dependent/Koha/Library.t >index c6637ddfd92..5c16eedb543 100755 >--- a/t/db_dependent/Koha/Library.t >+++ b/t/db_dependent/Koha/Library.t >@@ -101,22 +101,52 @@ subtest 'opac_info tests' => sub { > my $library01 = $builder->build_object({ class => 'Koha::Libraries' }); > my $library02 = $builder->build_object({ class => 'Koha::Libraries' }); > >- my $html01 = $builder->build_object({ >- class => 'Koha::AdditionalContents', >- value => { category => 'html_customizations', location => 'OpacLibraryInfo', branchcode => undef, lang => 'default', content => '1', expirationdate => undef }, >- }); >- my $html02 = $builder->build_object({ >- class => 'Koha::AdditionalContents', >- value => { category => 'html_customizations', location => 'OpacLibraryInfo', branchcode => $library01->id, lang => 'default', content => '2', expirationdate => undef }, >- }); >- my $html03 = $builder->build_object({ >- class => 'Koha::AdditionalContents', >- value => { category => 'html_customizations', location => 'OpacLibraryInfo', branchcode => $library01->id, lang => 'nl-NL', content => '3', expirationdate => undef }, >- }); >- my $html04 = $builder->build_object({ >- class => 'Koha::AdditionalContents', >- value => { category => 'html_customizations', location => 'OpacLibraryInfo', branchcode => undef, lang => 'fr-FR', content => '4', expirationdate => undef }, >- }); >+ my $html01 = $builder->build_object( >+ { >+ class => 'Koha::AdditionalContents', >+ value => { category => 'html_customizations', location => 'OpacLibraryInfo', branchcode => undef, expirationdate => undef }, >+ } >+ ); >+ $html01->translated_contents( >+ [ >+ { >+ lang => 'default', >+ content => '1', >+ } >+ ] >+ ); >+ my $html02 = $builder->build_object( >+ { >+ class => 'Koha::AdditionalContents', >+ value => { category => 'html_customizations', location => 'OpacLibraryInfo', branchcode => $library01->id, expirationdate => undef }, >+ } >+ ); >+ $html02->translated_contents( >+ [ >+ { >+ lang => 'default', >+ content => '2', >+ }, >+ { >+ lang => 'nl-NL', >+ content => '3', >+ } >+ ] >+ ); >+ my $html04 = $builder->build_object( >+ { >+ class => 'Koha::AdditionalContents', >+ value => { category => 'html_customizations', location => 'OpacLibraryInfo', branchcode => undef, expirationdate => undef }, >+ } >+ ); >+ $html04->translated_contents( >+ [ >+ { >+ lang => 'fr-FR', >+ content => '4', >+ } >+ ] >+ ); > > # Start testing > is( $library01->opac_info->content, '2', 'specific library, default language' ); >diff --git a/t/db_dependent/Letters/TemplateToolkit.t b/t/db_dependent/Letters/TemplateToolkit.t >index 7c38aef3d22..1c6fea8ee0a 100755 >--- a/t/db_dependent/Letters/TemplateToolkit.t >+++ b/t/db_dependent/Letters/TemplateToolkit.t >@@ -80,8 +80,8 @@ my $hold = $builder->build_object( > > my $news = $builder->build_object( > { >- class => 'Koha::AdditionalContents', >- value => { title => 'a news title', content => 'a news content' } >+ class => 'Koha::AdditionalContentsLocalizations', >+ value => { title => 'a news title', content => 'a news content', lang => 'default' } > } > ); > my $serial = $builder->build_object( { class => 'Koha::Serials' } ); >@@ -662,14 +662,22 @@ EOF > { > class => 'Koha::AdditionalContents', > value => { >- category => 'news', >- location => "slip", >- branchcode => $branchcode, >- lang => 'default', >- title => "A wonderful news", >- content => "This is the wonderful news.", >- expirationdate => undef, >- published_on => $one_minute_ago >+ category => 'news', >+ location => "slip", >+ branchcode => $branchcode, >+ expirationdate => undef, >+ published_on => $one_minute_ago >+ } >+ } >+ ); >+ my $content = $builder->build_object( >+ { >+ class => 'Koha::AdditionalContentsLocalizations', >+ value => { >+ additional_content_id => $news_item->id, >+ lang => 'default', >+ title => "A wonderful news", >+ content => "This is the wonderful news.", > } > } > ); >@@ -702,15 +710,17 @@ Date due: <<issues.date_due | dateonly>><br /> > > <hr> > >+[% IF additional_contents.count %] > <h4 style="text-align: center; font-style:italic;">News</h4> >-<news> >+[% FOR content IN additional_contents %] > <div class="newsitem"> >-<h5 style="margin-bottom: 1px; margin-top: 1px"><b><<additional_contents.title>></b></h5> >-<p style="margin-bottom: 1px; margin-top: 1px"><<additional_contents.content>></p> >-<p class="newsfooter" style="font-size: 8pt; font-style:italic; margin-bottom: 1px; margin-top: 1px">Posted on <<additional_contents.published_on>></p> >+<h5 style="margin-bottom: 1px; margin-top: 1px"><b>[% content.title %]</b></h5> >+<p style="margin-bottom: 1px; margin-top: 1px">[% content.content %]</p> >+<p class="newsfooter" style="font-size: 8pt; font-style:italic; margin-bottom: 1px; margin-top: 1px">Posted on [% content.published_on | \$KohaDates %]</p> > <hr /> > </div> >-</news> >+[% END %] >+[% END %] > EOF > > reset_template( { template => $template, code => $code, module => 'circulation' } ); >@@ -762,6 +772,7 @@ Date due: [% overdue.date_due | \$KohaDates %]<br /> > > <hr> > >+[% IF additional_contents.count %] > <h4 style="text-align: center; font-style:italic;">News</h4> > [% FOREACH n IN additional_contents %] > <div class="newsitem"> >@@ -771,6 +782,7 @@ Date due: [% overdue.date_due | \$KohaDates %]<br /> > <hr /> > </div> > [% END %] >+[% END %] > EOF > > reset_template( { template => $tt_template, code => $code, module => 'circulation' } ); >@@ -787,7 +799,7 @@ EOF > # There is too many line breaks generated by the historic syntax > $second_slip->{content} =~ s|</p>\n\n\n<p>|</p>\n\n<p>|s; > >- my $news_item_title = $news_item->title; >+ my $news_item_title = $content->title; > like( $first_slip->{content}, qr{$news_item_title} ); > is( $first_tt_slip->{content}, $first_slip->{content}, ); > is( $second_tt_slip->{content}, $second_slip->{content}, ); >-- >2.41.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 31383
:
147891
|
147892
|
147893
|
147894
|
147895
|
147896
|
149813
|
149814
|
149815
|
149816
|
149817
|
149818
|
152423
|
152424
|
152425
|
152426
|
152427
|
152428
|
152545
|
152546
|
152547
|
152566
|
152660
|
152661
|
152662
|
152663
|
152664
|
152665
|
152666
|
152667
|
152668
|
152669
|
153013
|
153666
|
153667
|
153668
|
153669
|
153670
|
153671
|
153672
|
153673
|
153674
|
153675
|
153676
|
156048
|
156049
|
156050
|
156051
|
156052
|
156053
|
156054
|
156055
|
156056
|
156057
|
156058
|
156265
|
156266
|
156267
|
156268
|
156269
|
156270
|
156271
|
156272
|
156273
|
156274
|
156275
|
156276
|
157539
|
157540
|
157541
|
157542
|
157543
|
157544
|
157545
|
157546
|
157547
|
157548
|
157549
|
157550
|
157580
|
157585
|
157640
|
157741
|
157742