From 7404857fb2349087797dfbba4ea14b5080b3599b Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Sat, 4 May 2019 12:31:05 -0400 Subject: [PATCH] Bug 22850: Do no longer use set_userenv in tests (SharedContent.t) Since bug 21817 we should use the mock_userenv subroutine instead. Test plan: The tests must pass after this patch --- t/db_dependent/Koha/SharedContent.t | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/t/db_dependent/Koha/SharedContent.t b/t/db_dependent/Koha/SharedContent.t index 67be87ec55..2739afbce6 100644 --- a/t/db_dependent/Koha/SharedContent.t +++ b/t/db_dependent/Koha/SharedContent.t @@ -111,19 +111,20 @@ is($request->method, 'POST', 'Share report - Method is post'); is($request->uri->path, '/report.json', 'Path is report.json'); # prepare shared data -my $loggedinuser = $builder->build({ - source => 'Borrower', +my $library = $builder->build_object({ + class => 'Koha::Libraries', +}); + +my $loggedinuser = $builder->build_object({ + class => 'Koha::Patrons', value => { email => '', emailpro => '', - B_email => '' + B_email => '', + branchcode => $library->branchcode, } }); -my $library = $builder->build({ - source => 'Branch', -}); - my $biblio = $builder->build({ source => 'Biblio', }); @@ -153,17 +154,12 @@ my $subscription = $builder->build({ } }); -C4::Context->_new_userenv('xxx'); -C4::Context->set_userenv(0,0,0, - $loggedinuser->{firstname}, - $loggedinuser->{surname}, - $library->{branchcode}, - 'Midway Public Library', '', '', ''); +t::lib::Mocks::mock_userenv({ patron => $loggedinuser}); t::lib::Mocks::mock_preference('language', 'en'); $post_request = 1; -$result = Koha::SharedContent::send_entity('en', $loggedinuser->{borrowernumber}, $subscription->{subscriptionid}, 'subscription'); +$result = Koha::SharedContent::send_entity('en', $loggedinuser->borrowernumber, $subscription->{subscriptionid}, 'subscription'); is($result->{code}, 200, 'send_entity success'); my $s = Koha::Subscriptions->find($subscription->{subscriptionid}); @@ -171,14 +167,13 @@ is($s->mana_id, 5, 'Mana id is set'); my $data = Koha::SharedContent::prepare_entity_data( '', - $loggedinuser->{borrowernumber}, + $loggedinuser->borrowernumber, $subscription->{subscriptionid}, 'subscription' ); is($data->{language}, 'en', 'Language is set to default'); -my $branch = Koha::Libraries->find($library->{branchcode}); -is($data->{exportemail}, $branch->branchemail, 'Email is set with the userenv branch one'); +is($data->{exportemail}, $library->branchemail, 'Email is set with the userenv branch one'); is($data->{title}, $biblio->{title}, 'Shared title'); is($data->{sfdescription}, $subscriptionFrequency->{description}, 'Shared sfdescription'); is($data->{unit}, $subscriptionFrequency->{unit}, 'Shared unit'); -- 2.11.0