Bugzilla – Attachment 155095 Details for
Bug 33870
Remove T::D::C from Sitemapper.t
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 33870: Polishing Sitemapper.t
Bug-33870-Polishing-Sitemappert.patch (text/plain), 7.15 KB, created by
Jonathan Druart
on 2023-09-01 10:14:09 UTC
(
hide
)
Description:
Bug 33870: Polishing Sitemapper.t
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2023-09-01 10:14:09 UTC
Size:
7.15 KB
patch
obsolete
>From 9ea87cfb3c209fb174e2e489bfb341a1a3436768 Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Wed, 31 May 2023 07:18:17 +0000 >Subject: [PATCH] Bug 33870: Polishing Sitemapper.t > >Create subtest. >Remove (useless) mock on DateTime. >Remove T::D::C module, add TestBuilder. >Replace local slurp function by use File::Slurp. > >Test plan: >Run t/db_dependent/Sitemapper.t > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Signed-off-by: Pedro Amorim <pedro.amorim@ptfs-europe.com> > >Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >--- > t/db_dependent/Sitemapper.t | 114 ++++++++++++++++-------------------- > 1 file changed, 49 insertions(+), 65 deletions(-) > >diff --git a/t/db_dependent/Sitemapper.t b/t/db_dependent/Sitemapper.t >index ae3dbeba3fd..d1b36f1f725 100755 >--- a/t/db_dependent/Sitemapper.t >+++ b/t/db_dependent/Sitemapper.t >@@ -18,59 +18,44 @@ > # along with Koha; if not, see <http://www.gnu.org/licenses>. > > use Modern::Perl; >+use Test::More tests => 1; >+use Carp qw/croak/; > use File::Basename; > use File::Path; >-use DateTime; >-use Koha::DateUtils qw( dt_from_string ); >+use File::Slurp qw( read_file ); > use Test::MockModule; >-use Test::More tests => 16; >-use Carp qw/croak carp/; >- > >-BEGIN { >- use_ok('Koha::Sitemapper'); >- use_ok('Koha::Sitemapper::Writer'); >-} >+use t::lib::TestBuilder; >+use t::lib::Mocks; > >-my $now_value = dt_from_string(); >-my $mocked_datetime = Test::MockModule->new('DateTime'); >-$mocked_datetime->mock( 'now', sub { return $now_value->clone; } ); >- >-sub slurp { >- my $file = shift; >- open my $fh, '<', $file or croak; >- 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}, ], >- ], 'add fixtures'; >- return; >-} >- >-# Make the code in the module use our mocked Koha::Schema/Koha::Database >-my $db = Test::MockModule->new('Koha::Database'); >-$db->mock( >- >- # Schema() gives us the DB connection set up by Test::DBIx::Class >- _new_schema => sub { return Schema(); } >-); >+use Koha::Database; >+use Koha::DateUtils qw( dt_from_string ); >+use Koha::Biblios; >+use Koha::Checkouts; >+use Koha::Sitemapper; >+use Koha::Sitemapper::Writer; >+ >+my $schema = Koha::Database->new->schema; >+my $builder = t::lib::TestBuilder->new; >+$schema->storage->txn_begin; >+ >+subtest 'Sitemapper' => sub { >+ plan tests => 12; >+ >+my $now = dt_from_string()->ymd; >+ >+# FIXME Would be nice to remove both deletes again >+Koha::Checkouts->delete; >+Koha::Biblios->delete; >+my $biblio1 = $builder->build_sample_biblio; >+$biblio1->set({ datecreated => '2013-11-15', timestamp => '2013-11-15' })->store; >+my $id1 = $biblio1->id; >+my $biblio2 = $builder->build_sample_biblio; >+$biblio2->set({ datecreated => '2015-08-31', timestamp => '2015-08-31' })->store; >+my $id2 = $biblio2->id; > > my $dir = C4::Context::temporary_directory; > >-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, >@@ -82,8 +67,7 @@ $sitemapper->run(); > > my $file = "$dir/sitemapindex.xml"; > ok( -e "$dir/sitemapindex.xml", 'File sitemapindex.xml created' ); >-my $file_content = slurp($file); >-my $now = DateTime->now->ymd; >+my $file_content = read_file($file); > my $expected_content = <<"EOS"; > <?xml version="1.0" encoding="UTF-8"?> > >@@ -99,17 +83,17 @@ is( $file_content, $expected_content, 'Its content is valid' ); > > $file = "$dir/sitemap0001.xml"; > ok( -e $file, 'File sitemap0001.xml created' ); >-$file_content = slurp($file); >+$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"> > <url> >- <loc>http://www.mylibrary.org/cgi-bin/koha/opac-detail.pl?biblionumber=1</loc> >+ <loc>http://www.mylibrary.org/cgi-bin/koha/opac-detail.pl?biblionumber=$id1</loc> > <lastmod>2013-11-15</lastmod> > </url> > <url> >- <loc>http://www.mylibrary.org/cgi-bin/koha/opac-detail.pl?biblionumber=2</loc> >+ <loc>http://www.mylibrary.org/cgi-bin/koha/opac-detail.pl?biblionumber=$id2</loc> > <lastmod>2015-08-31</lastmod> > </url> > </urlset> >@@ -128,31 +112,30 @@ $sitemapper->run(); > > $file = "$dir/sitemap0001.xml"; > ok( -e $file, 'File sitemap0001.xml with short URLs created' ); >-$file_content = slurp($file); >+$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"> > <url> >- <loc>http://www.mylibrary.org/bib/1</loc> >+ <loc>http://www.mylibrary.org/bib/$id1</loc> > <lastmod>2013-11-15</lastmod> > </url> > <url> >- <loc>http://www.mylibrary.org/bib/2</loc> >+ <loc>http://www.mylibrary.org/bib/$id2</loc> > <lastmod>2015-08-31</lastmod> > </url> > </urlset> > EOS > 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 = []; >-for my $count ( 3 .. 75_000 ) { >- push @{$data}, [ $count, '2015-08-31', '2015-08-31' ]; >+# No need to create 75000 biblios here. Let's create 10 with $MAX == 6. >+# Expecting 3 files: index plus 2 url files with 6 and 4 urls. >+$Koha::Sitemapper::Writer::MAX = 6; >+for my $count ( 3..10 ) { >+ my $biblio2 = $builder->build_sample_biblio->set({ datecreated => '2015-08-31', timestamp => '2015-08-31' })->store; > } >-fixtures($data); >+ > $sitemapper = Koha::Sitemapper->new( > verbose => 0, > url => 'http://www.mylibrary.org', >@@ -162,9 +145,8 @@ $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); >+ok( -e "$dir/sitemapindex.xml", 'File sitemapindex.xml for 10 bibs created' ); >+$file_content = read_file($file); > $expected_content = <<"EOS"; > <?xml version="1.0" encoding="UTF-8"?> > >@@ -191,7 +173,7 @@ while (<$fh>) { > if ( $_ =~ /<loc>/xsm ) { $count++; } > } > close $fh; >-is( $count, 50_000, 'It contains 50000 URLs' ); >+is( $count, 6, 'It contains 6 URLs' ); > > $file = "$dir/sitemap0002.xml"; > ok( -e $file, 'File sitemap0002.xml created' ); >@@ -202,9 +184,11 @@ while (<$fh>) { > if ( $_ =~ /<loc>/xsm ) { $count++; } > } > close $fh; >-is( $count, 25_000, 'It contains 25000 URLs' ); >+is( $count, 4, 'It contains 4 URLs' ); > > # Cleanup > for my $file (qw/sitemapindex.xml sitemap0001.xml sitemap0002.xml/) { > unlink "$dir/$file"; > } >+}; >+$schema->storage->txn_rollback; >-- >2.25.1
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 33870
:
151875
|
151876
|
151877
|
153453
|
153454
|
153455
|
155094
| 155095 |
155096