From a4c0be8617d22dfa47bdd9e104baf0f4bcc94a25 Mon Sep 17 00:00:00 2001 From: Mark Tompsett Date: Tue, 7 Nov 2017 03:21:36 +0000 Subject: [PATCH] Bug 17770: Improve perlcritic level before patch: perlcritic -4 noisy after patch: perlcritic -4 ok Signed-off-by: Your Full Name Signed-off-by: Jon Knight Signed-off-by: Kyle M Hall --- t/db_dependent/Sitemapper.t | 57 +++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/t/db_dependent/Sitemapper.t b/t/db_dependent/Sitemapper.t index 4c5e741..3dc9b48 100755 --- a/t/db_dependent/Sitemapper.t +++ b/t/db_dependent/Sitemapper.t @@ -24,7 +24,7 @@ use DateTime; use Test::MockModule; use Test::More tests => 16; use Koha::Schema; - +use Carp qw/croak carp/; BEGIN { use_ok('Koha::Sitemapper'); @@ -37,7 +37,7 @@ $mocked_datetime->mock('now', sub { return $now_value; } ); sub slurp { my $file = shift; - open my $fh, '<', $file or die; + open my $fh, '<', $file or croak; local $/ = undef; my $cont = <$fh>; close $fh; @@ -51,9 +51,10 @@ sub fixtures { 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 @@ -81,10 +82,10 @@ my $sitemapper = Koha::Sitemapper->new( $sitemapper->run(); my $file = "$dir/sitemapindex.xml"; -ok( -e "$dir/sitemapindex.xml", "File sitemapindex.xml created"); +ok( -e "$dir/sitemapindex.xml", 'File sitemapindex.xml created'); my $file_content = slurp($file); my $now = DateTime->now->ymd; -my $expected_content = < @@ -95,12 +96,12 @@ my $expected_content = < 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'); $file_content = slurp($file); -$expected_content = < @@ -114,7 +115,7 @@ $expected_content = < 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'. @@ -128,9 +129,9 @@ $sitemapper = Koha::Sitemapper->new( $sitemapper->run(); $file = "$dir/sitemap0001.xml"; -ok( -e $file, "File sitemap0001.xml with short URLs created"); +ok( -e $file, 'File sitemap0001.xml with short URLs created'); $file_content = slurp($file); -$expected_content = < @@ -144,14 +145,16 @@ $expected_content = < 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, @@ -162,9 +165,9 @@ $sitemapper = Koha::Sitemapper->new( $sitemapper->run(); $file = "$dir/sitemapindex.xml"; -ok( -e "$dir/sitemapindex.xml", "File sitemapindex.xml for 75000 bibs created"); +ok( -e "$dir/sitemapindex.xml", 'File sitemapindex.xml for 75000 bibs created'); $file_content = slurp($file); -$expected_content = < @@ -179,27 +182,31 @@ $expected_content = < 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 //; + if ($_ =~ //xsm) { $count++; } } -is( $count, 50000, "It contains 50000 URLs"); +close $fh; +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 //; + if ($_ =~ //xsm) { $count++; } } -is( $count, 25000, "It contains 25000 URLs"); +close $fh; +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.10.2