summaryrefslogtreecommitdiffstats
path: root/t/search.t
blob: 0e8ee9cf04cbca52c3d6f87149ad27f80c278464 (plain)
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
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use FindBin;
use Test::More;
use DBI;
use lib "$FindBin::Bin/lib";
use lib "$FindBin::Bin/../lib";

BEGIN 
{
  eval { require DBD::CSV; }
    or plan skip_all => 
    "DBD::CSV is needed for this test";

  plan tests => 13;

  unlink('foo_table') if ( -e 'foo_table' );
  my $dbh = DBI->connect('DBI:CSV:f_dir=./') or die $DBI::errstr;
  $dbh->do('create table foo_table (id INTEGER, name CHAR(255), password CHAR(255), email CHAR(255))') or $dbh->errstr;
  $dbh->do("insert into foo_table values (2, 'foo', 'pass', 'foo\@bar.org')") or $dbh->errstr;
  $dbh->do("insert into foo_table values (3, 'bar', 'pass', 'bar\@foo.org')") or $dbh->errstr;
  $dbh->disconnect();

  use_ok('Foo');
}

my $obj = Foo->find_or_create( id => 1, name => 'jason', password => 'pass', email => 'woodwardj@jaos.org' );
isa_ok($obj,'Foo');

ok(Foo->search(name => 'jason') > 0,'search returns array');
ok(Foo->search(name => 'jason',{ order_by => 'id'}) > 0,'search with order_by returns array');
ok(Foo->search_where("name = 'jason'") > 0,'search returns array');
ok(Foo->search_like(name => 'j%') > 0,'search_like returns array');
ok(Foo->search_ilike() > 0,'search_ilike returns array');
ok(Foo->search_or_like() > 0,'search_or_like returns array');
ok(Foo->search_or_ilike() > 0,'search_or_ilike returns array');
ok(Foo->search(name => ['jason','foo','bar']) == 3, 'search() using arrayref');
ok(Foo->search_like(name => ['%jason','%foo','%bar'], password => 'pass') == 3, 'search_like() using arrayref');
#PG specific #ok(Foo->search_ilike(name => ['%jason','%foo','%bar'], password => 'pass') == 3, 'search_ilike() using arrayref');
#PG specific #ok(Foo->search_or_ilike(name => ['%jason','%foo','%bar'], password => 'pass') == 3, 'search_or_ilike() using arrayref');
ok(Foo->search_or(name => ['jason','foo','bar'], password => 'pass') == 3, 'search_or() using arrayref');
ok(Foo->search_or_like(name => ['%jason','%foo','%bar'], password => 'pass') == 3, 'search_or_like() using arrayref');

END
{
  unlink('foo_table');
}