1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2 use DBIx::Class::Optional::Dependencies -skip_all_without => 'cdbicompat';
9 use lib 't/cdbi/testlib';
13 { # Check __ESSENTIAL__ expansion (RT#13038)
14 my @cols = Film->columns('Essential');
15 is_deeply \@cols, ['title'], "1 Column in essential";
16 is +Film->transform_sql('__ESSENTIAL__'), 'title', '__ESSENTIAL__ expansion';
18 # This provides a more interesting test
19 Film->columns(Essential => qw(title rating));
20 is +Film->transform_sql('__ESSENTIAL__'), 'title, rating',
21 'multi-col __ESSENTIAL__ expansion';
24 my $f1 = Film->create({ title => 'A', director => 'AA', rating => 'PG' });
25 my $f2 = Film->create({ title => 'B', director => 'BA', rating => 'PG' });
26 my $f3 = Film->create({ title => 'C', director => 'AA', rating => '15' });
27 my $f4 = Film->create({ title => 'D', director => 'BA', rating => '18' });
28 my $f5 = Film->create({ title => 'E', director => 'AA', rating => '18' });
34 WHERE __TABLE__.rating = 'PG'
40 (my $sth = Film->sql_pgs())->execute;
41 my @pgs = Film->sth_to_objects($sth);
42 is @pgs, 2, "Execute our own SQL";
43 is $pgs[0]->id, $f2->id, "get F2";
44 is $pgs[1]->id, $f1->id, "and F1";
48 my @pgs = Film->search_pgs;
49 is @pgs, 2, "SQL creates search() method";
50 is $pgs[0]->id, $f2->id, "get F2";
51 is $pgs[1]->id, $f1->id, "and F1";
64 my @pgs = Film->search_rating('18');
65 is @pgs, 2, "Can pass parameters to created search()";
66 is $pgs[0]->id, $f5->id, "F5";
67 is $pgs[1]->id, $f4->id, "and F4";
79 my $film = Film->retrieve_all->first;
80 my @found = Film->search_by_id($film->id);
82 is $found[0]->id, $film->id;
87 Actor->has_a(film => "Film");
90 SELECT __ESSENTIAL(f)__
91 FROM __TABLE(=f)__, __TABLE(Actor=a)__
99 my $a1 = Actor->create({ name => "A1", film => $f1 });
100 my $a2 = Actor->create({ name => "A2", film => $f2 });
101 my $a3 = Actor->create({ name => "B1", film => $f1 });
103 my @apg = Film->search_namerate("A_", "PG");
104 is @apg, 2, "2 Films with A* that are PG";
105 is $apg[0]->title, "A", "A";
106 is $apg[1]->title, "B", "and B";
110 Actor->has_a(film => "Film");
113 SELECT __ESSENTIAL(f)__
114 FROM __TABLE(=f)__, __TABLE(Actor=a)__
122 my @apg = Film->search_ratename(PG => "A_");
123 is @apg, 2, "2 Films with A* that are PG";
124 is $apg[0]->title, "A", "A";
125 is $apg[1]->title, "B", "and B";