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

(-)a/t/db_dependent/Sitemapper.t (-26 / +32 lines)
Lines 24-30 use DateTime; Link Here
24
use Test::MockModule;
24
use Test::MockModule;
25
use Test::More tests => 16;
25
use Test::More tests => 16;
26
use Koha::Schema;
26
use Koha::Schema;
27
27
use Carp qw/croak carp/;
28
28
29
BEGIN {
29
BEGIN {
30
    use_ok('Koha::Sitemapper');
30
    use_ok('Koha::Sitemapper');
Lines 37-43 $mocked_datetime->mock('now', sub { return $now_value; } ); Link Here
37
37
38
sub slurp {
38
sub slurp {
39
    my $file = shift;
39
    my $file = shift;
40
    open my $fh, '<', $file or die;
40
    open my $fh, '<', $file or croak;
41
    local $/ = undef;
41
    local $/ = undef;
42
    my $cont = <$fh>;
42
    my $cont = <$fh>;
43
    close $fh;
43
    close $fh;
Lines 51-59 sub fixtures { Link Here
51
    fixtures_ok [
51
    fixtures_ok [
52
        Biblio => [
52
        Biblio => [
53
            [ qw/ biblionumber datecreated timestamp  / ],
53
            [ qw/ biblionumber datecreated timestamp  / ],
54
            @$data,
54
            @{$data},
55
        ],
55
        ],
56
    ], 'add fixtures';
56
    ], 'add fixtures';
57
    return;
57
}
58
}
58
59
59
# Make the code in the module use our mocked Koha::Schema/Koha::Database
60
# Make the code in the module use our mocked Koha::Schema/Koha::Database
Lines 81-90 my $sitemapper = Koha::Sitemapper->new( Link Here
81
$sitemapper->run();
82
$sitemapper->run();
82
83
83
my $file = "$dir/sitemapindex.xml";
84
my $file = "$dir/sitemapindex.xml";
84
ok( -e "$dir/sitemapindex.xml", "File sitemapindex.xml created");
85
ok( -e "$dir/sitemapindex.xml", 'File sitemapindex.xml created');
85
my $file_content = slurp($file);
86
my $file_content = slurp($file);
86
my $now = DateTime->now->ymd;
87
my $now = DateTime->now->ymd;
87
my $expected_content = <<EOS;
88
my $expected_content = <<"EOS";
88
<?xml version="1.0" encoding="UTF-8"?>
89
<?xml version="1.0" encoding="UTF-8"?>
89
90
90
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
91
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
Lines 95-106 my $expected_content = <<EOS; Link Here
95
</sitemapindex>
96
</sitemapindex>
96
EOS
97
EOS
97
chop $expected_content;
98
chop $expected_content;
98
is( $file_content, $expected_content, "Its content is valid" );
99
is( $file_content, $expected_content, 'Its content is valid' );
99
100
100
$file = "$dir/sitemap0001.xml";
101
$file = "$dir/sitemap0001.xml";
101
ok( -e $file, "File sitemap0001.xml created");
102
ok( -e $file, 'File sitemap0001.xml created');
102
$file_content = slurp($file);
103
$file_content = slurp($file);
103
$expected_content = <<EOS;
104
$expected_content = <<"EOS";
104
<?xml version="1.0" encoding="UTF-8"?>
105
<?xml version="1.0" encoding="UTF-8"?>
105
106
106
<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">
107
<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 114-120 $expected_content = <<EOS; Link Here
114
  </url>
115
  </url>
115
</urlset>
116
</urlset>
116
EOS
117
EOS
117
is( $file_content, $expected_content, "Its content is valid" );
118
is( $file_content, $expected_content, 'Its content is valid' );
118
119
119
120
120
# Create a sitemap for a catalog containg 2 biblios, with option 'short url'.
121
# Create a sitemap for a catalog containg 2 biblios, with option 'short url'.
Lines 128-136 $sitemapper = Koha::Sitemapper->new( Link Here
128
$sitemapper->run();
129
$sitemapper->run();
129
130
130
$file = "$dir/sitemap0001.xml";
131
$file = "$dir/sitemap0001.xml";
131
ok( -e $file, "File sitemap0001.xml with short URLs created");
132
ok( -e $file, 'File sitemap0001.xml with short URLs created');
132
$file_content = slurp($file);
133
$file_content = slurp($file);
133
$expected_content = <<EOS;
134
$expected_content = <<"EOS";
134
<?xml version="1.0" encoding="UTF-8"?>
135
<?xml version="1.0" encoding="UTF-8"?>
135
136
136
<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">
137
<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 144-157 $expected_content = <<EOS; Link Here
144
  </url>
145
  </url>
145
</urlset>
146
</urlset>
146
EOS
147
EOS
147
is( $file_content, $expected_content, "Its content is valid" );
148
is( $file_content, $expected_content, 'Its content is valid' );
148
149
149
150
150
# Create a sitemap for a catalog containing 75000 biblios, with option 'short
151
# Create a sitemap for a catalog containing 75000 biblios, with option 'short
151
# url'. Test that 3 files are created: index file + 2 urls file with
152
# url'. Test that 3 files are created: index file + 2 urls file with
152
# respectively 50000 et 25000 urls.
153
# respectively 50000 et 25000 urls.
153
$data = [];
154
$data = [];
154
push @$data, [ $_, '2015-08-31', '2015-08-31'] for 3..75000;
155
for my $count (3..75_000) {
156
    push @{$data}, [ $count, '2015-08-31', '2015-08-31'];
157
}
155
fixtures($data);
158
fixtures($data);
156
$sitemapper = Koha::Sitemapper->new(
159
$sitemapper = Koha::Sitemapper->new(
157
    verbose => 0,
160
    verbose => 0,
Lines 162-170 $sitemapper = Koha::Sitemapper->new( Link Here
162
$sitemapper->run();
165
$sitemapper->run();
163
166
164
$file = "$dir/sitemapindex.xml";
167
$file = "$dir/sitemapindex.xml";
165
ok( -e "$dir/sitemapindex.xml", "File sitemapindex.xml for 75000 bibs created");
168
ok( -e "$dir/sitemapindex.xml", 'File sitemapindex.xml for 75000 bibs created');
166
$file_content = slurp($file);
169
$file_content = slurp($file);
167
$expected_content = <<EOS;
170
$expected_content = <<"EOS";
168
<?xml version="1.0" encoding="UTF-8"?>
171
<?xml version="1.0" encoding="UTF-8"?>
169
172
170
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
173
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
Lines 179-205 $expected_content = <<EOS; Link Here
179
</sitemapindex>
182
</sitemapindex>
180
EOS
183
EOS
181
chop $expected_content;
184
chop $expected_content;
182
is( $file_content, $expected_content, "Its content is valid" );
185
is( $file_content, $expected_content, 'Its content is valid' );
183
186
184
$file = "$dir/sitemap0001.xml";
187
$file = "$dir/sitemap0001.xml";
185
ok( -e $file, "File sitemap0001.xml created");
188
ok( -e $file, 'File sitemap0001.xml created');
186
189
187
open my $fh, "<", $file;
190
open my $fh, '<', $file or croak;
188
my $count = 0;
191
my $count = 0;
189
while (<$fh>) {
192
while (<$fh>) {
190
	$count++ if /<loc>/;
193
    if ($_ =~ /<loc>/xsm) { $count++; }
191
}
194
}
192
is( $count, 50000, "It contains 50000 URLs");
195
close $fh;
196
is( $count, 50_000, 'It contains 50000 URLs');
193
197
194
$file = "$dir/sitemap0002.xml";
198
$file = "$dir/sitemap0002.xml";
195
ok( -e $file, "File sitemap0002.xml created");
199
ok( -e $file, 'File sitemap0002.xml created');
196
200
197
open $fh, "<", $file;
201
open $fh, '<', $file or croak;
198
$count = 0;
202
$count = 0;
199
while (<$fh>) {
203
while (<$fh>) {
200
	$count++ if /<loc>/;
204
    if ($_ =~ /<loc>/xsm) { $count++; }
201
}
205
}
202
is( $count, 25000, "It contains 25000 URLs");
206
close $fh;
207
is( $count, 25_000, 'It contains 25000 URLs');
203
208
204
# Cleanup
209
# Cleanup
205
unlink "$dir/$_" for qw / sitemapindex.xml sitemap0001.xml sitemap0002.xml /;
210
for my $file (qw/sitemapindex.xml sitemap0001.xml sitemap0002.xml/) {
211
    unlink "$dir/$file";
212
}
206
- 

Return to bug 17770