Bugzilla – Attachment 43862 Details for
Bug 14778
DBIC should create/own the DB handler
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
[PASSED QA] Bug 14778: Example - Replace DBI::Mock with Test::DBIx::Class - Sitemapper.t
PASSED-QA-Bug-14778-Example---Replace-DBIMock-with.patch (text/plain), 6.09 KB, created by
Kyle M Hall (khall)
on 2015-10-23 14:56:23 UTC
(
hide
)
Description:
[PASSED QA] Bug 14778: Example - Replace DBI::Mock with Test::DBIx::Class - Sitemapper.t
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2015-10-23 14:56:23 UTC
Size:
6.09 KB
patch
obsolete
>From c60c364e06fd0c8082f7c36af2a293873e1171de Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Thu, 8 Oct 2015 11:40:43 +0100 >Subject: [PATCH] [PASSED QA] Bug 14778: Example - Replace DBI::Mock with Test::DBIx::Class - Sitemapper.t > >We can use Test::DBIx::Class to install fixtures before our tests. > >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >--- > t/db_dependent/Sitemapper.t | 75 +++++++++++++++++++++++++------------------ > 1 files changed, 44 insertions(+), 31 deletions(-) > >diff --git a/t/db_dependent/Sitemapper.t b/t/db_dependent/Sitemapper.t >index 293edad..c53ac8e 100755 >--- a/t/db_dependent/Sitemapper.t >+++ b/t/db_dependent/Sitemapper.t >@@ -18,11 +18,12 @@ > # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. > > use Modern::Perl; >-use Test::MockModule; > use File::Basename; > use File::Path; > use DateTime; >-use Test::More tests => 14; >+use Test::MockModule; >+use Test::More tests => 16; >+use Koha::Schema; > > > BEGIN { >@@ -30,7 +31,6 @@ BEGIN { > use_ok('Koha::Sitemapper::Writer'); > } > >- > sub slurp { > my $file = shift; > open my $fh, '<', $file or die; >@@ -40,28 +40,38 @@ sub slurp { > return $cont; > } > >+use Test::DBIx::Class { >+ schema_class => 'Koha::Schema', >+ connect_info => ['dbi:SQLite:dbname=:memory:','',''], >+ connect_opts => { name_sep => '.', quote_char => '`', }, >+ fixture_class => '::Populate', >+}, 'Biblio' ; >+ >+sub fixtures { >+ my ( $data ) = @_; >+ fixtures_ok [ >+ Biblio => [ >+ [ qw/ biblionumber datecreated timestamp / ], >+ @$data, >+ ], >+ ], 'add fixtures'; >+} > >-# Create 3 mocked dataset to be used by Koha::Sitemaper in place of DB content >-my $module_context = new Test::MockModule('C4::Context'); >-$module_context->mock('_new_dbh', sub { >- my $dbh = DBI->connect( 'DBI:Mock:', '', '' ) >- || die "Cannot create handle: $DBI::errstr\n"; >- return $dbh >-}); >-my $dbh = C4::Context->dbh(); >-my $two_bibs = [ >- [ qw/ biblionumber timestamp / ], >- [ qw/ 1234 2013-11-15 / ], >- [ qw/ 9875 2015-08-31 / ], >-]; >-my $lotof_bibs = [ [ qw/ biblionumber timestamp / ] ]; >-push @$lotof_bibs, [ $_, '2015-08-31' ] for 1..75000; >-$dbh->{mock_add_resultset} = $two_bibs; >-$dbh->{mock_add_resultset} = $two_bibs; >-$dbh->{mock_add_resultset} = $lotof_bibs; >+# 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(); } >+); > > my $dir = File::Spec->rel2abs( dirname(__FILE__) ); > >+ >+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 $sitemaper = Koha::Sitemapper->new( > verbose => 0, >@@ -86,7 +96,7 @@ my $expected_content = <<EOS; > </sitemapindex> > EOS > chop $expected_content; >-ok( $file_content eq $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"); >@@ -96,16 +106,16 @@ $expected_content = <<EOS; > > <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=1234</loc> >+ <loc>http://www.mylibrary.org/cgi-bin/koha/opac-detail.pl?biblionumber=1</loc> > <lastmod>2013-11-15</lastmod> > </url> > <url> >- <loc>http://www.mylibrary.org/cgi-bin/koha/opac-detail.pl?biblionumber=9875</loc> >+ <loc>http://www.mylibrary.org/cgi-bin/koha/opac-detail.pl?biblionumber=2</loc> > <lastmod>2015-08-31</lastmod> > </url> > </urlset> > EOS >-ok( $file_content eq $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'. >@@ -126,21 +136,24 @@ $expected_content = <<EOS; > > <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/1234</loc> >+ <loc>http://www.mylibrary.org/bib/1</loc> > <lastmod>2013-11-15</lastmod> > </url> > <url> >- <loc>http://www.mylibrary.org/bib/9875</loc> >+ <loc>http://www.mylibrary.org/bib/2</loc> > <lastmod>2015-08-31</lastmod> > </url> > </urlset> > EOS >-ok( $file_content eq $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; >+fixtures($data); > $sitemaper = Koha::Sitemapper->new( > verbose => 0, > url => 'http://www.mylibrary.org', >@@ -167,7 +180,7 @@ $expected_content = <<EOS; > </sitemapindex> > EOS > chop $expected_content; >-ok( $file_content eq $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"); >@@ -177,7 +190,7 @@ my $count = 0; > while (<$fh>) { > $count++ if /<loc>/; > } >-ok ( $count == 50000, "It contains 50000 URLs"); >+is( $count, 50000, "It contains 50000 URLs"); > > $file = "$dir/sitemap0002.xml"; > ok( -e $file, "File sitemap0002.xml created"); >@@ -187,7 +200,7 @@ $count = 0; > while (<$fh>) { > $count++ if /<loc>/; > } >-ok ( $count == 25000, "It contains 25000 URLs"); >+is( $count, 25000, "It contains 25000 URLs"); > > # Cleanup > unlink "$dir/$_" for qw / sitemapindex.xml sitemap0001.xml sitemap0002.xml /; >-- >1.7.2.5
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 14778
:
42326
|
42388
|
43247
|
43248
|
43249
|
43250
|
43440
|
43631
|
43632
|
43633
|
43634
|
43635
|
43636
|
43637
|
43638
|
43639
|
43640
|
43641
|
43642
|
43643
|
43644
|
43645
|
43834
|
43835
|
43836
|
43837
|
43838
|
43839
|
43840
|
43841
|
43842
|
43843
|
43844
|
43845
|
43846
|
43847
|
43848
|
43849
|
43850
|
43851
|
43852
|
43853
|
43857
|
43858
|
43859
|
43860
|
43861
| 43862 |
43863
|
43864
|
43865
|
43866
|
43867
|
43868
|
43869
|
43870
|
43871
|
43872
|
43873
|
43874
|
43875
|
43876
|
44003