Institute a central "load this first in testing" package
[dbsrgits/DBIx-Class.git] / t / 78self_referencial.t
1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7
8 use DBICTest;
9
10 my $schema = DBICTest->init_schema();
11
12 # this test will check to see if you can have 2 columns
13 # in the same class pointing at the same other class
14 #
15 # example:
16 #
17 # +---------+       +--------------+
18 # | SelfRef |       | SelfRefAlias |
19 # +---------+  1-M  +--------------+
20 # | id      |-------| self_ref     | --+
21 # | name    |       | alias        | --+
22 # +---------+       +--------------+   |
23 #    /|\                               |
24 #     |                                |
25 #     +--------------------------------+
26 #
27 # see http://use.perl.org/~LTjake/journal/24876 for the
28 # issue with CDBI
29
30 plan tests => 4;
31
32 my $item = $schema->resultset("SelfRef")->find( 1 );
33 is( $item->name, 'First', 'proper start item' );
34
35 my @aliases = $item->aliases;
36
37 is( scalar @aliases, 1, 'proper number of aliases' );
38
39 my $orig  = $aliases[ 0 ]->self_ref;
40 my $alias = $aliases[ 0 ]->alias;
41
42 is( $orig->name, 'First', 'proper original' );
43 is( $alias->name, 'Second', 'proper alias' );
44