Bugzilla – Attachment 43637 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]
Bug 14778: Install fixtures for t/ItemType.t
Bug-14778-Install-fixtures-for-tItemTypet.patch (text/plain), 3.25 KB, created by
Jonathan Druart
on 2015-10-20 15:02:09 UTC
(
hide
)
Description:
Bug 14778: Install fixtures for t/ItemType.t
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2015-10-20 15:02:09 UTC
Size:
3.25 KB
patch
obsolete
>From 9844d90abe042172ac6a77a598d0c00fa3ce968e Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Tue, 20 Oct 2015 12:48:37 +0100 >Subject: [PATCH] Bug 14778: Install fixtures for t/ItemType.t > >--- > t/ItemType.t | 69 +++++++++++++++++++++++------------------------------------- > 1 file changed, 26 insertions(+), 43 deletions(-) > >diff --git a/t/ItemType.t b/t/ItemType.t >index 238fe2c..b10efdd 100755 >--- a/t/ItemType.t >+++ b/t/ItemType.t >@@ -1,59 +1,48 @@ > #!/usr/bin/perl > > use Modern::Perl; >-use DBI; >-use Test::More tests => 27; >-use Test::MockModule; >- >-BEGIN { >- use_ok('C4::ItemType'); >+use Test::More tests => 25; >+use t::lib::Mocks; >+ >+use_ok('C4::ItemType'); >+ >+use Test::DBIx::Class { >+ schema_class => 'Koha::Schema', >+ connect_info => ['dbi:SQLite:dbname=:memory:','',''], >+ connect_opts => { name_sep => '.', quote_char => '`', }, >+ fixture_class => '::Populate', >+}, 'Itemtype' ; >+ >+sub fixtures { >+ my ( $data ) = @_; >+ fixtures_ok [ >+ Itemtype => [ >+ [ >+ 'itemtype', 'description', 'rentalcharge', 'notforloan', >+ 'imageurl', 'summary', 'checkinmsg' >+ ], >+ @$data, >+ ], >+ ], 'add fixtures'; > } > >-my $module = new Test::MockModule('C4::Context'); >-$module->mock( >- '_new_dbh', >- sub { >- my $dbh = DBI->connect( 'DBI:Mock:', '', '' ) >- || die "Cannot create handle: $DBI::errstr\n"; >- return $dbh; >- } >-); >+my $db = Test::MockModule->new('Koha::Database'); >+$db->mock( _new_schema => sub { return Schema(); } ); > > # Mock data > my $itemtypes = [ >- [ >- 'itemtype', 'description', 'rentalcharge', 'notforloan', >- 'imageurl', 'summary', 'checkinmsg' >- ], > [ 'BK', 'Books', 0, 0, '', '', 'foo' ], > [ 'CD', 'CDRom', 0, 0, '', '', 'bar' ] > ]; > >-my $itemtypes_empty = [ >- [ >- 'itemtype', 'description', 'rentalcharge', 'notforloan', >- 'imageurl', 'summary', 'checkinmsg' >- ], >-]; >- >-my $dbh = C4::Context->dbh(); >-$dbh->{mock_add_resultset} = $itemtypes_empty; >- > my @itemtypes = C4::ItemType->all(); > is( @itemtypes, 0, 'Testing all itemtypes is empty' ); > >-# This should run exactly one query so we can test >-my $history = $dbh->{mock_all_history}; >-is( scalar( @{$history} ), 1, 'Correct number of statements executed' ); >- > # Now lets mock some data >-$dbh->{mock_add_resultset} = $itemtypes; >+fixtures($itemtypes); > > @itemtypes = C4::ItemType->all(); > >-$history = $dbh->{mock_all_history}; >-is( scalar( @{$history} ), 2, 'Correct number of statements executed' ); >- > is( @itemtypes, 2, 'ItemType->all should return an array with 2 elements' ); > > is( $itemtypes[0]->fish, undef, 'Calling a bad descriptor gives undef' ); >@@ -82,15 +71,9 @@ is( $itemtypes[0]->checkinmsg, 'foo', 'first checkinmsg is foo' ); > > is( $itemtypes[1]->checkinmsg, 'bar', 'second checkinmsg is bar' ); > >-# Mock the data again >-$dbh->{mock_add_resultset} = $itemtypes; >- > # Test get(), which should return one itemtype > my $itemtype = C4::ItemType->get( 'BK' ); > >-$history = $dbh->{mock_all_history}; >-is( scalar( @{$history} ), 3, 'Correct number of statements executed' ); >- > is( $itemtype->fish, undef, 'Calling a bad descriptor gives undef' ); > > is( $itemtype->itemtype, 'BK', 'itemtype is bk' ); >-- >2.1.0
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