Lines 42-74
$schema->storage->txn_begin;
Link Here
|
42 |
subtest 'Sitemapper' => sub { |
42 |
subtest 'Sitemapper' => sub { |
43 |
plan tests => 12; |
43 |
plan tests => 12; |
44 |
|
44 |
|
45 |
my $now = dt_from_string()->ymd; |
45 |
my $now = dt_from_string()->ymd; |
46 |
|
46 |
|
47 |
# FIXME Would be nice to remove both deletes again |
47 |
# FIXME Would be nice to remove both deletes again |
48 |
Koha::Checkouts->delete; |
48 |
Koha::Checkouts->delete; |
49 |
Koha::Biblios->delete; |
49 |
Koha::Biblios->delete; |
50 |
my $biblio1 = $builder->build_sample_biblio; |
50 |
my $biblio1 = $builder->build_sample_biblio; |
51 |
$biblio1->set({ datecreated => '2013-11-15', timestamp => '2013-11-15' })->store; |
51 |
$biblio1->set( { datecreated => '2013-11-15', timestamp => '2013-11-15' } )->store; |
52 |
my $id1 = $biblio1->id; |
52 |
my $id1 = $biblio1->id; |
53 |
my $biblio2 = $builder->build_sample_biblio; |
53 |
my $biblio2 = $builder->build_sample_biblio; |
54 |
$biblio2->set({ datecreated => '2015-08-31', timestamp => '2015-08-31' })->store; |
54 |
$biblio2->set( { datecreated => '2015-08-31', timestamp => '2015-08-31' } )->store; |
55 |
my $id2 = $biblio2->id; |
55 |
my $id2 = $biblio2->id; |
56 |
|
56 |
|
57 |
my $dir = C4::Context::temporary_directory; |
57 |
my $dir = C4::Context::temporary_directory; |
58 |
|
58 |
|
59 |
# Create a sitemap for a catalog containg 2 biblios, with option 'long url' |
59 |
# Create a sitemap for a catalog containg 2 biblios, with option 'long url' |
60 |
my $sitemapper = Koha::Sitemapper->new( |
60 |
my $sitemapper = Koha::Sitemapper->new( |
61 |
verbose => 0, |
61 |
verbose => 0, |
62 |
url => 'http://www.mylibrary.org', |
62 |
url => 'http://www.mylibrary.org', |
63 |
dir => $dir, |
63 |
dir => $dir, |
64 |
short => 0, |
64 |
short => 0, |
65 |
); |
65 |
); |
66 |
$sitemapper->run(); |
66 |
$sitemapper->run(); |
67 |
|
67 |
|
68 |
my $file = "$dir/sitemapindex.xml"; |
68 |
my $file = "$dir/sitemapindex.xml"; |
69 |
ok( -e "$dir/sitemapindex.xml", 'File sitemapindex.xml created' ); |
69 |
ok( -e "$dir/sitemapindex.xml", 'File sitemapindex.xml created' ); |
70 |
my $file_content = read_file($file); |
70 |
my $file_content = read_file($file); |
71 |
my $expected_content = <<"EOS"; |
71 |
my $expected_content = <<"EOS"; |
72 |
<?xml version="1.0" encoding="UTF-8"?> |
72 |
<?xml version="1.0" encoding="UTF-8"?> |
73 |
|
73 |
|
74 |
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> |
74 |
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> |
Lines 78-90
my $expected_content = <<"EOS";
Link Here
|
78 |
</sitemap> |
78 |
</sitemap> |
79 |
</sitemapindex> |
79 |
</sitemapindex> |
80 |
EOS |
80 |
EOS |
81 |
chop $expected_content; |
81 |
chop $expected_content; |
82 |
is( $file_content, $expected_content, 'Its content is valid' ); |
82 |
is( $file_content, $expected_content, 'Its content is valid' ); |
83 |
|
83 |
|
84 |
$file = "$dir/sitemap0001.xml"; |
84 |
$file = "$dir/sitemap0001.xml"; |
85 |
ok( -e $file, 'File sitemap0001.xml created' ); |
85 |
ok( -e $file, 'File sitemap0001.xml created' ); |
86 |
$file_content = read_file($file); |
86 |
$file_content = read_file($file); |
87 |
$expected_content = <<"EOS"; |
87 |
$expected_content = <<"EOS"; |
88 |
<?xml version="1.0" encoding="UTF-8"?> |
88 |
<?xml version="1.0" encoding="UTF-8"?> |
89 |
|
89 |
|
90 |
<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"> |
90 |
<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 98-119
$expected_content = <<"EOS";
Link Here
|
98 |
</url> |
98 |
</url> |
99 |
</urlset> |
99 |
</urlset> |
100 |
EOS |
100 |
EOS |
101 |
is( $file_content, $expected_content, 'Its content is valid' ); |
101 |
is( $file_content, $expected_content, 'Its content is valid' ); |
102 |
|
102 |
|
103 |
# Create a sitemap for a catalog containg 2 biblios, with option 'short url'. |
103 |
# Create a sitemap for a catalog containg 2 biblios, with option 'short url'. |
104 |
# Test that 2 files are created. |
104 |
# Test that 2 files are created. |
105 |
$sitemapper = Koha::Sitemapper->new( |
105 |
$sitemapper = Koha::Sitemapper->new( |
106 |
verbose => 0, |
106 |
verbose => 0, |
107 |
url => 'http://www.mylibrary.org', |
107 |
url => 'http://www.mylibrary.org', |
108 |
dir => $dir, |
108 |
dir => $dir, |
109 |
short => 1, |
109 |
short => 1, |
110 |
); |
110 |
); |
111 |
$sitemapper->run(); |
111 |
$sitemapper->run(); |
112 |
|
112 |
|
113 |
$file = "$dir/sitemap0001.xml"; |
113 |
$file = "$dir/sitemap0001.xml"; |
114 |
ok( -e $file, 'File sitemap0001.xml with short URLs created' ); |
114 |
ok( -e $file, 'File sitemap0001.xml with short URLs created' ); |
115 |
$file_content = read_file($file); |
115 |
$file_content = read_file($file); |
116 |
$expected_content = <<"EOS"; |
116 |
$expected_content = <<"EOS"; |
117 |
<?xml version="1.0" encoding="UTF-8"?> |
117 |
<?xml version="1.0" encoding="UTF-8"?> |
118 |
|
118 |
|
119 |
<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"> |
119 |
<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 127-153
$expected_content = <<"EOS";
Link Here
|
127 |
</url> |
127 |
</url> |
128 |
</urlset> |
128 |
</urlset> |
129 |
EOS |
129 |
EOS |
130 |
is( $file_content, $expected_content, 'Its content is valid' ); |
130 |
is( $file_content, $expected_content, 'Its content is valid' ); |
131 |
|
131 |
|
132 |
# No need to create 75000 biblios here. Let's create 10 with $MAX == 6. |
132 |
# No need to create 75000 biblios here. Let's create 10 with $MAX == 6. |
133 |
# Expecting 3 files: index plus 2 url files with 6 and 4 urls. |
133 |
# Expecting 3 files: index plus 2 url files with 6 and 4 urls. |
134 |
$Koha::Sitemapper::Writer::MAX = 6; |
134 |
$Koha::Sitemapper::Writer::MAX = 6; |
135 |
for my $count ( 3..10 ) { |
135 |
for my $count ( 3 .. 10 ) { |
136 |
my $biblio2 = $builder->build_sample_biblio->set({ datecreated => '2015-08-31', timestamp => '2015-08-31' })->store; |
136 |
my $biblio2 = |
137 |
} |
137 |
$builder->build_sample_biblio->set( { datecreated => '2015-08-31', timestamp => '2015-08-31' } )->store; |
138 |
|
138 |
} |
139 |
$sitemapper = Koha::Sitemapper->new( |
139 |
|
140 |
verbose => 0, |
140 |
$sitemapper = Koha::Sitemapper->new( |
141 |
url => 'http://www.mylibrary.org', |
141 |
verbose => 0, |
142 |
dir => $dir, |
142 |
url => 'http://www.mylibrary.org', |
143 |
short => 1, |
143 |
dir => $dir, |
144 |
); |
144 |
short => 1, |
145 |
$sitemapper->run(); |
145 |
); |
146 |
|
146 |
$sitemapper->run(); |
147 |
$file = "$dir/sitemapindex.xml"; |
147 |
|
148 |
ok( -e "$dir/sitemapindex.xml", 'File sitemapindex.xml for 10 bibs created' ); |
148 |
$file = "$dir/sitemapindex.xml"; |
149 |
$file_content = read_file($file); |
149 |
ok( -e "$dir/sitemapindex.xml", 'File sitemapindex.xml for 10 bibs created' ); |
150 |
$expected_content = <<"EOS"; |
150 |
$file_content = read_file($file); |
|
|
151 |
$expected_content = <<"EOS"; |
151 |
<?xml version="1.0" encoding="UTF-8"?> |
152 |
<?xml version="1.0" encoding="UTF-8"?> |
152 |
|
153 |
|
153 |
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> |
154 |
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> |
Lines 161-194
$expected_content = <<"EOS";
Link Here
|
161 |
</sitemap> |
162 |
</sitemap> |
162 |
</sitemapindex> |
163 |
</sitemapindex> |
163 |
EOS |
164 |
EOS |
164 |
chop $expected_content; |
165 |
chop $expected_content; |
165 |
is( $file_content, $expected_content, 'Its content is valid' ); |
166 |
is( $file_content, $expected_content, 'Its content is valid' ); |
166 |
|
167 |
|
167 |
$file = "$dir/sitemap0001.xml"; |
168 |
$file = "$dir/sitemap0001.xml"; |
168 |
ok( -e $file, 'File sitemap0001.xml created' ); |
169 |
ok( -e $file, 'File sitemap0001.xml created' ); |
169 |
|
170 |
|
170 |
open my $fh, '<', $file or croak; |
171 |
open my $fh, '<', $file or croak; |
171 |
my $count = 0; |
172 |
my $count = 0; |
172 |
while (<$fh>) { |
173 |
while (<$fh>) { |
173 |
if ( $_ =~ /<loc>/xsm ) { $count++; } |
174 |
if ( $_ =~ /<loc>/xsm ) { $count++; } |
174 |
} |
175 |
} |
175 |
close $fh; |
176 |
close $fh; |
176 |
is( $count, 6, 'It contains 6 URLs' ); |
177 |
is( $count, 6, 'It contains 6 URLs' ); |
177 |
|
178 |
|
178 |
$file = "$dir/sitemap0002.xml"; |
179 |
$file = "$dir/sitemap0002.xml"; |
179 |
ok( -e $file, 'File sitemap0002.xml created' ); |
180 |
ok( -e $file, 'File sitemap0002.xml created' ); |
180 |
|
181 |
|
181 |
open $fh, '<', $file or croak; |
182 |
open $fh, '<', $file or croak; |
182 |
$count = 0; |
183 |
$count = 0; |
183 |
while (<$fh>) { |
184 |
while (<$fh>) { |
184 |
if ( $_ =~ /<loc>/xsm ) { $count++; } |
185 |
if ( $_ =~ /<loc>/xsm ) { $count++; } |
185 |
} |
186 |
} |
186 |
close $fh; |
187 |
close $fh; |
187 |
is( $count, 4, 'It contains 4 URLs' ); |
188 |
is( $count, 4, 'It contains 4 URLs' ); |
188 |
|
189 |
|
189 |
# Cleanup |
190 |
# Cleanup |
190 |
for my $file (qw/sitemapindex.xml sitemap0001.xml sitemap0002.xml/) { |
191 |
for my $file (qw/sitemapindex.xml sitemap0001.xml sitemap0002.xml/) { |
191 |
unlink "$dir/$file"; |
192 |
unlink "$dir/$file"; |
192 |
} |
193 |
} |
193 |
}; |
194 |
}; |
194 |
$schema->storage->txn_rollback; |
195 |
$schema->storage->txn_rollback; |
195 |
- |
|
|