Bugzilla – Attachment 69930 Details for
Bug 17770
t/db_dependent/Sitemapper.t fails when date changes during test run
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17770: Perlcritic improvements
Bug-17770-Perlcritic-improvements.patch (text/plain), 6.20 KB, created by
Mark Tompsett
on 2017-12-19 19:56:35 UTC
(
hide
)
Description:
Bug 17770: Perlcritic improvements
Filename:
MIME Type:
Creator:
Mark Tompsett
Created:
2017-12-19 19:56:35 UTC
Size:
6.20 KB
patch
obsolete
>From 06eac48cae292db1b3af202234aeea8f5c744e24 Mon Sep 17 00:00:00 2001 >From: Mark Tompsett <mtompset@hotmail.com> >Date: Tue, 19 Dec 2017 14:51:27 -0500 >Subject: [PATCH] Bug 17770: Perlcritic improvements > >before patch: perlcritic -3 noisy >after patch: perlcritic -3 ok >--- > t/db_dependent/Sitemapper.t | 79 ++++++++++++++++++++++----------------------- > 1 file changed, 38 insertions(+), 41 deletions(-) > >diff --git a/t/db_dependent/Sitemapper.t b/t/db_dependent/Sitemapper.t >index 379538d..2f07dfa 100755 >--- a/t/db_dependent/Sitemapper.t >+++ b/t/db_dependent/Sitemapper.t >@@ -25,31 +25,23 @@ use Test::MockModule; > use Test::More tests => 16; > use Koha::Schema; > use t::lib::Dates; >- >+use Carp qw/croak carp/; >+use File::Slurp; >+use Test::DBIx::Class; > > t::lib::Dates::wait_till_midnight(1); > use_ok('Koha::Sitemapper'); > use_ok('Koha::Sitemapper::Writer'); > >-sub slurp { >- my $file = shift; >- open my $fh, '<', $file or die; >- local $/ = undef; >- my $cont = <$fh>; >- close $fh; >- return $cont; >-} >- >-use Test::DBIx::Class; >- > sub fixtures { > my ( $data ) = @_; > fixtures_ok [ > Biblio => [ > [ qw/ biblionumber datecreated timestamp / ], >- @$data, >+ @{$data}, > ], > ], 'add fixtures'; >+ return; > } > > # Make the code in the module use our mocked Koha::Schema/Koha::Database >@@ -61,12 +53,12 @@ $db->mock( > > my $dir = File::Spec->tmpdir(); > >- > my $data = [ > [ qw/ 1 2013-11-15 2013-11-15/ ], > [ qw/ 2 2015-08-31 2015-08-31/ ], > ]; > fixtures($data); >+ > # Create a sitemap for a catalog containg 2 biblios, with option 'long url' > my $sitemapper = Koha::Sitemapper->new( > verbose => 0, >@@ -77,10 +69,10 @@ my $sitemapper = Koha::Sitemapper->new( > $sitemapper->run(); > > my $file = "$dir/sitemapindex.xml"; >-ok( -e "$dir/sitemapindex.xml", "File sitemapindex.xml created"); >-my $file_content = slurp($file); >+ok( -e "$dir/sitemapindex.xml", 'File sitemapindex.xml created'); >+my $file_content = read_file($file); > my $now = DateTime->now->ymd; >-my $expected_content = <<EOS; >+my $expected_content = <<"EOS"; > <?xml version="1.0" encoding="UTF-8"?> > > <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> >@@ -91,12 +83,12 @@ my $expected_content = <<EOS; > </sitemapindex> > EOS > chop $expected_content; >-is( $file_content, $expected_content, "Its content is valid" ); >+is( $file_content, $expected_content, 'Its content is valid' ); > > $file = "$dir/sitemap0001.xml"; >-ok( -e $file, "File sitemap0001.xml created"); >-$file_content = slurp($file); >-$expected_content = <<EOS; >+ok( -e $file, 'File sitemap0001.xml created'); >+$file_content = read_file($file); >+$expected_content = <<"EOS"; > <?xml version="1.0" encoding="UTF-8"?> > > <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"> >@@ -110,7 +102,7 @@ $expected_content = <<EOS; > </url> > </urlset> > EOS >-is( $file_content, $expected_content, "Its content is valid" ); >+is( $file_content, $expected_content, 'Its content is valid' ); > > > # Create a sitemap for a catalog containg 2 biblios, with option 'short url'. >@@ -124,9 +116,9 @@ $sitemapper = Koha::Sitemapper->new( > $sitemapper->run(); > > $file = "$dir/sitemap0001.xml"; >-ok( -e $file, "File sitemap0001.xml with short URLs created"); >-$file_content = slurp($file); >-$expected_content = <<EOS; >+ok( -e $file, 'File sitemap0001.xml with short URLs created'); >+$file_content = read_file($file); >+$expected_content = <<"EOS"; > <?xml version="1.0" encoding="UTF-8"?> > > <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"> >@@ -140,14 +132,15 @@ $expected_content = <<EOS; > </url> > </urlset> > EOS >-is( $file_content, $expected_content, "Its content is valid" ); >- >+is( $file_content, $expected_content, 'Its content is valid' ); > > # Create a sitemap for a catalog containing 75000 biblios, with option 'short > # url'. Test that 3 files are created: index file + 2 urls file with > # respectively 50000 et 25000 urls. > $data = []; >-push @$data, [ $_, '2015-08-31', '2015-08-31'] for 3..75000; >+for my $count (3..75_000) { >+ push @{$data}, [ $count, '2015-08-31', '2015-08-31']; >+} > fixtures($data); > $sitemapper = Koha::Sitemapper->new( > verbose => 0, >@@ -158,9 +151,9 @@ $sitemapper = Koha::Sitemapper->new( > $sitemapper->run(); > > $file = "$dir/sitemapindex.xml"; >-ok( -e "$dir/sitemapindex.xml", "File sitemapindex.xml for 75000 bibs created"); >-$file_content = slurp($file); >-$expected_content = <<EOS; >+ok( -e "$dir/sitemapindex.xml", 'File sitemapindex.xml for 75000 bibs created'); >+$file_content = read_file($file); >+$expected_content = <<"EOS"; > <?xml version="1.0" encoding="UTF-8"?> > > <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> >@@ -175,27 +168,31 @@ $expected_content = <<EOS; > </sitemapindex> > EOS > chop $expected_content; >-is( $file_content, $expected_content, "Its content is valid" ); >+is( $file_content, $expected_content, 'Its content is valid' ); > > $file = "$dir/sitemap0001.xml"; >-ok( -e $file, "File sitemap0001.xml created"); >+ok( -e $file, 'File sitemap0001.xml created'); > >-open my $fh, "<", $file; >+open my $fh, '<', $file or croak; > my $count = 0; > while (<$fh>) { >- $count++ if /<loc>/; >+ if (/<loc>/xsm) { $count++; } > } >-is( $count, 50000, "It contains 50000 URLs"); >+close $fh or carp "Failed to close $file well."; >+is( $count, 50_000, 'It contains 50000 URLs'); > > $file = "$dir/sitemap0002.xml"; >-ok( -e $file, "File sitemap0002.xml created"); >+ok( -e $file, 'File sitemap0002.xml created'); > >-open $fh, "<", $file; >+open $fh, '<', $file or croak; > $count = 0; > while (<$fh>) { >- $count++ if /<loc>/; >+ if (/<loc>/xsm) { $count++; } > } >-is( $count, 25000, "It contains 25000 URLs"); >+close $fh or carp "Failed to close $file well."; >+is( $count, 25_000, 'It contains 25000 URLs'); > > # Cleanup >-unlink "$dir/$_" for qw / sitemapindex.xml sitemap0001.xml sitemap0002.xml /; >+for my $file (qw/sitemapindex.xml sitemap0001.xml sitemap0002.xml/) { >+ unlink "$dir/$file"; >+} >-- >2.1.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 17770
:
68994
|
68995
|
68996
|
69741
|
69742
|
69743
|
69929
|
69930
|
69931
|
70005
|
70006
|
70007