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

(-)a/t/db_dependent/Sitemapper.t (-24 / +21 lines)
Lines 34-45 use_ok('Koha::Sitemapper'); Link Here
34
use_ok('Koha::Sitemapper::Writer');
34
use_ok('Koha::Sitemapper::Writer');
35
35
36
sub fixtures {
36
sub fixtures {
37
    my ( $data ) = @_;
37
    my ($data) = @_;
38
    fixtures_ok [
38
    fixtures_ok [
39
        Biblio => [
39
        Biblio => [ [qw/ biblionumber datecreated timestamp  /], @{$data}, ],
40
            [ qw/ biblionumber datecreated timestamp  / ],
41
            @{$data},
42
        ],
43
    ], 'add fixtures';
40
    ], 'add fixtures';
44
    return;
41
    return;
45
}
42
}
Lines 47-52 sub fixtures { Link Here
47
# Make the code in the module use our mocked Koha::Schema/Koha::Database
44
# Make the code in the module use our mocked Koha::Schema/Koha::Database
48
my $db = Test::MockModule->new('Koha::Database');
45
my $db = Test::MockModule->new('Koha::Database');
49
$db->mock(
46
$db->mock(
47
50
    # Schema() gives us the DB connection set up by Test::DBIx::Class
48
    # Schema() gives us the DB connection set up by Test::DBIx::Class
51
    _new_schema => sub { return Schema(); }
49
    _new_schema => sub { return Schema(); }
52
);
50
);
Lines 54-61 $db->mock( Link Here
54
my $dir = File::Spec->tmpdir();
52
my $dir = File::Spec->tmpdir();
55
53
56
my $data = [
54
my $data = [
57
    [ qw/ 1         2013-11-15 2013-11-15/ ],
55
    [qw/ 1         2013-11-15 2013-11-15/],
58
    [ qw/ 2         2015-08-31 2015-08-31/ ],
56
    [qw/ 2         2015-08-31 2015-08-31/],
59
];
57
];
60
fixtures($data);
58
fixtures($data);
61
59
Lines 69-77 my $sitemapper = Koha::Sitemapper->new( Link Here
69
$sitemapper->run();
67
$sitemapper->run();
70
68
71
my $file = "$dir/sitemapindex.xml";
69
my $file = "$dir/sitemapindex.xml";
72
ok( -e "$dir/sitemapindex.xml", 'File sitemapindex.xml created');
70
ok( -e "$dir/sitemapindex.xml", 'File sitemapindex.xml created' );
73
my $file_content = read_file($file);
71
my $file_content     = read_file($file);
74
my $now = DateTime->now->ymd;
72
my $now              = DateTime->now->ymd;
75
my $expected_content = <<"EOS";
73
my $expected_content = <<"EOS";
76
<?xml version="1.0" encoding="UTF-8"?>
74
<?xml version="1.0" encoding="UTF-8"?>
77
75
Lines 86-93 chop $expected_content; Link Here
86
is( $file_content, $expected_content, 'Its content is valid' );
84
is( $file_content, $expected_content, 'Its content is valid' );
87
85
88
$file = "$dir/sitemap0001.xml";
86
$file = "$dir/sitemap0001.xml";
89
ok( -e $file, 'File sitemap0001.xml created');
87
ok( -e $file, 'File sitemap0001.xml created' );
90
$file_content = read_file($file);
88
$file_content     = read_file($file);
91
$expected_content = <<"EOS";
89
$expected_content = <<"EOS";
92
<?xml version="1.0" encoding="UTF-8"?>
90
<?xml version="1.0" encoding="UTF-8"?>
93
91
Lines 104-110 $expected_content = <<"EOS"; Link Here
104
EOS
102
EOS
105
is( $file_content, $expected_content, 'Its content is valid' );
103
is( $file_content, $expected_content, 'Its content is valid' );
106
104
107
108
# Create a sitemap for a catalog containg 2 biblios, with option 'short url'.
105
# Create a sitemap for a catalog containg 2 biblios, with option 'short url'.
109
# Test that 2 files are created.
106
# Test that 2 files are created.
110
$sitemapper = Koha::Sitemapper->new(
107
$sitemapper = Koha::Sitemapper->new(
Lines 116-123 $sitemapper = Koha::Sitemapper->new( Link Here
116
$sitemapper->run();
113
$sitemapper->run();
117
114
118
$file = "$dir/sitemap0001.xml";
115
$file = "$dir/sitemap0001.xml";
119
ok( -e $file, 'File sitemap0001.xml with short URLs created');
116
ok( -e $file, 'File sitemap0001.xml with short URLs created' );
120
$file_content = read_file($file);
117
$file_content     = read_file($file);
121
$expected_content = <<"EOS";
118
$expected_content = <<"EOS";
122
<?xml version="1.0" encoding="UTF-8"?>
119
<?xml version="1.0" encoding="UTF-8"?>
123
120
Lines 138-145 is( $file_content, $expected_content, 'Its content is valid' ); Link Here
138
# url'. Test that 3 files are created: index file + 2 urls file with
135
# url'. Test that 3 files are created: index file + 2 urls file with
139
# respectively 50000 et 25000 urls.
136
# respectively 50000 et 25000 urls.
140
$data = [];
137
$data = [];
141
for my $count (3..75_000) {
138
for my $count ( 3 .. 75_000 ) {
142
    push @{$data}, [ $count, '2015-08-31', '2015-08-31'];
139
    push @{$data}, [ $count, '2015-08-31', '2015-08-31' ];
143
}
140
}
144
fixtures($data);
141
fixtures($data);
145
$sitemapper = Koha::Sitemapper->new(
142
$sitemapper = Koha::Sitemapper->new(
Lines 151-158 $sitemapper = Koha::Sitemapper->new( Link Here
151
$sitemapper->run();
148
$sitemapper->run();
152
149
153
$file = "$dir/sitemapindex.xml";
150
$file = "$dir/sitemapindex.xml";
154
ok( -e "$dir/sitemapindex.xml", 'File sitemapindex.xml for 75000 bibs created');
151
ok( -e "$dir/sitemapindex.xml",
155
$file_content = read_file($file);
152
    'File sitemapindex.xml for 75000 bibs created' );
153
$file_content     = read_file($file);
156
$expected_content = <<"EOS";
154
$expected_content = <<"EOS";
157
<?xml version="1.0" encoding="UTF-8"?>
155
<?xml version="1.0" encoding="UTF-8"?>
158
156
Lines 171-177 chop $expected_content; Link Here
171
is( $file_content, $expected_content, 'Its content is valid' );
169
is( $file_content, $expected_content, 'Its content is valid' );
172
170
173
$file = "$dir/sitemap0001.xml";
171
$file = "$dir/sitemap0001.xml";
174
ok( -e $file, 'File sitemap0001.xml created');
172
ok( -e $file, 'File sitemap0001.xml created' );
175
173
176
open my $fh, '<', $file or croak;
174
open my $fh, '<', $file or croak;
177
my $count = 0;
175
my $count = 0;
Lines 179-188 while (<$fh>) { Link Here
179
    if (/<loc>/xsm) { $count++; }
177
    if (/<loc>/xsm) { $count++; }
180
}
178
}
181
close $fh or carp "Failed to close $file well.";
179
close $fh or carp "Failed to close $file well.";
182
is( $count, 50_000, 'It contains 50000 URLs');
180
is( $count, 50_000, 'It contains 50000 URLs' );
183
181
184
$file = "$dir/sitemap0002.xml";
182
$file = "$dir/sitemap0002.xml";
185
ok( -e $file, 'File sitemap0002.xml created');
183
ok( -e $file, 'File sitemap0002.xml created' );
186
184
187
open $fh, '<', $file or croak;
185
open $fh, '<', $file or croak;
188
$count = 0;
186
$count = 0;
Lines 190-196 while (<$fh>) { Link Here
190
    if (/<loc>/xsm) { $count++; }
188
    if (/<loc>/xsm) { $count++; }
191
}
189
}
192
close $fh or carp "Failed to close $file well.";
190
close $fh or carp "Failed to close $file well.";
193
is( $count, 25_000, 'It contains 25000 URLs');
191
is( $count, 25_000, 'It contains 25000 URLs' );
194
192
195
# Cleanup
193
# Cleanup
196
for my $file (qw/sitemapindex.xml sitemap0001.xml sitemap0002.xml/) {
194
for my $file (qw/sitemapindex.xml sitemap0001.xml sitemap0002.xml/) {
197
- 

Return to bug 17770