|
Lines 25-55
use Test::MockModule;
Link Here
|
| 25 |
use Test::More tests => 16; |
25 |
use Test::More tests => 16; |
| 26 |
use Koha::Schema; |
26 |
use Koha::Schema; |
| 27 |
use t::lib::Dates; |
27 |
use t::lib::Dates; |
| 28 |
|
28 |
use Carp qw/croak carp/; |
|
|
29 |
use File::Slurp; |
| 30 |
use Test::DBIx::Class; |
| 29 |
|
31 |
|
| 30 |
t::lib::Dates::wait_till_midnight(1); |
32 |
t::lib::Dates::wait_till_midnight(1); |
| 31 |
use_ok('Koha::Sitemapper'); |
33 |
use_ok('Koha::Sitemapper'); |
| 32 |
use_ok('Koha::Sitemapper::Writer'); |
34 |
use_ok('Koha::Sitemapper::Writer'); |
| 33 |
|
35 |
|
| 34 |
sub slurp { |
|
|
| 35 |
my $file = shift; |
| 36 |
open my $fh, '<', $file or die; |
| 37 |
local $/ = undef; |
| 38 |
my $cont = <$fh>; |
| 39 |
close $fh; |
| 40 |
return $cont; |
| 41 |
} |
| 42 |
|
| 43 |
use Test::DBIx::Class; |
| 44 |
|
| 45 |
sub fixtures { |
36 |
sub fixtures { |
| 46 |
my ( $data ) = @_; |
37 |
my ( $data ) = @_; |
| 47 |
fixtures_ok [ |
38 |
fixtures_ok [ |
| 48 |
Biblio => [ |
39 |
Biblio => [ |
| 49 |
[ qw/ biblionumber datecreated timestamp / ], |
40 |
[ qw/ biblionumber datecreated timestamp / ], |
| 50 |
@$data, |
41 |
@{$data}, |
| 51 |
], |
42 |
], |
| 52 |
], 'add fixtures'; |
43 |
], 'add fixtures'; |
|
|
44 |
return; |
| 53 |
} |
45 |
} |
| 54 |
|
46 |
|
| 55 |
# Make the code in the module use our mocked Koha::Schema/Koha::Database |
47 |
# Make the code in the module use our mocked Koha::Schema/Koha::Database |
|
Lines 61-72
$db->mock(
Link Here
|
| 61 |
|
53 |
|
| 62 |
my $dir = File::Spec->tmpdir(); |
54 |
my $dir = File::Spec->tmpdir(); |
| 63 |
|
55 |
|
| 64 |
|
|
|
| 65 |
my $data = [ |
56 |
my $data = [ |
| 66 |
[ qw/ 1 2013-11-15 2013-11-15/ ], |
57 |
[ qw/ 1 2013-11-15 2013-11-15/ ], |
| 67 |
[ qw/ 2 2015-08-31 2015-08-31/ ], |
58 |
[ qw/ 2 2015-08-31 2015-08-31/ ], |
| 68 |
]; |
59 |
]; |
| 69 |
fixtures($data); |
60 |
fixtures($data); |
|
|
61 |
|
| 70 |
# Create a sitemap for a catalog containg 2 biblios, with option 'long url' |
62 |
# Create a sitemap for a catalog containg 2 biblios, with option 'long url' |
| 71 |
my $sitemapper = Koha::Sitemapper->new( |
63 |
my $sitemapper = Koha::Sitemapper->new( |
| 72 |
verbose => 0, |
64 |
verbose => 0, |
|
Lines 77-86
my $sitemapper = Koha::Sitemapper->new(
Link Here
|
| 77 |
$sitemapper->run(); |
69 |
$sitemapper->run(); |
| 78 |
|
70 |
|
| 79 |
my $file = "$dir/sitemapindex.xml"; |
71 |
my $file = "$dir/sitemapindex.xml"; |
| 80 |
ok( -e "$dir/sitemapindex.xml", "File sitemapindex.xml created"); |
72 |
ok( -e "$dir/sitemapindex.xml", 'File sitemapindex.xml created'); |
| 81 |
my $file_content = slurp($file); |
73 |
my $file_content = read_file($file); |
| 82 |
my $now = DateTime->now->ymd; |
74 |
my $now = DateTime->now->ymd; |
| 83 |
my $expected_content = <<EOS; |
75 |
my $expected_content = <<"EOS"; |
| 84 |
<?xml version="1.0" encoding="UTF-8"?> |
76 |
<?xml version="1.0" encoding="UTF-8"?> |
| 85 |
|
77 |
|
| 86 |
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> |
78 |
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> |
|
Lines 91-102
my $expected_content = <<EOS;
Link Here
|
| 91 |
</sitemapindex> |
83 |
</sitemapindex> |
| 92 |
EOS |
84 |
EOS |
| 93 |
chop $expected_content; |
85 |
chop $expected_content; |
| 94 |
is( $file_content, $expected_content, "Its content is valid" ); |
86 |
is( $file_content, $expected_content, 'Its content is valid' ); |
| 95 |
|
87 |
|
| 96 |
$file = "$dir/sitemap0001.xml"; |
88 |
$file = "$dir/sitemap0001.xml"; |
| 97 |
ok( -e $file, "File sitemap0001.xml created"); |
89 |
ok( -e $file, 'File sitemap0001.xml created'); |
| 98 |
$file_content = slurp($file); |
90 |
$file_content = read_file($file); |
| 99 |
$expected_content = <<EOS; |
91 |
$expected_content = <<"EOS"; |
| 100 |
<?xml version="1.0" encoding="UTF-8"?> |
92 |
<?xml version="1.0" encoding="UTF-8"?> |
| 101 |
|
93 |
|
| 102 |
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"> |
94 |
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"> |
|
Lines 110-116
$expected_content = <<EOS;
Link Here
|
| 110 |
</url> |
102 |
</url> |
| 111 |
</urlset> |
103 |
</urlset> |
| 112 |
EOS |
104 |
EOS |
| 113 |
is( $file_content, $expected_content, "Its content is valid" ); |
105 |
is( $file_content, $expected_content, 'Its content is valid' ); |
| 114 |
|
106 |
|
| 115 |
|
107 |
|
| 116 |
# Create a sitemap for a catalog containg 2 biblios, with option 'short url'. |
108 |
# Create a sitemap for a catalog containg 2 biblios, with option 'short url'. |
|
Lines 124-132
$sitemapper = Koha::Sitemapper->new(
Link Here
|
| 124 |
$sitemapper->run(); |
116 |
$sitemapper->run(); |
| 125 |
|
117 |
|
| 126 |
$file = "$dir/sitemap0001.xml"; |
118 |
$file = "$dir/sitemap0001.xml"; |
| 127 |
ok( -e $file, "File sitemap0001.xml with short URLs created"); |
119 |
ok( -e $file, 'File sitemap0001.xml with short URLs created'); |
| 128 |
$file_content = slurp($file); |
120 |
$file_content = read_file($file); |
| 129 |
$expected_content = <<EOS; |
121 |
$expected_content = <<"EOS"; |
| 130 |
<?xml version="1.0" encoding="UTF-8"?> |
122 |
<?xml version="1.0" encoding="UTF-8"?> |
| 131 |
|
123 |
|
| 132 |
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"> |
124 |
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"> |
|
Lines 140-153
$expected_content = <<EOS;
Link Here
|
| 140 |
</url> |
132 |
</url> |
| 141 |
</urlset> |
133 |
</urlset> |
| 142 |
EOS |
134 |
EOS |
| 143 |
is( $file_content, $expected_content, "Its content is valid" ); |
135 |
is( $file_content, $expected_content, 'Its content is valid' ); |
| 144 |
|
|
|
| 145 |
|
136 |
|
| 146 |
# Create a sitemap for a catalog containing 75000 biblios, with option 'short |
137 |
# Create a sitemap for a catalog containing 75000 biblios, with option 'short |
| 147 |
# url'. Test that 3 files are created: index file + 2 urls file with |
138 |
# url'. Test that 3 files are created: index file + 2 urls file with |
| 148 |
# respectively 50000 et 25000 urls. |
139 |
# respectively 50000 et 25000 urls. |
| 149 |
$data = []; |
140 |
$data = []; |
| 150 |
push @$data, [ $_, '2015-08-31', '2015-08-31'] for 3..75000; |
141 |
for my $count (3..75_000) { |
|
|
142 |
push @{$data}, [ $count, '2015-08-31', '2015-08-31']; |
| 143 |
} |
| 151 |
fixtures($data); |
144 |
fixtures($data); |
| 152 |
$sitemapper = Koha::Sitemapper->new( |
145 |
$sitemapper = Koha::Sitemapper->new( |
| 153 |
verbose => 0, |
146 |
verbose => 0, |
|
Lines 158-166
$sitemapper = Koha::Sitemapper->new(
Link Here
|
| 158 |
$sitemapper->run(); |
151 |
$sitemapper->run(); |
| 159 |
|
152 |
|
| 160 |
$file = "$dir/sitemapindex.xml"; |
153 |
$file = "$dir/sitemapindex.xml"; |
| 161 |
ok( -e "$dir/sitemapindex.xml", "File sitemapindex.xml for 75000 bibs created"); |
154 |
ok( -e "$dir/sitemapindex.xml", 'File sitemapindex.xml for 75000 bibs created'); |
| 162 |
$file_content = slurp($file); |
155 |
$file_content = read_file($file); |
| 163 |
$expected_content = <<EOS; |
156 |
$expected_content = <<"EOS"; |
| 164 |
<?xml version="1.0" encoding="UTF-8"?> |
157 |
<?xml version="1.0" encoding="UTF-8"?> |
| 165 |
|
158 |
|
| 166 |
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> |
159 |
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> |
|
Lines 175-201
$expected_content = <<EOS;
Link Here
|
| 175 |
</sitemapindex> |
168 |
</sitemapindex> |
| 176 |
EOS |
169 |
EOS |
| 177 |
chop $expected_content; |
170 |
chop $expected_content; |
| 178 |
is( $file_content, $expected_content, "Its content is valid" ); |
171 |
is( $file_content, $expected_content, 'Its content is valid' ); |
| 179 |
|
172 |
|
| 180 |
$file = "$dir/sitemap0001.xml"; |
173 |
$file = "$dir/sitemap0001.xml"; |
| 181 |
ok( -e $file, "File sitemap0001.xml created"); |
174 |
ok( -e $file, 'File sitemap0001.xml created'); |
| 182 |
|
175 |
|
| 183 |
open my $fh, "<", $file; |
176 |
open my $fh, '<', $file or croak; |
| 184 |
my $count = 0; |
177 |
my $count = 0; |
| 185 |
while (<$fh>) { |
178 |
while (<$fh>) { |
| 186 |
$count++ if /<loc>/; |
179 |
if (/<loc>/xsm) { $count++; } |
| 187 |
} |
180 |
} |
| 188 |
is( $count, 50000, "It contains 50000 URLs"); |
181 |
close $fh or carp "Failed to close $file well."; |
|
|
182 |
is( $count, 50_000, 'It contains 50000 URLs'); |
| 189 |
|
183 |
|
| 190 |
$file = "$dir/sitemap0002.xml"; |
184 |
$file = "$dir/sitemap0002.xml"; |
| 191 |
ok( -e $file, "File sitemap0002.xml created"); |
185 |
ok( -e $file, 'File sitemap0002.xml created'); |
| 192 |
|
186 |
|
| 193 |
open $fh, "<", $file; |
187 |
open $fh, '<', $file or croak; |
| 194 |
$count = 0; |
188 |
$count = 0; |
| 195 |
while (<$fh>) { |
189 |
while (<$fh>) { |
| 196 |
$count++ if /<loc>/; |
190 |
if (/<loc>/xsm) { $count++; } |
| 197 |
} |
191 |
} |
| 198 |
is( $count, 25000, "It contains 25000 URLs"); |
192 |
close $fh or carp "Failed to close $file well."; |
|
|
193 |
is( $count, 25_000, 'It contains 25000 URLs'); |
| 199 |
|
194 |
|
| 200 |
# Cleanup |
195 |
# Cleanup |
| 201 |
unlink "$dir/$_" for qw / sitemapindex.xml sitemap0001.xml sitemap0002.xml /; |
196 |
for my $file (qw/sitemapindex.xml sitemap0001.xml sitemap0002.xml/) { |
|
|
197 |
unlink "$dir/$file"; |
| 198 |
} |
| 202 |
- |
|
|