2 use base qw(Test::Class);
7 eval "use Test::Class";
8 plan skip_all => "Test::Class required for performing database tests" if $@;
9 # Or, maybe I should just die there.
19 # Since this is an abstract base class, this prevents these tests from
20 # being run directly unless we're testing a subclass. It just makes
22 __PACKAGE__->SKIP_CLASS( 1 );
25 =head2 startup methods
27 these are run once, at the beginning of the whole test suite
31 sub startup_15_truncate_tables : Test( startup => 1 ) {
34 # my @truncate_tables = qw( accountlines
46 # auth_subfield_structure
73 # import_record_matches
83 # language_descriptions
84 # language_rfc4646_to_iso639
85 # language_script_bidi
86 # language_script_mapping
87 # language_subtag_registry
90 # marc_subfield_structure
94 # matchpoint_component_norms
95 # matchpoint_components
108 # repeatable_holidays
125 # subscriptionhistory
126 # subscriptionroutinglist
131 # virtualshelfcontents
137 my @truncate_tables = qw( accountlines
158 import_record_matches
190 subscriptionroutinglist
196 my $failed_to_truncate = 0;
197 foreach my $table ( @truncate_tables ) {
198 my $dbh = C4::Context->dbh();
199 $dbh->do( "truncate $table" )
200 or $failed_to_truncate = 1;
202 is( $failed_to_truncate, 0, 'truncated tables' );
206 =head2 startup_20_add_bookseller
208 we need a bookseller for many of the tests, so let's insert one. Feel
209 free to use this one, or insert your own.
213 sub startup_20_add_bookseller : Test(startup => 1) {
216 my $booksellerinfo = { name => 'bookseller ' . $self->random_string(),
219 my $id = AddBookseller( $booksellerinfo );
220 ok( $id, "created bookseller: $id" );
221 $self->{'booksellerid'} = $id;
226 =head2 startup_22_add_bookfund
228 we need a bookfund for many of the tests. This currently uses one that
229 is in the skeleton database. free to use this one, or insert your
234 sub startup_22_add_bookfund : Test(startup => 2) {
237 my $bookfundid = 'GEN';
238 my $bookfund = GetBookFund( $bookfundid, undef );
239 # diag( Data::Dumper->Dump( [ $bookfund ], qw( bookfund ) ) );
240 is( $bookfund->{'bookfundid'}, $bookfundid, "found bookfund: '$bookfundid'" );
241 is( $bookfund->{'bookfundname'}, 'General Stacks', "found bookfund: '$bookfundid'" );
243 $self->{'bookfundid'} = $bookfundid;
247 =head2 startup_24_add_member
249 Add a patron/member for the tests to use
253 sub startup_24_add_member : Test(startup => 1) {
256 my $memberinfo = { surname => 'surname ' . $self->random_string(),
257 firstname => 'firstname' . $self->random_string(),
258 address => 'address' . $self->random_string(),
259 city => 'city' . $self->random_string(),
260 branchcode => 'CPL', # CPL => Centerville
261 categorycode => 'PT', # PT => PaTron
264 my $id = AddMember( %$memberinfo );
265 ok( $id, "created member: $id" );
266 $self->{'memberid'} = $id;
273 setup methods are run before every test method
277 =head2 teardown methods
279 teardown methods are many time, once at the end of each test method.
283 =head2 shutdown methods
285 shutdown methods are run once, at the end of the test suite
289 =head2 utility methods
291 These are not test methods, but they're handy
297 Nice for generating names and such. It's not actually random, more
305 my $wordsize = 6; # how many letters in your string?
307 # leave out these characters: "oOlL10". They're too confusing.
308 my @alphabet = ( 'a'..'k','m','n','p'..'z', 'A'..'K','M','N','P'..'Z', 2..9 );
311 foreach ( 0..$wordsize ) {
312 $randomstring .= $alphabet[ rand( scalar( @alphabet ) ) ];
314 return $randomstring;
320 $self->add_biblios( count => 10,
324 count: number of biblios to add
325 add_items: should you add items for each one?
331 adds the biblionumbers to the $self->{'biblios'} listref
334 Should I allow you to pass in biblio information, like title?
335 Since this method is in the KohaTest class, all tests in it will be ignored, unless you call this from your own namespace.
336 This runs 10 tests, plus 4 for each "count", plus 3 more for each item added.
344 $param{'count'} = 1 unless defined( $param{'count'} );
345 $param{'add_items'} = 0 unless defined( $param{'add_items'} );
347 foreach my $counter ( 1..$param{'count'} ) {
348 my $marcrecord = MARC::Record->new();
349 isa_ok( $marcrecord, 'MARC::Record' );
350 my $appendedfieldscount = $marcrecord->append_fields( MARC::Field->new( '100', '1', '0',
353 MARC::Field->new( '245', '1', '4',
354 a => sprintf( 'The Adventures of Huckleberry Finn Test %s', $counter ),
355 c => "Mark Twain ; illustrated by E.W. Kemble." )
357 is( $appendedfieldscount, 2, 'added 2 fields' );
359 my $frameworkcode = ''; # XXX I'd like to put something reasonable here.
360 my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $marcrecord, $frameworkcode );
361 ok( $biblionumber, "the biblionumber is $biblionumber" );
362 ok( $biblioitemnumber, "the biblioitemnumber is $biblioitemnumber" );
363 if ( $param{'add_items'} ) {
364 # my @iteminfo = AddItem( {}, $biblionumber );
365 my @iteminfo = AddItemFromMarc( $marcrecord, $biblionumber );
366 is( $iteminfo[0], $biblionumber, "biblionumber is $biblionumber" );
367 is( $iteminfo[1], $biblioitemnumber, "biblioitemnumber is $biblioitemnumber" );
368 ok( $iteminfo[2], "itemnumber is $iteminfo[2]" );
370 push @{$self->{'biblios'}}, $biblionumber;
373 my $query = 'Finn Test';
375 # XXX we're going to repeatedly try to fetch the marc records that
376 # we inserted above. It may take a while before they all show
379 DELAY: foreach my $trial ( 1..$tries ) {
380 diag "waiting for zebra indexing. Trial: $trial of $tries";
381 my ( $error, $results ) = SimpleSearch( $query );
382 if ( $param{'count'} <= scalar( @$results ) ) {
383 ok( $tries, "found all $param{'count'} titles after $trial tries" );
388 if ( $trial == $tries ) {
389 fail( "we never found all $param{'count'} titles even after $tries tries." );