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

(-)a/t/db_dependent/UsageStats.t (-21 / +22 lines)
Lines 15-21 Link Here
15
# with Koha; if not, see <http://www.gnu.org/licenses>.
15
# with Koha; if not, see <http://www.gnu.org/licenses>.
16
16
17
use Modern::Perl;
17
use Modern::Perl;
18
use Test::More tests => 59;
18
use Test::More tests => 57;
19
use t::lib::Mocks qw(mock_preference);
19
use t::lib::Mocks qw(mock_preference);
20
use POSIX qw(strftime);
20
use POSIX qw(strftime);
21
use Data::Dumper;
21
use Data::Dumper;
Lines 74-79 t::lib::Mocks::mock_preference( "UsageStatsLastUpdateTime", $now ); Link Here
74
$update = C4::UsageStats->NeedUpdate;
74
$update = C4::UsageStats->NeedUpdate;
75
is( $update, 0, "Last update just be done, no update needed " );
75
is( $update, 0, "Last update just be done, no update needed " );
76
76
77
my $nb_of_libraries = Koha::Libraries->count;
78
77
# ---------- Testing BuildReport ----------------
79
# ---------- Testing BuildReport ----------------
78
80
79
#Test report->library -----------------
81
#Test report->library -----------------
Lines 87-101 t::lib::Mocks::mock_preference( "UsageStatsLibraryUrl", 0 ); Link Here
87
89
88
my $report = C4::UsageStats->BuildReport();
90
my $report = C4::UsageStats->BuildReport();
89
91
90
isa_ok( $report,            'HASH', '$report is a HASH' );
92
isa_ok( $report,              'HASH',  '$report is a HASH' );
91
isa_ok( $report->{library}, 'HASH', '$report->{library} is a HASH' );
93
isa_ok( $report->{libraries}, 'ARRAY', '$report->{libraries} is an ARRAY' );
92
is( scalar( keys %{$report->{library}} ), 6,  "There are 6 fields in $report->{library}" );
94
is( scalar( @{ $report->{libraries} } ), 0, "There are 0 fields in libraries, libraries info are not shared" );
93
is( $report->{library}->{id},             0,  "UsageStatsID           is good" );
95
is( $report->{installation}->{koha_id}, 0,  "UsageStatsID          is good" );
94
is( $report->{library}->{name},           '', "UsageStatsLibraryName  is good" );
96
is( $report->{installation}->{name},    '', "UsageStatsLibraryName is good" );
95
is( $report->{library}->{url},            '', "UsageStatsLibraryUrl   is good" );
97
is( $report->{installation}->{url},     '', "UsageStatsLibraryUrl  is good" );
96
is( $report->{library}->{type},           '', "UsageStatsLibraryType  is good" );
98
is( $report->{installation}->{type},    '', "UsageStatsLibraryType is good" );
97
is( $report->{library}->{country},        '', "UsageStatsCountry      is good" );
99
is( $report->{installation}->{country}, '', "UsageStatsCountry     is good" );
98
is( $report->{library}->{number_of_libraries}, undef, "UsageStatsLibrariesInfo is good" );
100
99
101
100
#mock with values
102
#mock with values
101
t::lib::Mocks::mock_preference( "UsageStatsID",          1 );
103
t::lib::Mocks::mock_preference( "UsageStatsID",          1 );
Lines 104-122 t::lib::Mocks::mock_preference( "UsageStatsLibraryUrl", 'URL' ); Link Here
104
t::lib::Mocks::mock_preference( "UsageStatsLibraryType", 'TYPE' );
106
t::lib::Mocks::mock_preference( "UsageStatsLibraryType", 'TYPE' );
105
t::lib::Mocks::mock_preference( "UsageStatsCountry",     'COUNTRY' );
107
t::lib::Mocks::mock_preference( "UsageStatsCountry",     'COUNTRY' );
106
t::lib::Mocks::mock_preference( "UsageStatsLibrariesInfo", 1 );
108
t::lib::Mocks::mock_preference( "UsageStatsLibrariesInfo", 1 );
109
t::lib::Mocks::mock_preference( "UsageStatsGeolocation", 1 );
110
107
111
108
$report = C4::UsageStats->BuildReport();
112
$report = C4::UsageStats->BuildReport();
109
113
110
isa_ok( $report,            'HASH', '$report is a HASH' );
114
isa_ok( $report,              'HASH',  '$report is a HASH' );
111
isa_ok( $report->{library}, 'HASH', '$report->{library} is a HASH' );
115
isa_ok( $report->{libraries}, 'ARRAY', '$report->{libraries} is an ARRAY' );
112
is( scalar( keys %{$report->{library}} ), 6,         "There are 6 fields in $report->{library}" );
116
is( scalar( @{ $report->{libraries} } ), $nb_of_libraries, "There are 6 fields in $report->{libraries}" );
113
is( $report->{library}->{id},             1,         "UsageStatsID            is good" );
117
is( $report->{installation}->{koha_id}, 1,     "UsageStatsID          is good" );
114
is( $report->{library}->{name},           'NAME',    "UsageStatsLibraryName   is good" );
118
is( $report->{installation}->{name},   'NAME', "UsageStatsLibraryName is good" );
115
is( $report->{library}->{url},            'URL',     "UsageStatsLibraryUrl    is good" );
119
is( $report->{installation}->{url},     'URL', "UsageStatsLibraryUrl  is good" );
116
is( $report->{library}->{type},           'TYPE',    "UsageStatsLibraryType   is good" );
120
is( $report->{installation}->{type},   'TYPE', "UsageStatsLibraryType is good" );
117
is( $report->{library}->{country},        'COUNTRY', "UsageStatsCountry       is good" );
121
is( $report->{installation}->{country}, 'COUNTRY', "UsageStatsCountry is good" );
118
my $nb_of_libraries = Koha::Libraries->count;
119
is( $report->{library}->{number_of_libraries}, $nb_of_libraries, "UsageStatsLibrariesInfo is good" );
120
122
121
#Test report->volumetry ---------------
123
#Test report->volumetry ---------------
122
#with original values
124
#with original values
123
- 

Return to bug 18066