Bugzilla – Attachment 122289 Details for
Bug 28565
Adding a new syspref for sharing through HEA should be simpler
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 28565: Refactor tests
Bug-28565-Refactor-tests.patch (text/plain), 26.90 KB, created by
Tomás Cohen Arazi
on 2021-06-22 14:52:29 UTC
(
hide
)
Description:
Bug 28565: Refactor tests
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi
Created:
2021-06-22 14:52:29 UTC
Size:
26.90 KB
patch
obsolete
>From 55baa62a3e5dc68bc71327067d6b5d83cf4cb832 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Tue, 22 Jun 2021 11:43:03 -0300 >Subject: [PATCH] Bug 28565: Refactor tests > >Tests were too complex with no gain. They even deleted the whole DB to >run (inside a transaction). I refactored to test the same thing, and >make it rely (mostly) on existing data. > >_count behavior is tested implicitly by comparing with Koha::*->count. > >To test: >1. Run: > $ kshell > k$ prove t/db_dependent/UsageStats.t >=> SUCCESS: Tests pass >2. Apply this patch >3. Repeat 1 >=> SUCCESS: Tests still pass >4. Sign off :-D > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > t/db_dependent/UsageStats.t | 679 ++++++------------------------------ > 1 file changed, 101 insertions(+), 578 deletions(-) > >diff --git a/t/db_dependent/UsageStats.t b/t/db_dependent/UsageStats.t >index ddc12679c5..04767ccccf 100755 >--- a/t/db_dependent/UsageStats.t >+++ b/t/db_dependent/UsageStats.t >@@ -15,23 +15,25 @@ > # with Koha; if not, see <http://www.gnu.org/licenses>. > > use Modern::Perl; >-use Test::More tests => 57; >+ >+use Test::More tests => 4; >+ > use t::lib::Mocks qw(mock_preference); > use t::lib::TestBuilder; >+ > use POSIX qw(strftime); >-use Data::Dumper; >-use Koha::Biblios; > >+use C4::Reserves qw(AddReserve); >+use Koha::Authorities; >+use Koha::Biblios; >+use Koha::Items; > use Koha::Libraries; >+use Koha::Old::Checkouts; >+use Koha::Old::Holds; >+use Koha::Patrons; > > BEGIN { > use_ok('C4::UsageStats'); >- use_ok('C4::Context'); >- use_ok('C4::Biblio'); >- use_ok( 'C4::AuthoritiesMarc', qw(AddAuthority) ); >- use_ok('C4::Reserves'); >- use_ok('MARC::Record'); >- use_ok('Koha::Acquisition::Orders'); > } > > can_ok( >@@ -42,574 +44,95 @@ can_ok( > _count ) > ); > >-my $schema = Koha::Database->new->schema; >-$schema->storage->txn_begin; > my $builder = t::lib::TestBuilder->new; >-my $dbh = C4::Context->dbh; >- >-$dbh->do('DELETE FROM issues'); >-$dbh->do('DELETE FROM biblio'); >-$dbh->do('DELETE FROM items'); >-$dbh->do('DELETE FROM auth_header'); >-$dbh->do('DELETE FROM old_issues'); >-$dbh->do('DELETE FROM old_reserves'); >-$dbh->do('DELETE FROM borrowers'); >-$dbh->do('DELETE FROM aqorders'); >-$dbh->do('DELETE FROM subscription'); >- >-################################################# >-# Testing Subs >-################################################# >- >-# ---------- Testing NeedUpdate ----------------- >- >-#Mocking C4::Context->preference("UsageStatsLastUpdateTime") to 0 >-my $now = strftime( "%s", localtime ); >-t::lib::Mocks::mock_preference( "UsageStatsLastUpdateTime", 0 ); >- >-my $update = C4::UsageStats->NeedUpdate; >-is( $update, 1, "There is no last update, update needed" ); >- >-#Mocking C4::Context->preference("UsageStatsLastUpdateTime") to now >-$now = strftime( "%s", localtime ); >-t::lib::Mocks::mock_preference( "UsageStatsLastUpdateTime", $now ); >- >-$update = C4::UsageStats->NeedUpdate; >-is( $update, 0, "Last update just be done, no update needed " ); >- >-my $nb_of_libraries = Koha::Libraries->count; >- >-# ---------- Testing BuildReport ---------------- >- >-#Test report->library ----------------- >-#mock to 0 >-t::lib::Mocks::mock_preference( "UsageStatsID", 0 ); >-t::lib::Mocks::mock_preference( "UsageStatsLibraryName", 0 ); >-t::lib::Mocks::mock_preference( "UsageStatsLibrariesInfo", 0 ); >-t::lib::Mocks::mock_preference( "UsageStatsLibraryType", 0 ); >-t::lib::Mocks::mock_preference( "UsageStatsCountry", 0 ); >-t::lib::Mocks::mock_preference( "UsageStatsLibraryUrl", 0 ); >- >-my $report = C4::UsageStats->BuildReport(); >- >-isa_ok( $report, 'HASH', '$report is a HASH' ); >-isa_ok( $report->{libraries}, 'ARRAY', '$report->{libraries} is an ARRAY' ); >-is( scalar( @{ $report->{libraries} } ), 0, "There are 0 fields in libraries, libraries info are not shared" ); >-is( $report->{installation}->{koha_id}, 0, "UsageStatsID is good" ); >-is( $report->{installation}->{name}, '', "UsageStatsLibraryName is good" ); >-is( $report->{installation}->{url}, '', "UsageStatsLibraryUrl is good" ); >-is( $report->{installation}->{type}, '', "UsageStatsLibraryType is good" ); >-is( $report->{installation}->{country}, '', "UsageStatsCountry is good" ); >- >- >-#mock with values >-t::lib::Mocks::mock_preference( "UsageStatsID", 1 ); >-t::lib::Mocks::mock_preference( "UsageStatsLibraryName", 'NAME' ); >-t::lib::Mocks::mock_preference( "UsageStatsLibraryUrl", 'URL' ); >-t::lib::Mocks::mock_preference( "UsageStatsLibraryType", 'TYPE' ); >-t::lib::Mocks::mock_preference( "UsageStatsCountry", 'COUNTRY' ); >-t::lib::Mocks::mock_preference( "UsageStatsLibrariesInfo", 1 ); >-t::lib::Mocks::mock_preference( "UsageStatsGeolocation", 1 ); >- >- >-$report = C4::UsageStats->BuildReport(); >- >-isa_ok( $report, 'HASH', '$report is a HASH' ); >-isa_ok( $report->{libraries}, 'ARRAY', '$report->{libraries} is an ARRAY' ); >-is( scalar( @{ $report->{libraries} } ), $nb_of_libraries, "There are 6 fields in $report->{libraries}" ); >-is( $report->{installation}->{koha_id}, 1, "UsageStatsID is good" ); >-is( $report->{installation}->{name}, 'NAME', "UsageStatsLibraryName is good" ); >-is( $report->{installation}->{url}, 'URL', "UsageStatsLibraryUrl is good" ); >-is( $report->{installation}->{type}, 'TYPE', "UsageStatsLibraryType is good" ); >-is( $report->{installation}->{country}, 'COUNTRY', "UsageStatsCountry is good" ); >- >-#Test report->volumetry --------------- >-#with original values >-$report = C4::UsageStats->BuildReport(); >- >-isa_ok( $report, 'HASH', '$report is a HASH' ); >-isa_ok( $report->{volumetry}, 'HASH', '$report->{volumetry} is a HASH' ); >-is( scalar( keys %{$report->{volumetry}} ), 8, "There are 8 fields in $report->{volumetry}" ); >-is( $report->{volumetry}->{biblio}, 0, "There is no biblio" ); >-is( $report->{volumetry}->{items}, 0, "There is no items" ); >-is( $report->{volumetry}->{auth_header}, 0, "There is no auth_header" ); >-is( $report->{volumetry}->{old_issues}, 0, "There is no old_issues" ); >-is( $report->{volumetry}->{old_reserves}, 0, "There is no old_reserves" ); >-is( $report->{volumetry}->{borrowers}, 0, "There is no borrowers" ); >-is( $report->{volumetry}->{aqorders}, 0, "There is no aqorders" ); >-is( $report->{volumetry}->{subscription}, 0, "There is no subscription" ); >- >-#after adding objects >-construct_objects_needed(); >- >-$report = C4::UsageStats->BuildReport(); >- >-isa_ok( $report, 'HASH', '$report is a HASH' ); >-isa_ok( $report->{volumetry}, 'HASH', '$report->{volumetry} is a HASH' ); >-is( scalar( keys %{$report->{volumetry}} ), 8, "There are 8 fields in $report->{volumetry}" ); >-is( $report->{volumetry}->{biblio}, 3, "There are 3 biblio" ); >-is( $report->{volumetry}->{items}, 3, "There are 3 items" ); >-is( $report->{volumetry}->{auth_header}, 2, "There are 2 auth_header" ); >-is( $report->{volumetry}->{old_issues}, 1, "There is 1 old_issues" ); >-is( $report->{volumetry}->{old_reserves}, 1, "There is 1 old_reserves" ); >-is( $report->{volumetry}->{borrowers}, 3, "There are 3 borrowers" ); >-is( $report->{volumetry}->{aqorders}, 1, "There is 1 aqorders" ); >-is( $report->{volumetry}->{subscription}, 1, "There is 1 subscription" ); >- >-#Test report->systempreferences ------- >-#mock to 0 >-mocking_systempreferences_to_a_set_value(0); >- >-$report = C4::UsageStats->BuildReport(); >-isa_ok( $report, 'HASH', '$report is a HASH' ); >-isa_ok( $report->{systempreferences}, 'HASH', '$report->{systempreferences} is a HASH' ); >-verif_systempreferences_values( $report, 0 ); >- >-#mock with values >-mocking_systempreferences_to_a_set_value(1); >- >-$report = C4::UsageStats->BuildReport(); >-isa_ok( $report, 'HASH', '$report is a HASH' ); >-isa_ok( $report->{systempreferences}, 'HASH', '$report->{systempreferences} is a HASH' ); >-verif_systempreferences_values( $report, 1 ); >- >-#Test if unwanted syspref are not sent >-is( $report->{systempreferences}->{useDischarge}, undef, 'useDischarge should not be shared'); >-is( $report->{systempreferences}->{OpacUserJS}, undef, 'OpacUserJS should not be shared'); >- >-# ---------- Testing ReportToCommunity ---------- >- >-# ---------- Testing _count --------------------- >-my $query = ' >- SELECT count(*) >- FROM borrowers >- '; >-my $count = $dbh->selectrow_array($query); >- >-my $nb_fields = C4::UsageStats::_count('borrowers'); >-is( $nb_fields, $count, "_count return the good number of fields" ); >- >-################################################# >-# Subs >-################################################# >- >-# Adding : >-# 3 borrowers >-# 4 biblio >-# 3 biblio items >-# 3 items >-# 2 auth_header >-# 1 old_issues >-# 1 old_reserves >-# 1 subscription >-# 1 aqorders >-sub construct_objects_needed { >- >- # ---------- 3 borrowers --------------------- >- my $surname1 = 'Borrower 1'; >- my $surname2 = 'Borrower 2'; >- my $surname3 = 'Borrower 3'; >- my $firstname1 = 'firstname 1'; >- my $firstname2 = 'firstname 2'; >- my $firstname3 = 'firstname 3'; >- my $cardnumber1 = 'test_card1'; >- my $cardnumber2 = 'test_card2'; >- my $cardnumber3 = 'test_card3'; >- my $categorycode = $builder->build({ source => 'Category' })->{categorycode}; >- my $branchcode = $builder->build({ source => 'Branch' })->{branchcode}; >- >- my $query = ' >- INSERT INTO borrowers >- (surname, firstname, cardnumber, branchcode, categorycode) >- VALUES (?,?,?,?,?)'; >- my $insert_sth = $dbh->prepare($query); >- $insert_sth->execute( $surname1, $firstname1, $cardnumber1, $branchcode, $categorycode ); >- my $borrowernumber1 = $dbh->last_insert_id( undef, undef, 'borrowers', undef ); >- $insert_sth->execute( $surname2, $firstname2, $cardnumber2, $branchcode, $categorycode ); >- my $borrowernumber2 = $dbh->last_insert_id( undef, undef, 'borrowers', undef ); >- $insert_sth->execute( $surname3, $firstname3, $cardnumber3, $branchcode, $categorycode ); >- my $borrowernumber3 = $dbh->last_insert_id( undef, undef, 'borrowers', undef ); >- >- # ---------- 3 biblios ----------------------- >- my $title1 = 'Title 1'; >- my $title2 = 'Title 2'; >- my $title3 = 'Title 3'; >- my $author1 = 'Author 1'; >- my $author2 = 'Author 2'; >- my $author3 = 'Author 3'; >- >- $query = ' >- INSERT INTO biblio >- (title, author, datecreated) >- VALUES (?,?, NOW())'; >- $insert_sth = $dbh->prepare($query); >- $insert_sth->execute( $title1, $author1 ); >- my $biblionumber1 = $dbh->last_insert_id( undef, undef, 'biblio', undef ); >- $insert_sth->execute( $title2, undef ); >- my $biblionumber2 = $dbh->last_insert_id( undef, undef, 'biblio', undef ); >- $insert_sth->execute( $title3, $author3 ); >- my $biblionumber3 = $dbh->last_insert_id( undef, undef, 'biblio', undef ); >- >- # ---------- 3 biblio items ------------------------- >- $query = ' >- INSERT INTO biblioitems >- (biblionumber, itemtype) >- VALUES (?,?)'; >- $insert_sth = $dbh->prepare($query); >- $insert_sth->execute( $biblionumber1, 'Book' ); >- my $biblioitemnumber1 = $dbh->last_insert_id( undef, undef, 'biblioitems', undef ); >- $insert_sth->execute( $biblionumber2, 'Music' ); >- my $biblioitemnumber2 = $dbh->last_insert_id( undef, undef, 'biblioitems', undef ); >- $insert_sth->execute( $biblionumber3, 'Book' ); >- my $biblioitemnumber3 = $dbh->last_insert_id( undef, undef, 'biblioitems', undef ); >- >- # ---------- 3 items ------------------------- >- my $barcode1 = '111111'; >- my $barcode2 = '222222'; >- my $barcode3 = '333333'; >- >- $query = ' >- INSERT INTO items >- (biblionumber, biblioitemnumber, barcode, itype) >- VALUES (?,?,?,?)'; >- $insert_sth = $dbh->prepare($query); >- $insert_sth->execute( $biblionumber1, $biblioitemnumber1, $barcode1, 'Book' ); >- my $item_number1 = $dbh->last_insert_id( undef, undef, 'items', undef ); >- $insert_sth->execute( $biblionumber2, $biblioitemnumber2, $barcode2, 'Music' ); >- my $item_number2 = $dbh->last_insert_id( undef, undef, 'items', undef ); >- $insert_sth->execute( $biblionumber3, $biblioitemnumber3, $barcode3, 'Book' ); >- my $item_number3 = $dbh->last_insert_id( undef, undef, 'items', undef ); >- >- # ---------- Add 2 auth_header >- $query = ' >- INSERT INTO auth_header >- (authtypecode, marcxml) >- VALUES (?, "")'; >- $insert_sth = $dbh->prepare($query); >- $insert_sth->execute('atc1'); >- my $authid1 = $dbh->last_insert_id( undef, undef, 'auth_header', undef ); >- $insert_sth->execute('atc2'); >- my $authid2 = $dbh->last_insert_id( undef, undef, 'auth_header', undef ); >- >- # ---------- Add 1 old_issues >- $query = ' >- INSERT INTO old_issues >- (issue_id, borrowernumber, branchcode, itemnumber) >- VALUES ((select coalesce(max(issue_id), 0)+1 from issues),?,?,?)'; >- $insert_sth = $dbh->prepare($query); >- $insert_sth->execute( $borrowernumber1, $branchcode, $item_number1 ); >- my $issue_id1 = $dbh->last_insert_id( undef, undef, 'old_issues', undef ); >- >- # ---------- Add 1 old_reserves >- AddReserve( >- { >- branchcode => $branchcode, >- borrowernumber => $borrowernumber1, >- biblionumber => $biblionumber1, >- priority => 1, >- title => 'Title', >- } >- ); >- my $biblio = Koha::Biblios->find( $biblionumber1 ); >- my $holds = $biblio->holds; >- $holds->next->cancel if $holds->count; >- >- # ---------- Add 1 aqbudgets >- $query = ' >- INSERT INTO aqbudgets >- (budget_amount) >- VALUES (?)'; >- $insert_sth = $dbh->prepare($query); >- $insert_sth->execute("20.0"); >- my $aqbudgets1 = $dbh->last_insert_id( undef, undef, 'aqbudgets', undef ); >- >- # ---------- Add 1 aqorders >- $query = ' >- INSERT INTO aqorders >- (budget_id, basketno, biblionumber, invoiceid, subscriptionid) >- VALUES (?,?,?,?,?)'; >- $insert_sth = $dbh->prepare($query); >- $insert_sth->execute( $aqbudgets1, undef, undef, undef, undef ); >- my $aqorders1 = $dbh->last_insert_id( undef, undef, 'aqorders', undef ); >- >- # --------- Add 1 subscription >- $query = ' >- INSERT INTO subscription >- (biblionumber) >- VALUES (?)'; >- $insert_sth = $dbh->prepare($query); >- $insert_sth->execute($biblionumber1); >- my $subscription1 = $dbh->last_insert_id( undef, undef, 'subscription', undef ); >- >-} >- >-#Change systempreferences values to $set_value >-sub mocking_systempreferences_to_a_set_value { >- my $set_value = shift; >- >- foreach ( >- qw/ >- AcqCreateItem >- AcqWarnOnDuplicateInvoice >- AcqViewBaskets >- AllowHoldItemTypeSelection >- BasketConfirmations >- OrderPdfFormat >- casAuthentication >- casLogout >- AllowPKIAuth >- DebugLevel >- CSVDelimiter >- noItemTypeImages >- OpacNoItemTypeImages >- virtualshelves >- AutoLocation >- IndependentBranches >- SessionStorage >- Persona >- AuthDisplayHierarchy >- AutoCreateAuthorities >- BiblioAddsAuthorities >- AuthorityMergeLimit >- AuthorityMergeMode >- UseAuthoritiesForTracings >- CatalogModuleRelink >- hide_marc >- IntranetBiblioDefaultView >- LabelMARCView >- OpacSuppression >- SeparateHoldings >- UseControlNumber >- advancedMARCeditor >- DefaultClassificationSource >- EasyAnalyticalRecords >- autoBarcode >- item-level_itypes >- marcflavour >- PrefillItem >- z3950NormalizeAuthor >- SpineLabelAutoPrint >- SpineLabelShowPrintOnBibDetails >- BlockReturnOfLostItems >- BlockReturnOfWithdrawnItems >- CalculateFinesOnReturn >- AgeRestrictionOverride >- AllFinesNeedOverride >- AllowFineOverride >- AllowItemsOnHoldCheckoutSIP >- AllowItemsOnHoldCheckoutSCO >- AllowNotForLoanOverride >- AllowRenewalLimitOverride >- AllowReturnToBranch >- AllowTooManyOverride >- AutomaticItemReturn >- AutoRemoveOverduesRestrictions >- CircControl >- HomeOrHoldingBranch >- HomeOrHoldingBranchReturn >- IssueLostItem >- IssuingInProcess >- ManInvInNoissuesCharge >- OverduesBlockCirc >- RenewalPeriodBase >- RenewalSendNotice >- RentalsInNoissuesCharge >- ReturnBeforeExpiry >- TransfersMaxDaysWarning >- UseBranchTransferLimits >- UseTransportCostMatrix >- UseCourseReserves >- finesCalendar >- FinesIncludeGracePeriod >- finesMode >- RefundLostOnReturnControl >- WhenLostChargeReplacementFee >- WhenLostForgiveFine >- AllowHoldDateInFuture >- AllowHoldPolicyOverride >- AllowHoldsOnDamagedItems >- AllowHoldsOnPatronsPossessions >- AutoResumeSuspendedHolds >- canreservefromotherbranches >- decreaseLoanHighHolds >- DisplayMultiPlaceHold >- emailLibrarianWhenHoldIsPlaced >- ExpireReservesMaxPickUpDelay >- OPACAllowHoldDateInFuture >- OPACAllowUserToChooseBranch >- ReservesControlBranch >- ReservesNeedReturns >- SuspendHoldsIntranet >- SuspendHoldsOpac >- TransferWhenCancelAllWaitingHolds >- AllowAllMessageDeletion >- AllowOfflineCirculation >- PatronAutoComplete >- CircAutoPrintQuickSlip >- DisplayClearScreenButton >- FilterBeforeOverdueReport >- FineNotifyAtCheckin >- itemBarcodeFallbackSearch >- itemBarcodeInputFilter >- previousIssuesDefaultSortOrder >- RecordLocalUseOnReturn >- soundon >- SpecifyDueDate >- todaysIssuesDefaultSortOrder >- UpdateTotalIssuesOnCirc >- UseTablesortForCirc >- WaitingNotifyAtCheckin >- SCOAllowCheckin >- AutoSelfCheckAllowed >- FRBRizeEditions >- OPACFRBRizeEditions >- AmazonCoverImages >- OPACAmazonCoverImages >- Babeltheque >- BakerTaylorEnabled >- GoogleJackets >- HTML5MediaEnabled >- LibraryThingForLibrariesEnabled >- LocalCoverImages >- OPACLocalCoverImages >- NovelistSelectEnabled >- OpenLibraryCovers >- OpenLibrarySearch >- SyndeticsEnabled >- TagsEnabled >- CalendarFirstDayOfWeek >- opaclanguagesdisplay >- AcquisitionLog >- AuthoritiesLog >- BorrowersLog >- CataloguingLog >- FinesLog >- IssueLog >- ClaimsLog >- ReturnLog >- SubscriptionLog >- BiblioDefaultView >- COinSinOPACResults >- DisplayOPACiconsXSLT >- hidelostitems >- HighlightOwnItemsOnOPAC >- OpacAddMastheadLibraryPulldown >- OPACDisplay856uAsImage >- OpacHighlightedWords >- OpacKohaUrl >- OpacMaintenance >- OpacPublic >- OpacSeparateHoldings >- OPACShowCheckoutName >- OpacShowFiltersPulldownMobile >- OPACShowHoldQueueDetails >- OpacShowRecentComments >- OPACShowUnusedAuthorities >- OpacStarRatings >- opacthemes >- OPACURLOpenInNewWindow >- OpacAuthorities >- opacbookbag >- OpacBrowser >- OpacBrowseResults >- OpacCloud >- OPACFinesTab >- OpacHoldNotes >- OpacItemLocation >- OpacPasswordChange >- OPACPatronDetails >- OPACpatronimages >- OPACPopupAuthorsSearch >- OpacTopissue >- opacuserlogin >- QuoteOfTheDay >- RequestOnOpac >- OPACComments >- ShowReviewer >- ShowReviewerPhoto >- SocialNetworks >- suggestion >- OpacAllowPublicListCreation >- OpacAllowSharingPrivateLists >- OpacRenewalAllowed >- OpacRenewalBranch >- OPACViewOthersSuggestions >- SearchMyLibraryFirst >- singleBranchMode >- AnonSuggestions >- EnableOpacSearchHistory >- OPACPrivacy >- opacreadinghistory >- TrackClicks >- PatronSelfRegistration >- OPACShelfBrowser >- AutoEmailOpacUser >- AutoEmailPrimaryAddress >- autoMemberNum >- BorrowerRenewalPeriodBase >- EnableBorrowerFiles >- EnhancedMessagingPreferences >- ExtendedPatronAttributes >- intranetreadinghistory >- patronimages >- TalkingTechItivaPhoneNotification >- uppercasesurnames >- IncludeSeeFromInSearches >- QueryAutoTruncate >- QueryFuzzy >- QueryStemming >- QueryWeightFields >- TraceCompleteSubfields >- TraceSubjectSubdivisions >- UseICUStyleQuotes >- defaultSortField >- displayFacetCount >- OPACdefaultSortField >- OPACItemsResultsDisplay >- expandedSearchOption >- IntranetNumbersPreferPhrase >- OPACNumbersPreferPhrase >- opacSerialDefaultTab >- RenewSerialAddsSuggestion >- RoutingListAddReserves >- RoutingSerials >- SubscriptionHistory >- Display856uAsImage >- DisplayIconsXSLT >- template >- yuipath >- HidePatronName >- intranetbookbag >- StaffDetailItemSelection >- viewISBD >- viewLabeledMARC >- viewMARC >- ILS-DI >- OAI-PMH >- version >- AudioAlerts >- / >- ) { >- t::lib::Mocks::mock_preference( $_, $set_value ); >- } >-} >- >-#Test if all systempreferences are at $value_to_test >-sub verif_systempreferences_values { >- my ( $report, $value_to_test ) = @_; >- >- my @missings; >- foreach my $key ( keys %{$report->{systempreferences}} ) { >- if ( $report->{systempreferences}->{$key} ne $value_to_test ) { >- warn $key; >- push @missings, $key; >- } >- } >- unless ( @missings ) { >- ok(1, 'All prefs are present'); >- } else { >- ok(0, 'Some prefs are missing: ' . Dumper(\@missings)); >- } >-} >+my $schema = Koha::Database->new->schema; > >-$schema->storage->txn_rollback; >+subtest 'NeedUpdate() tests' => sub { >+ >+ plan tests => 2; >+ >+ #Mocking C4::Context->preference("UsageStatsLastUpdateTime") to 0 >+ my $now = strftime( "%s", localtime ); >+ t::lib::Mocks::mock_preference( "UsageStatsLastUpdateTime", 0 ); >+ >+ my $update = C4::UsageStats->NeedUpdate; >+ is( $update, 1, "There is no last update, update needed" ); >+ >+ #Mocking C4::Context->preference("UsageStatsLastUpdateTime") to now >+ $now = strftime( "%s", localtime ); >+ t::lib::Mocks::mock_preference( "UsageStatsLastUpdateTime", $now ); >+ >+ $update = C4::UsageStats->NeedUpdate; >+ is( $update, 0, "Last update just be done, no update needed " ); >+}; >+ >+subtest 'BuildReport() tests' => sub { >+ >+ plan tests => 30; >+ >+ $schema->storage->txn_begin; >+ >+ # make sure we have some data for each 'volumetry' key >+ my $category = $builder->build_object( { class => 'Koha::Patron::Categories' } ); >+ my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); >+ my $library = $builder->build_object( { class => 'Koha::Libraries' } ); >+ my $biblio = $builder->build_sample_biblio(); >+ my $item = $builder->build_sample_item(); >+ $builder->build_object( { class => 'Koha::Old::Holds' } ); >+ $builder->build_object( { class => 'Koha::Old::Checkouts' } ); >+ >+ t::lib::Mocks::mock_preference( "UsageStatsID", 0 ); >+ t::lib::Mocks::mock_preference( "UsageStatsLibraryName", 0 ); >+ t::lib::Mocks::mock_preference( "UsageStatsLibrariesInfo", 0 ); >+ t::lib::Mocks::mock_preference( "UsageStatsLibraryType", 0 ); >+ t::lib::Mocks::mock_preference( "UsageStatsCountry", 0 ); >+ t::lib::Mocks::mock_preference( "UsageStatsLibraryUrl", 0 ); >+ >+ my $report = C4::UsageStats->BuildReport(); >+ >+ isa_ok( $report, 'HASH', '$report is a HASH' ); >+ isa_ok( $report->{libraries}, 'ARRAY', '$report->{libraries} is an ARRAY' ); >+ is( scalar( @{ $report->{libraries} } ), 0, "There are 0 fields in libraries, libraries info are not shared" ); >+ is( $report->{installation}->{koha_id}, 0, "UsageStatsID is good" ); >+ is( $report->{installation}->{name}, '', "UsageStatsLibraryName is good" ); >+ is( $report->{installation}->{url}, '', "UsageStatsLibraryUrl is good" ); >+ is( $report->{installation}->{type}, '', "UsageStatsLibraryType is good" ); >+ is( $report->{installation}->{country}, '', "UsageStatsCountry is good" ); >+ is( $report->{installation}->{geolocation}, '', "UsageStatsGeolocation is good" ); >+ >+ #mock with values >+ t::lib::Mocks::mock_preference( "UsageStatsID", 1 ); >+ t::lib::Mocks::mock_preference( "UsageStatsLibraryName", 'NAME' ); >+ t::lib::Mocks::mock_preference( "UsageStatsLibraryUrl", 'URL' ); >+ t::lib::Mocks::mock_preference( "UsageStatsLibraryType", 'TYPE' ); >+ t::lib::Mocks::mock_preference( "UsageStatsCountry", 'COUNTRY' ); >+ t::lib::Mocks::mock_preference( "UsageStatsLibrariesInfo", 1 ); >+ t::lib::Mocks::mock_preference( "UsageStatsGeolocation", 1 ); >+ >+ $report = C4::UsageStats->BuildReport(); >+ >+ isa_ok( $report, 'HASH', '$report is a HASH' ); >+ isa_ok( $report->{libraries}, 'ARRAY', '$report->{libraries} is an ARRAY' ); >+ is( scalar( @{ $report->{libraries} } ), Koha::Libraries->count, "There are 6 fields in $report->{libraries}" ); >+ is( $report->{installation}->{koha_id}, 1, "UsageStatsID is good" ); >+ is( $report->{installation}->{name}, 'NAME', "UsageStatsLibraryName is good" ); >+ is( $report->{installation}->{url}, 'URL', "UsageStatsLibraryUrl is good" ); >+ is( $report->{installation}->{type}, 'TYPE', "UsageStatsLibraryType is good" ); >+ is( $report->{installation}->{country}, 'COUNTRY', "UsageStatsCountry is good" ); >+ is( $report->{installation}->{geolocation}, '1', "UsageStatsGeolocation is good" ); >+ ok( exists $report->{systempreferences}, 'systempreferences is present' ); >+ >+ isa_ok( $report, 'HASH', '$report is a HASH' ); >+ isa_ok( $report->{volumetry}, 'HASH', '$report->{volumetry} is a HASH' ); >+ is( scalar( keys %{ $report->{volumetry} } ), 8, "There are 8 fields in 'volumetry'" ); >+ is( $report->{volumetry}->{biblio}, Koha::Biblios->count, "Biblios count correct" ); >+ is( $report->{volumetry}->{items}, Koha::Items->count, "Items count correct" ); >+ is( $report->{volumetry}->{auth_header}, Koha::Authorities->count, "Authorities count correct" ); >+ is( $report->{volumetry}->{old_issues}, Koha::Old::Checkouts->count, "Old checkouts count correct" ); >+ is( $report->{volumetry}->{old_reserves}, Koha::Old::Holds->count, "Old holds count correct" ); >+ is( $report->{volumetry}->{borrowers}, Koha::Patrons->count, "Patrons count correct" ); >+ is( $report->{volumetry}->{aqorders}, Koha::Acquisition::Orders->count, "Orders count correct" ); >+ is( $report->{volumetry}->{subscription}, Koha::Subscriptions->count, "Suscriptions count correct" ); >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.32.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 28565
:
121938
|
121939
|
121986
|
121987
|
122289
|
122353
|
122354
|
123167
|
123168