f6616a5e1facbc22c99827547ec57a31d0079681
[dbsrgits/DBIx-Class.git] / t / schema / source-tree.t
1 use strict;
2 use warnings;
3 use Test::More;
4
5 use lib qw(t/lib);
6 use DBICTest;
7
8 my $schema = DBICTest->init_schema( no_connect => 1, no_deploy => 1 );
9
10 is_deeply($schema->source_tree, {
11   Artist => {},
12   ArtistSubclass => {},
13   ArtistUndirectedMap => {
14     artist => 1
15   },
16   Artwork => {
17     cd => 1
18   },
19   Artwork_to_Artist => {
20     artist => 1,
21     cd_artwork => 1
22   },
23   BindType => {},
24   Bookmark => {
25     link => 1
26   },
27   BooksInLibrary => {
28     owners => 1
29   },
30   CD => {
31     genre => 1,
32     track => 1
33   },
34   CD_to_Producer => {
35     cd => 1,
36     producer => 1
37   },
38   Collection => {},
39   CollectionObject => {
40     collection => 1,
41     typed_object => 1
42   },
43   CustomSql => {},
44   Dummy => {},
45   Employee => {
46     encoded => 1
47   },
48   Encoded => {},
49   Event => {},
50   EventTZ => {},
51   ForceForeign => {
52     artist => 1
53   },
54   FourKeys => {},
55   FourKeys_to_TwoKeys => {
56     fourkeys => 1,
57     twokeys => 1
58   },
59   Genre => {},
60   Image => {
61     cd_artwork => 1
62   },
63   LinerNotes => {
64     cd => 1
65   },
66   Link => {},
67   LyricVersion => {
68     lyrics => 1
69   },
70   Lyrics => {
71     track => 1
72   },
73   Money => {},
74   NoPrimaryKey => {},
75   OneKey => {},
76   Owners => {},
77   Producer => {},
78   SelfRef => {},
79   SelfRefAlias => {
80     self_ref => 1
81   },
82   SequenceTest => {},
83   Serialized => {},
84   SourceNameArtists => {},
85   Tag => {
86     cd => 1
87   },
88   TimestampPrimaryKey => {},
89   Track => {
90     cd => 1
91   },
92   TreeLike => {},
93   TwoKeyTreeLike => {},
94   TwoKeys => {
95     artist => 1,
96     cd => 1
97   },
98   TypedObject => {}
99 }, 'got correct source tree');
100
101 use Devel::Dwarn;
102
103 my $sans_TwoKeys = {
104   Artist => {},
105   ArtistSubclass => {},
106   ArtistUndirectedMap => {
107     artist => 1
108   },
109   Artwork => {
110     cd => 1
111   },
112   Artwork_to_Artist => {
113     artist => 1,
114     cd_artwork => 1
115   },
116   BindType => {},
117   Bookmark => {
118     link => 1
119   },
120   BooksInLibrary => {
121     owners => 1
122   },
123   CD => {
124     genre => 1,
125     track => 1
126   },
127   CD_to_Producer => {
128     cd => 1,
129     producer => 1
130   },
131   Collection => {},
132   CollectionObject => {
133     collection => 1,
134     typed_object => 1
135   },
136   CustomSql => {},
137   Dummy => {},
138   Employee => {
139     encoded => 1
140   },
141   Encoded => {},
142   Event => {},
143   EventTZ => {},
144   ForceForeign => {
145     artist => 1
146   },
147   FourKeys => {},
148   FourKeys_to_TwoKeys => {
149     fourkeys => 1
150   },
151   Genre => {},
152   Image => {
153     cd_artwork => 1
154   },
155   LinerNotes => {
156     cd => 1
157   },
158   Link => {},
159   LyricVersion => {
160     lyrics => 1
161   },
162   Lyrics => {
163     track => 1
164   },
165   Money => {},
166   NoPrimaryKey => {},
167   OneKey => {},
168   Owners => {},
169   Producer => {},
170   SelfRef => {},
171   SelfRefAlias => {
172     self_ref => 1
173   },
174   SequenceTest => {},
175   Serialized => {},
176   SourceNameArtists => {},
177   Tag => {
178     cd => 1
179   },
180   TimestampPrimaryKey => {},
181   Track => {
182     cd => 1
183   },
184   TreeLike => {},
185   TwoKeyTreeLike => {},
186   TypedObject => {}
187 };
188
189 is_deeply(
190    $schema->source_tree({ limit_sources => ['TwoKeys'] }),
191    $sans_TwoKeys,
192    'got correct source tree with limit_sources => [ ... ]',
193 );
194
195 is_deeply(
196    $schema->source_tree({ limit_sources => { TwoKeys => 1 } }),
197    $sans_TwoKeys,
198    'got correct source tree with limit_sources => { ... }',
199 );
200
201 # We probably also want a "collapsed" tree
202
203 done_testing;