1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
#!perl
use strict;
use warnings;
use Test::More tests => 19;
use Test::Fatal;
use lib '.';
use t::lib::Functions;
{
no warnings qw<redefine once>;
my $count = 0;
*MetaCPAN::Client::ssearch = sub {
my ( $self, $type, $args, $params ) = @_;
::isa_ok( $self, 'MetaCPAN::Client' );
::is( $type, 'author', 'Correct type' );
::is_deeply( $args, { hello => 'world' }, 'Correct args' );
if ( $count++ == 0 ) {
::is_deeply( $params, {}, 'Correct empty params' );
} else {
::is_deeply( $params, { a => 'b' }, 'Correct params' );
}
return { a => 'ok' };
};
*MetaCPAN::Client::ResultSet::new = sub {
my ( $self, %args ) = @_;
::isa_ok( $self, 'MetaCPAN::Client::ResultSet' );
::is_deeply(
\%args,
{
scroller => { a => 'ok' },
type => 'author',
},
'Correct args to ::ResultSet',
);
return 'yoyo';
};
}
my $mc = mcpan();
can_ok( $mc, '_search' );
like(
exception { $mc->_search('author') },
qr/^_search takes a hash ref as query/,
'Failed with no query',
);
like(
exception { $mc->_search( 'author', { hello => 'world' }, 'fail' ) },
qr/^_search takes a hash ref as query parameters/,
'Failed with no query parameters',
);
like(
exception { $mc->_search( 'authorz', { hello => 'world' }, { a => 'b' } ) },
qr/^search type is not supported/,
'Unsupported search type',
);
is(
$mc->_search( 'author', { hello => 'world' } ),
'yoyo',
'Works with no query parameters',
);
is(
$mc->_search( 'author', { hello => 'world' }, { a => 'b' } ),
'yoyo',
'Correct _search call',
);
|