Bugzilla – Attachment 95614 Details for
Bug 22544
Move C4:NewsChannels to Koha namespace
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 22544: Add tests
Bug-22544-Add-tests.patch (text/plain), 9.69 KB, created by
Jonathan Druart
on 2019-11-20 13:29:34 UTC
(
hide
)
Description:
Bug 22544: Add tests
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2019-11-20 13:29:34 UTC
Size:
9.69 KB
patch
obsolete
>From 462b185237499e40e80510977c6a219889639dcc Mon Sep 17 00:00:00 2001 >From: Josef Moravec <josef.moravec@gmail.com> >Date: Wed, 20 Mar 2019 10:20:29 +0000 >Subject: [PATCH] Bug 22544: Add tests > >--- > t/db_dependent/Koha/News.t | 266 ++++++++++++++++++++++++++++++++++++++++----- > 1 file changed, 239 insertions(+), 27 deletions(-) > >diff --git a/t/db_dependent/Koha/News.t b/t/db_dependent/Koha/News.t >index e1b56f5f3f..bf3c531db6 100644 >--- a/t/db_dependent/Koha/News.t >+++ b/t/db_dependent/Koha/News.t >@@ -20,39 +20,251 @@ > use Modern::Perl; > > use Test::More tests => 5; >+use Test::Exception; > >-use Koha::NewsItem; > use Koha::News; > use Koha::Database; >+use Koha::DateUtils; > > use t::lib::TestBuilder; > > my $schema = Koha::Database->new->schema; >-$schema->storage->txn_begin; >- > my $builder = t::lib::TestBuilder->new; >-my $library = $builder->build({ source => 'Branch'}); >-my $nb_of_news = Koha::News->search->count; >-my $new_news_item_1 = Koha::NewsItem->new({ >- branchcode => $library->{branchcode}, >- title => 'a news', >- content => 'content for news 1', >-})->store; >-my $new_news_item_2 = Koha::NewsItem->new({ >- 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'); >-is( Koha::News->search->count, $nb_of_news + 2, 'The 2 news should have been added' ); >- >-my $retrieved_news_item_1 = Koha::News->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; >-is( Koha::News->search->count, $nb_of_news + 1, 'Delete should have deleted the news_item' ); >- >-$schema->storage->txn_rollback; > >+subtest 'Koha::News basic test' => sub { >+ >+ plan tests => 5; >+ >+ $schema->storage->txn_begin; >+ >+ my $library = $builder->build({ source => 'Branch'}); >+ my $nb_of_news = Koha::News->search->count; >+ my $new_news_item_1 = Koha::NewsItem->new({ >+ branchcode => $library->{branchcode}, >+ title => 'a news', >+ content => 'content for news 1', >+ })->store; >+ my $new_news_item_2 = Koha::NewsItem->new({ >+ 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'); >+ is( Koha::News->search->count, $nb_of_news + 2, 'The 2 news should have been added' ); >+ >+ my $retrieved_news_item_1 = Koha::News->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; >+ is( Koha::News->search->count, $nb_of_news + 1, 'Delete should have deleted the news_item' ); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+subtest '->is_expired' => sub { >+ >+ plan tests => 3; >+ >+ $schema->storage->txn_begin; >+ >+ my $today = dt_from_string; >+ my $yesterday = dt_from_string->add( days => -1 ); >+ my $tommorow = dt_from_string->add( days => 1 ); >+ my $new_today = $builder->build_object({ >+ class => 'Koha::News', >+ value => { >+ expirationdate => $today, >+ } >+ }); >+ my $new_expired = $builder->build_object({ >+ class => 'Koha::News', >+ value => { >+ expirationdate => $yesterday, >+ } >+ }); >+ my $new_not_expired = $builder->build_object({ >+ class => 'Koha::News', >+ value => { >+ expirationdate => $tommorow, >+ } >+ }); >+ >+ ok($new_expired->is_expired, 'Expired new is expired'); >+ ok(!$new_not_expired->is_expired, 'Not expired new is not expired'); >+ ok(!$new_today->is_expired, 'Today expiration date means the new is not expired'); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+subtest '->library' => sub { >+ >+ plan tests => 3; >+ >+ $schema->storage->txn_begin; >+ >+ my $library = $builder->build_object({ class => 'Koha::Libraries' }); >+ >+ my $new_with_library = $builder->build_object({ >+ class => 'Koha::News', >+ value => { >+ branchcode => $library->branchcode >+ } >+ }); >+ my $new_without_library = $builder->build_object({ >+ class => 'Koha::News', >+ value => { >+ branchcode => undef >+ } >+ }); >+ >+ ok($new_with_library->library, 'News item with library have library relation'); >+ is($new_with_library->library->branchcode, $library->branchcode, 'The library linked with new item is right'); >+ >+ ok(!$new_without_library->library, 'New item without library does not have library relation'); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+subtest '->author' => sub { >+ >+ plan tests => 3; >+ >+ $schema->storage->txn_begin; >+ >+ my $patron = $builder->build_object({ class => 'Koha::Patrons' }); >+ >+ my $new_with_author = $builder->build_object({ >+ class => 'Koha::News', >+ value => { >+ borrowernumber => $patron->borrowernumber >+ } >+ }); >+ my $new_without_author = $builder->build_object({ >+ class => 'Koha::News', >+ value => { >+ borrowernumber => undef >+ } >+ }); >+ >+ ok($new_with_author->author, 'News item with author have author relation'); >+ is($new_with_author->author->borrowernumber, $patron->borrowernumber, 'The patron linked with new item is right'); >+ >+ ok(!$new_without_author->author, 'New item without author does not have author relation'); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+subtest '->search_for_display' => sub { >+ >+ plan tests => 12; >+ >+ $schema->storage->txn_begin; >+ >+ Koha::News->search->delete; >+ >+ my $today = dt_from_string; >+ my $yesterday = dt_from_string->add( days => -1 ); >+ my $tommorow = dt_from_string->add( days => 1 ); >+ my $library1 = $builder->build_object({ class => 'Koha::Libraries' }); >+ my $library2 = $builder->build_object({ class => 'Koha::Libraries' }); >+ >+ my $new_expired = $builder->build_object({ >+ class => 'Koha::News', >+ value => { >+ expirationdate => $yesterday, >+ timestamp => $today, >+ lang => '', >+ branchcode => undef, >+ number => 1, >+ } >+ }); >+ my $new_not_expired = $builder->build_object({ >+ class => 'Koha::News', >+ value => { >+ expirationdate => $tommorow, >+ timestamp => $today, >+ lang => '', >+ branchcode => undef, >+ number => 2, >+ } >+ }); >+ my $new_not_active = $builder->build_object({ >+ class => 'Koha::News', >+ value => { >+ expirationdate => $tommorow, >+ timestamp => $tommorow, >+ lang => '', >+ branchcode => undef, >+ number => 3, >+ } >+ }); >+ my $new_slip= $builder->build_object({ >+ class => 'Koha::News', >+ value => { >+ expirationdate => $tommorow, >+ timestamp => $today, >+ lang => 'slip', >+ branchcode => $library1->branchcode, >+ number => 4, >+ } >+ }); >+ my $new_intra = $builder->build_object({ >+ class => 'Koha::News', >+ value => { >+ expirationdate => $tommorow, >+ timestamp => $today, >+ lang => 'koha', >+ branchcode => $library2->branchcode, >+ number => 5, >+ } >+ }); >+ my $new_intra2 = $builder->build_object({ >+ class => 'Koha::News', >+ value => { >+ expirationdate => $tommorow, >+ timestamp => $today, >+ lang => 'koha', >+ branchcode => undef, >+ number => 5, >+ } >+ }); >+ my $news = Koha::News->search_for_display; >+ >+ is($news->count, 4, 'Active and not expired news'); >+ is($news->next->number, 2, 'News items are returned in correct order'); >+ >+ $news = Koha::News->search_for_display({ type => 'slip'}); >+ is($news->count, 2, 'Slip and all type returned'); >+ >+ $news = Koha::News->search_for_display({ type => 'koha'}); >+ is($news->count, 3, 'Intranet and all'); >+ >+ $new_not_expired->lang('OpacNavRight_en')->store; >+ $news = Koha::News->search_for_display({ type => 'OpacNavRight', lang => 'en'}); >+ is($news->count, 1, 'OpacNavRight'); >+ is($news->next->idnew, $new_not_expired->idnew, 'Returned the right new item'); >+ >+ $new_intra->lang('')->store; >+ $news = Koha::News->search_for_display({ type => 'opac', lang => 'en'}); >+ is($news->count, 1, 'Only all type is returned'); >+ $new_not_expired->lang('en')->store; >+ $news = Koha::News->search_for_display({ type => 'opac', lang => 'en'}); >+ is($news->count, 2, 'Opac en and all is returned'); >+ >+ $news = Koha::News->search_for_display({ library_id => $library1->branchcode }); >+ is($news->count, 3, 'Filtering by library returns right number of news items'); >+ >+ $news = Koha::News->search_for_display({ library_id => $library2->branchcode}); >+ is($news->count, 3, 'Filtering by library returns right number of news items'); >+ >+ $new_intra->branchcode($library1->branchcode)->store; >+ $news = Koha::News->search_for_display({ library_id => $library2->branchcode}); >+ is($news->count, 2, 'Filtering by library returns right number of news items'); >+ >+ throws_ok { Koha::News->search_for_display({type => 'opac'}) } 'Koha::Exceptions::BadParameter', >+ 'Exception raised when type is opac and no language given'; >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.11.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 22544
:
86772
|
86773
|
86774
|
86775
|
86776
|
86777
|
86780
|
86781
|
90103
|
90104
|
90105
|
90106
|
90107
|
90108
|
90109
|
90110
|
92005
|
92006
|
92007
|
92008
|
92009
|
92010
|
92011
|
92012
|
95613
|
95614
|
95615
|
95627
|
95628
|
95629
|
95630
|
95631
|
95632
|
95633
|
95634
|
99849
|
99850
|
99851
|
99852
|
99853
|
99854
|
99855
|
99856
|
99857
|
104176
|
104177
|
104178
|
104179
|
104180
|
104181
|
104182
|
104183
|
104184
|
111012
|
111013
|
111014
|
111015
|
111016
|
111017
|
111018
|
111019
|
111020
|
111021
|
111022
|
111023
|
115135
|
115136
|
115137
|
115138
|
115139
|
115140
|
115141
|
115142
|
115143
|
115144
|
115145
|
115146
|
115218
|
115296
|
115297
|
115298
|
115299
|
116933
|
116934
|
116935
|
117479
|
117480
|
117481
|
117482
|
117483
|
117484
|
117485
|
117486
|
117487
|
117488
|
117489
|
117490
|
117491
|
117492
|
117493
|
117494
|
117495
|
117496
|
117497
|
118054
|
118055
|
118056
|
118057
|
118058
|
118059
|
118060
|
118061
|
118062
|
118063
|
118064
|
118065
|
118066
|
118067
|
118068
|
118069
|
118070
|
118071
|
118072
|
118073
|
118087
|
118088
|
118089
|
118090
|
118091
|
118092
|
118093
|
118094
|
118095
|
118096
|
118097
|
118098
|
118099
|
118100
|
118101
|
118102
|
118103
|
118104
|
118105
|
118106
|
120377
|
120378
|
120379
|
120380
|
120381
|
120382
|
120383
|
120384
|
120385
|
120386
|
120387
|
120388
|
120389
|
120390
|
120391
|
120392
|
120393
|
120394
|
120395
|
120396
|
122396
|
122397
|
122398
|
122399
|
122400
|
122401
|
122402
|
122403
|
122404
|
122405
|
122406
|
122407
|
122408
|
122409
|
122410
|
122411
|
122412
|
122413
|
122414
|
122415