Merge 'trunk' into 'cdbicompat_integration'
[dbsrgits/DBIx-Class.git] / t / 61findnot.t
CommitLineData
57dc206e 1use strict;
2use warnings;
3
4use Test::More;
5use lib qw(t/lib);
6use DBICTest;
7
8my $schema = DBICTest->init_schema();
9
10plan tests => 17;
11
12my $art = $schema->resultset("Artist")->find(4);
13ok(!defined($art), 'Find on primary id: artist not found');
14my @cd = $schema->resultset("CD")->find(6);
15cmp_ok(@cd, '==', 1, 'Return something even in array context');
16ok(@cd && !defined($cd[0]), 'Array contains an undef as only element');
17
18$art = $schema->resultset("Artist")->find({artistid => '4'});
19ok(!defined($art), 'Find on unique constraint: artist not found');
20@cd = $schema->resultset("CD")->find({artist => '2', title => 'Lada-Di Lada-Da'});
21cmp_ok(@cd, '==', 1, 'Return something even in array context');
22ok(@cd && !defined($cd[0]), 'Array contains an undef as only element');
23
24$art = $schema->resultset("Artist")->search({name => 'The Jesus And Mary Chain'});
25isa_ok($art, 'DBIx::Class::ResultSet', 'get a DBIx::Class::ResultSet object');
26my $next = $art->next;
27ok(!defined($next), 'Nothing next in ResultSet');
28my $cd = $schema->resultset("CD")->search({title => 'Rubbersoul'});
29@cd = $cd->next;
30cmp_ok(@cd, '==', 1, 'Return something even in array context');
31ok(@cd && !defined($cd[0]), 'Array contains an undef as only element');
32
33$art = $schema->resultset("Artist")->single({name => 'Bikini Bottom Boys'});
34ok(!defined($art), 'Find on primary id: artist not found');
35@cd = $schema->resultset("CD")->single({title => 'The Singles 1962-2006'});
36cmp_ok(@cd, '==', 1, 'Return something even in array context');
37ok(@cd && !defined($cd[0]), 'Array contains an undef as only element');
38
39$art = $schema->resultset("Artist")->search({name => 'Random Girl Band'});
40isa_ok($art, 'DBIx::Class::ResultSet', 'get a DBIx::Class::ResultSet object');
41$next = $art->single;
42ok(!defined($next), 'Nothing next in ResultSet');
43$cd = $schema->resultset("CD")->search({title => 'Call of the West'});
44@cd = $cd->single;
45cmp_ok(@cd, '==', 1, 'Return something even in array context');
46ok(@cd && !defined($cd[0]), 'Array contains an undef as only element');