Lines 31-39
BEGIN {
Link Here
|
31 |
use_ok('Koha::Sitemapper::Writer'); |
31 |
use_ok('Koha::Sitemapper::Writer'); |
32 |
} |
32 |
} |
33 |
|
33 |
|
34 |
my $now_value = DateTime->now(); |
34 |
my $now_value = DateTime->now(); |
35 |
my $mocked_datetime = Test::MockModule->new('DateTime'); |
35 |
my $mocked_datetime = Test::MockModule->new('DateTime'); |
36 |
$mocked_datetime->mock('now', sub { return $now_value; } ); |
36 |
$mocked_datetime->mock( 'now', sub { return $now_value; } ); |
37 |
|
37 |
|
38 |
sub slurp { |
38 |
sub slurp { |
39 |
my $file = shift; |
39 |
my $file = shift; |
Lines 47-58
sub slurp {
Link Here
|
47 |
use Test::DBIx::Class; |
47 |
use Test::DBIx::Class; |
48 |
|
48 |
|
49 |
sub fixtures { |
49 |
sub fixtures { |
50 |
my ( $data ) = @_; |
50 |
my ($data) = @_; |
51 |
fixtures_ok [ |
51 |
fixtures_ok [ |
52 |
Biblio => [ |
52 |
Biblio => [ [qw/ biblionumber datecreated timestamp /], @{$data}, ], |
53 |
[ qw/ biblionumber datecreated timestamp / ], |
|
|
54 |
@{$data}, |
55 |
], |
56 |
], 'add fixtures'; |
53 |
], 'add fixtures'; |
57 |
return; |
54 |
return; |
58 |
} |
55 |
} |
Lines 60-77
sub fixtures {
Link Here
|
60 |
# Make the code in the module use our mocked Koha::Schema/Koha::Database |
57 |
# Make the code in the module use our mocked Koha::Schema/Koha::Database |
61 |
my $db = Test::MockModule->new('Koha::Database'); |
58 |
my $db = Test::MockModule->new('Koha::Database'); |
62 |
$db->mock( |
59 |
$db->mock( |
|
|
60 |
|
63 |
# Schema() gives us the DB connection set up by Test::DBIx::Class |
61 |
# Schema() gives us the DB connection set up by Test::DBIx::Class |
64 |
_new_schema => sub { return Schema(); } |
62 |
_new_schema => sub { return Schema(); } |
65 |
); |
63 |
); |
66 |
|
64 |
|
67 |
my $dir = File::Spec->tmpdir(); |
65 |
my $dir = File::Spec->tmpdir(); |
68 |
|
66 |
|
69 |
|
|
|
70 |
my $data = [ |
67 |
my $data = [ |
71 |
[ qw/ 1 2013-11-15 2013-11-15/ ], |
68 |
[qw/ 1 2013-11-15 2013-11-15/], |
72 |
[ qw/ 2 2015-08-31 2015-08-31/ ], |
69 |
[qw/ 2 2015-08-31 2015-08-31/], |
73 |
]; |
70 |
]; |
74 |
fixtures($data); |
71 |
fixtures($data); |
|
|
72 |
|
75 |
# Create a sitemap for a catalog containg 2 biblios, with option 'long url' |
73 |
# Create a sitemap for a catalog containg 2 biblios, with option 'long url' |
76 |
my $sitemapper = Koha::Sitemapper->new( |
74 |
my $sitemapper = Koha::Sitemapper->new( |
77 |
verbose => 0, |
75 |
verbose => 0, |
Lines 82-90
my $sitemapper = Koha::Sitemapper->new(
Link Here
|
82 |
$sitemapper->run(); |
80 |
$sitemapper->run(); |
83 |
|
81 |
|
84 |
my $file = "$dir/sitemapindex.xml"; |
82 |
my $file = "$dir/sitemapindex.xml"; |
85 |
ok( -e "$dir/sitemapindex.xml", 'File sitemapindex.xml created'); |
83 |
ok( -e "$dir/sitemapindex.xml", 'File sitemapindex.xml created' ); |
86 |
my $file_content = slurp($file); |
84 |
my $file_content = slurp($file); |
87 |
my $now = DateTime->now->ymd; |
85 |
my $now = DateTime->now->ymd; |
88 |
my $expected_content = <<"EOS"; |
86 |
my $expected_content = <<"EOS"; |
89 |
<?xml version="1.0" encoding="UTF-8"?> |
87 |
<?xml version="1.0" encoding="UTF-8"?> |
90 |
|
88 |
|
Lines 99-106
chop $expected_content;
Link Here
|
99 |
is( $file_content, $expected_content, 'Its content is valid' ); |
97 |
is( $file_content, $expected_content, 'Its content is valid' ); |
100 |
|
98 |
|
101 |
$file = "$dir/sitemap0001.xml"; |
99 |
$file = "$dir/sitemap0001.xml"; |
102 |
ok( -e $file, 'File sitemap0001.xml created'); |
100 |
ok( -e $file, 'File sitemap0001.xml created' ); |
103 |
$file_content = slurp($file); |
101 |
$file_content = slurp($file); |
104 |
$expected_content = <<"EOS"; |
102 |
$expected_content = <<"EOS"; |
105 |
<?xml version="1.0" encoding="UTF-8"?> |
103 |
<?xml version="1.0" encoding="UTF-8"?> |
106 |
|
104 |
|
Lines 117-123
$expected_content = <<"EOS";
Link Here
|
117 |
EOS |
115 |
EOS |
118 |
is( $file_content, $expected_content, 'Its content is valid' ); |
116 |
is( $file_content, $expected_content, 'Its content is valid' ); |
119 |
|
117 |
|
120 |
|
|
|
121 |
# Create a sitemap for a catalog containg 2 biblios, with option 'short url'. |
118 |
# Create a sitemap for a catalog containg 2 biblios, with option 'short url'. |
122 |
# Test that 2 files are created. |
119 |
# Test that 2 files are created. |
123 |
$sitemapper = Koha::Sitemapper->new( |
120 |
$sitemapper = Koha::Sitemapper->new( |
Lines 129-136
$sitemapper = Koha::Sitemapper->new(
Link Here
|
129 |
$sitemapper->run(); |
126 |
$sitemapper->run(); |
130 |
|
127 |
|
131 |
$file = "$dir/sitemap0001.xml"; |
128 |
$file = "$dir/sitemap0001.xml"; |
132 |
ok( -e $file, 'File sitemap0001.xml with short URLs created'); |
129 |
ok( -e $file, 'File sitemap0001.xml with short URLs created' ); |
133 |
$file_content = slurp($file); |
130 |
$file_content = slurp($file); |
134 |
$expected_content = <<"EOS"; |
131 |
$expected_content = <<"EOS"; |
135 |
<?xml version="1.0" encoding="UTF-8"?> |
132 |
<?xml version="1.0" encoding="UTF-8"?> |
136 |
|
133 |
|
Lines 147-159
$expected_content = <<"EOS";
Link Here
|
147 |
EOS |
144 |
EOS |
148 |
is( $file_content, $expected_content, 'Its content is valid' ); |
145 |
is( $file_content, $expected_content, 'Its content is valid' ); |
149 |
|
146 |
|
150 |
|
|
|
151 |
# Create a sitemap for a catalog containing 75000 biblios, with option 'short |
147 |
# Create a sitemap for a catalog containing 75000 biblios, with option 'short |
152 |
# url'. Test that 3 files are created: index file + 2 urls file with |
148 |
# url'. Test that 3 files are created: index file + 2 urls file with |
153 |
# respectively 50000 et 25000 urls. |
149 |
# respectively 50000 et 25000 urls. |
154 |
$data = []; |
150 |
$data = []; |
155 |
for my $count (3..75_000) { |
151 |
for my $count ( 3 .. 75_000 ) { |
156 |
push @{$data}, [ $count, '2015-08-31', '2015-08-31']; |
152 |
push @{$data}, [ $count, '2015-08-31', '2015-08-31' ]; |
157 |
} |
153 |
} |
158 |
fixtures($data); |
154 |
fixtures($data); |
159 |
$sitemapper = Koha::Sitemapper->new( |
155 |
$sitemapper = Koha::Sitemapper->new( |
Lines 165-172
$sitemapper = Koha::Sitemapper->new(
Link Here
|
165 |
$sitemapper->run(); |
161 |
$sitemapper->run(); |
166 |
|
162 |
|
167 |
$file = "$dir/sitemapindex.xml"; |
163 |
$file = "$dir/sitemapindex.xml"; |
168 |
ok( -e "$dir/sitemapindex.xml", 'File sitemapindex.xml for 75000 bibs created'); |
164 |
ok( -e "$dir/sitemapindex.xml", |
169 |
$file_content = slurp($file); |
165 |
'File sitemapindex.xml for 75000 bibs created' ); |
|
|
166 |
$file_content = slurp($file); |
170 |
$expected_content = <<"EOS"; |
167 |
$expected_content = <<"EOS"; |
171 |
<?xml version="1.0" encoding="UTF-8"?> |
168 |
<?xml version="1.0" encoding="UTF-8"?> |
172 |
|
169 |
|
Lines 185-210
chop $expected_content;
Link Here
|
185 |
is( $file_content, $expected_content, 'Its content is valid' ); |
182 |
is( $file_content, $expected_content, 'Its content is valid' ); |
186 |
|
183 |
|
187 |
$file = "$dir/sitemap0001.xml"; |
184 |
$file = "$dir/sitemap0001.xml"; |
188 |
ok( -e $file, 'File sitemap0001.xml created'); |
185 |
ok( -e $file, 'File sitemap0001.xml created' ); |
189 |
|
186 |
|
190 |
open my $fh, '<', $file or croak; |
187 |
open my $fh, '<', $file or croak; |
191 |
my $count = 0; |
188 |
my $count = 0; |
192 |
while (<$fh>) { |
189 |
while (<$fh>) { |
193 |
if ($_ =~ /<loc>/xsm) { $count++; } |
190 |
if ( $_ =~ /<loc>/xsm ) { $count++; } |
194 |
} |
191 |
} |
195 |
close $fh; |
192 |
close $fh; |
196 |
is( $count, 50_000, 'It contains 50000 URLs'); |
193 |
is( $count, 50_000, 'It contains 50000 URLs' ); |
197 |
|
194 |
|
198 |
$file = "$dir/sitemap0002.xml"; |
195 |
$file = "$dir/sitemap0002.xml"; |
199 |
ok( -e $file, 'File sitemap0002.xml created'); |
196 |
ok( -e $file, 'File sitemap0002.xml created' ); |
200 |
|
197 |
|
201 |
open $fh, '<', $file or croak; |
198 |
open $fh, '<', $file or croak; |
202 |
$count = 0; |
199 |
$count = 0; |
203 |
while (<$fh>) { |
200 |
while (<$fh>) { |
204 |
if ($_ =~ /<loc>/xsm) { $count++; } |
201 |
if ( $_ =~ /<loc>/xsm ) { $count++; } |
205 |
} |
202 |
} |
206 |
close $fh; |
203 |
close $fh; |
207 |
is( $count, 25_000, 'It contains 25000 URLs'); |
204 |
is( $count, 25_000, 'It contains 25000 URLs' ); |
208 |
|
205 |
|
209 |
# Cleanup |
206 |
# Cleanup |
210 |
for my $file (qw/sitemapindex.xml sitemap0001.xml sitemap0002.xml/) { |
207 |
for my $file (qw/sitemapindex.xml sitemap0001.xml sitemap0002.xml/) { |
211 |
- |
|
|