1 package KohaTest::Search::SimpleSearch;
2 use base qw( KohaTest::Search );
12 =head2 STARTUP METHODS
14 These get run once, before the main test methods in this module
16 =head3 insert_test_data
20 sub insert_test_data : Test( startup => 71 ) {
23 # get original 'Finn Test' count
24 my $query = 'Finn Test';
25 my ( $error, $results ) = SimpleSearch( $query );
26 $self->{'orig_finn_test_hits'} = scalar(@$results);
28 # I'm going to add a bunch of biblios so that I can search for them.
29 $self->add_biblios( count => 10,
34 =head2 STARTUP METHODS
44 sub basic_test : Test( 2 ) {
49 my ( $error, $results ) = SimpleSearch( $query );
50 ok( ! defined $error, 'no error found during search' );
51 like( $results->[0], qr/$query/i, 'the result seems to match the query' )
52 or diag( Data::Dumper->Dump( [ $results ], [ 'results' ] ) );
56 =head3 basic_test_with_server
58 Test the usage where we specify no limits, but we do specify a server.
62 sub basic_test_with_server : Test( 2 ) {
67 my ( $error, $results ) = SimpleSearch( $query, undef, undef, [ 'biblioserver' ] );
68 ok( ! defined $error, 'no error found during search' );
69 like( $results->[0], qr/$query/i, 'the result seems to match the query' )
70 or diag( Data::Dumper->Dump( [ $results ], [ 'results' ] ) );
75 =head3 basic_test_no_results
77 Make sure we get back an empty listref when there are no results.
81 sub basic_test_no_results : Test( 3 ) {
84 my $query = 'This string is almost guaranteed to not match anything.';
86 my ( $error, $results ) = SimpleSearch( $query );
87 ok( ! defined $error, 'no error found during search' );
88 isa_ok( $results, 'ARRAY' );
89 is( scalar( @$results ), 0, 'an empty list was returned.' )
90 or diag( Data::Dumper->Dump( [ $results ], [ 'results' ] ) );
95 check that the SimpleTest method limits the number of results returned.
99 sub limits : Test( 8 ) {
102 my $query = 'Finn Test';
105 my ( $error, $results ) = SimpleSearch( $query );
106 ok( ! defined $error, 'no error found during search' );
107 my $expected_hits = 10 + $self->{'orig_finn_test_hits'};
108 is( scalar @$results, $expected_hits, "found all $expected_hits results." )
109 or diag( Data::Dumper->Dump( [ $results ], [ 'results' ] ) );
114 my ( $error, $results ) = SimpleSearch( $query, $offset );
115 ok( ! defined $error, 'no error found during search' );
116 my $expected_hits = 6 + $self->{'orig_finn_test_hits'};
117 is( scalar @$results, $expected_hits, "found $expected_hits results." )
118 or diag( Data::Dumper->Dump( [ $results ], [ 'results' ] ) );
123 my ( $error, $results ) = SimpleSearch( $query, $offset, $max_results );
124 ok( ! defined $error, 'no error found during search' );
125 is( scalar @$results, $max_results, "found $max_results results." )
126 or diag( Data::Dumper->Dump( [ $results ], [ 'results' ] ) );
130 my ( $error, $results ) = SimpleSearch( $query, 0, $max_results );
131 ok( ! defined $error, 'no error found during search' );
132 is( scalar @$results, $max_results, "found $max_results results." )
133 or diag( Data::Dumper->Dump( [ $results ], [ 'results' ] ) );