100% conversion to sources
[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 use Devel::Dwarn;
11
12 is_deeply($schema->source_tree, {
13   Artist => {},
14   ArtistSubclass => {},
15   ArtistUndirectedMap => {
16     Artist => 1
17   },
18   Artwork => {
19     CD => 1,
20     Genre => 1,
21     Track => 1
22   },
23   Artwork_to_Artist => {
24     Artist => 1,
25     Artwork => 1,
26     CD => 1,
27     Genre => 1,
28     Track => 1
29   },
30   BindType => {},
31   Bookmark => {
32     Link => 1
33   },
34   BooksInLibrary => {
35     Owners => 1
36   },
37   CD => {
38     Genre => 1,
39     Track => 1
40   },
41   CD_to_Producer => {
42     CD => 1,
43     Genre => 1,
44     Producer => 1,
45     Track => 1
46   },
47   Collection => {},
48   CollectionObject => {
49     Collection => 1,
50     TypedObject => 1
51   },
52   CustomSql => {},
53   Dummy => {},
54   Employee => {
55     Encoded => 1
56   },
57   Encoded => {},
58   Event => {},
59   EventTZ => {},
60   ForceForeign => {
61     Artist => 1
62   },
63   FourKeys => {},
64   FourKeys_to_TwoKeys => {
65     Artist => 1,
66     CD => 1,
67     FourKeys => 1,
68     Genre => 1,
69     Track => 1,
70     TwoKeys => 1
71   },
72   Genre => {},
73   Image => {
74     Artwork => 1,
75     CD => 1,
76     Genre => 1,
77     Track => 1
78   },
79   LinerNotes => {
80     CD => 1,
81     Genre => 1,
82     Track => 1
83   },
84   Link => {},
85   LyricVersion => {
86     CD => 1,
87     Lyrics => 1,
88     Track => 1
89   },
90   Lyrics => {
91     CD => 1,
92     Track => 1
93   },
94   Money => {},
95   NoPrimaryKey => {},
96   OneKey => {},
97   Owners => {},
98   Producer => {},
99   SelfRef => {},
100   SelfRefAlias => {
101     SelfRef => 1
102   },
103   SequenceTest => {},
104   Serialized => {},
105   SourceNameArtists => {},
106   Tag => {
107     CD => 1,
108     Genre => 1,
109     Track => 1
110   },
111   TimestampPrimaryKey => {},
112   Track => {
113     CD => 1
114   },
115   TreeLike => {},
116   TwoKeyTreeLike => {},
117   TwoKeys => {
118     Artist => 1,
119     CD => 1,
120     Genre => 1,
121     Track => 1
122   },
123   TypedObject => {}
124 }, 'got correct source tree');
125
126 use Devel::Dwarn;
127
128 my $sans_TwoKeys = {
129   Artist => {},
130   ArtistSubclass => {},
131   ArtistUndirectedMap => {
132     Artist => 1
133   },
134   Artwork => {
135     CD => 1,
136     Genre => 1,
137     Track => 1
138   },
139   Artwork_to_Artist => {
140     Artist => 1,
141     Artwork => 1,
142     CD => 1,
143     Genre => 1,
144     Track => 1
145   },
146   BindType => {},
147   Bookmark => {
148     Link => 1
149   },
150   BooksInLibrary => {
151     Owners => 1
152   },
153   CD => {
154     Genre => 1,
155     Track => 1
156   },
157   CD_to_Producer => {
158     CD => 1,
159     Genre => 1,
160     Producer => 1,
161     Track => 1
162   },
163   Collection => {},
164   CollectionObject => {
165     Collection => 1,
166     TypedObject => 1
167   },
168   CustomSql => {},
169   Dummy => {},
170   Employee => {
171     Encoded => 1
172   },
173   Encoded => {},
174   Event => {},
175   EventTZ => {},
176   ForceForeign => {
177     Artist => 1
178   },
179   FourKeys => {},
180   FourKeys_to_TwoKeys => {
181     FourKeys => 1
182   },
183   Genre => {},
184   Image => {
185     Artwork => 1,
186     CD => 1,
187     Genre => 1,
188     Track => 1
189   },
190   LinerNotes => {
191     CD => 1,
192     Genre => 1,
193     Track => 1
194   },
195   Link => {},
196   LyricVersion => {
197     CD => 1,
198     Lyrics => 1,
199     Track => 1
200   },
201   Lyrics => {
202     CD => 1,
203     Track => 1
204   },
205   Money => {},
206   NoPrimaryKey => {},
207   OneKey => {},
208   Owners => {},
209   Producer => {},
210   SelfRef => {},
211   SelfRefAlias => {
212     SelfRef => 1
213   },
214   SequenceTest => {},
215   Serialized => {},
216   SourceNameArtists => {},
217   Tag => {
218     CD => 1,
219     Genre => 1,
220     Track => 1
221   },
222   TimestampPrimaryKey => {},
223   Track => {
224     CD => 1
225   },
226   TreeLike => {},
227   TwoKeyTreeLike => {},
228   TypedObject => {}
229 };
230
231 is_deeply(
232    $schema->source_tree({ limit_sources => ['TwoKeys'] }),
233    $sans_TwoKeys,
234    'got correct source tree with limit_sources => [ ... ]',
235 );
236
237 is_deeply(
238    $schema->source_tree({ limit_sources => { TwoKeys => 1 } }),
239    $sans_TwoKeys,
240    'got correct source tree with limit_sources => { ... }',
241 );
242
243 # We probably also want a "collapsed" tree thingy
244
245 done_testing;