nearly there with conversion of source_tree
[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   "  ( SELECT a.*, cd.cdid AS cdid, cd.title AS title, cd.year AS year\n  FROM artist a\n  JOIN cd ON cd.artist = a.artistid\n  WHERE cd.year = ?)\n" => {},
12   artist => {},
13   artist_undirected_map => {
14     artist => 1
15   },
16   artwork_to_artist => {
17     artist => 1,
18     cd => 1,
19     cd_artwork => 1,
20     genre => 1,
21     track => 1
22   },
23   bindtype_test => {},
24   bookmark => {
25     link => 1
26   },
27   books => {
28     owners => 1
29   },
30   cd => {
31     genre => 1,
32     track => 1
33   },
34   cd_artwork => {
35     cd => 1,
36     genre => 1,
37     track => 1
38   },
39   cd_to_producer => {
40     cd => 1,
41     genre => 1,
42     producer => 1,
43     track => 1
44   },
45   collection => {},
46   collection_object => {
47     collection => 1,
48     typed_object => 1
49   },
50   dummy => {},
51   employee => {
52     encoded => 1
53   },
54   encoded => {},
55   event => {},
56   forceforeign => {
57     artist => 1
58   },
59   fourkeys => {},
60   fourkeys_to_twokeys => {
61     artist => 1,
62     cd => 1,
63     fourkeys => 1,
64     genre => 1,
65     track => 1,
66     twokeys => 1
67   },
68   genre => {},
69   images => {
70     cd => 1,
71     cd_artwork => 1,
72     genre => 1,
73     track => 1
74   },
75   liner_notes => {
76     cd => 1,
77     genre => 1,
78     track => 1
79   },
80   link => {},
81   lyric_versions => {
82     cd => 1,
83     lyrics => 1,
84     track => 1
85   },
86   lyrics => {
87     cd => 1,
88     track => 1
89   },
90   money_test => {},
91   noprimarykey => {},
92   onekey => {},
93   owners => {},
94   producer => {},
95   self_ref => {},
96   self_ref_alias => {
97     self_ref => 1
98   },
99   sequence_test => {},
100   serialized => {},
101   tags => {
102     cd => 1,
103     genre => 1,
104     track => 1
105   },
106   timestamp_primary_key_test => {},
107   track => {
108     cd => 1
109   },
110   treelike => {},
111   twokeys => {
112     artist => 1,
113     cd => 1,
114     genre => 1,
115     track => 1
116   },
117   twokeytreelike => {},
118   typed_object => {},
119 }, 'got correct source tree');
120
121 is_deeply($schema->source_tree({ limit_sources => ['TwoKeys'] }), {
122   "  ( SELECT a.*, cd.cdid AS cdid, cd.title AS title, cd.year AS year\n  FROM artist a\n  JOIN cd ON cd.artist = a.artistid\n  WHERE cd.year = ?)\n" => {},
123   artist => {},
124   artist_undirected_map => {
125     artist => 1
126   },
127   artwork_to_artist => {
128     artist => 1,
129     cd => 1,
130     cd_artwork => 1,
131     genre => 1,
132     track => 1
133   },
134   bindtype_test => {},
135   bookmark => {
136     link => 1
137   },
138   books => {
139     owners => 1
140   },
141   cd => {
142     genre => 1,
143     track => 1
144   },
145   cd_artwork => {
146     cd => 1,
147     genre => 1,
148     track => 1
149   },
150   cd_to_producer => {
151     cd => 1,
152     genre => 1,
153     producer => 1,
154     track => 1
155   },
156   collection => {},
157   collection_object => {
158     collection => 1,
159     typed_object => 1
160   },
161   dummy => {},
162   employee => {
163     encoded => 1
164   },
165   encoded => {},
166   event => {},
167   forceforeign => {
168     artist => 1
169   },
170   fourkeys => {},
171   fourkeys_to_twokeys => {
172     fourkeys => 1
173   },
174   genre => {},
175   images => {
176     cd => 1,
177     cd_artwork => 1,
178     genre => 1,
179     track => 1
180   },
181   liner_notes => {
182     cd => 1,
183     genre => 1,
184     track => 1
185   },
186   link => {},
187   lyric_versions => {
188     cd => 1,
189     lyrics => 1,
190     track => 1
191   },
192   lyrics => {
193     cd => 1,
194     track => 1
195   },
196   money_test => {},
197   noprimarykey => {},
198   onekey => {},
199   owners => {},
200   producer => {},
201   self_ref => {},
202   self_ref_alias => {
203     self_ref => 1
204   },
205   sequence_test => {},
206   serialized => {},
207   tags => {
208     cd => 1,
209     genre => 1,
210     track => 1
211   },
212   timestamp_primary_key_test => {},
213   track => {
214     cd => 1
215   },
216   treelike => {},
217   twokeytreelike => {},
218   typed_object => {}
219 }, 'got correct source tree with limit_sources => [ ... ]');
220
221 is_deeply($schema->source_tree({ limit_sources => { TwoKeys => 1 } }), {
222   "  ( SELECT a.*, cd.cdid AS cdid, cd.title AS title, cd.year AS year\n  FROM artist a\n  JOIN cd ON cd.artist = a.artistid\n  WHERE cd.year = ?)\n" => {},
223   artist => {},
224   artist_undirected_map => {
225     artist => 1
226   },
227   artwork_to_artist => {
228     artist => 1,
229     cd => 1,
230     cd_artwork => 1,
231     genre => 1,
232     track => 1
233   },
234   bindtype_test => {},
235   bookmark => {
236     link => 1
237   },
238   books => {
239     owners => 1
240   },
241   cd => {
242     genre => 1,
243     track => 1
244   },
245   cd_artwork => {
246     cd => 1,
247     genre => 1,
248     track => 1
249   },
250   cd_to_producer => {
251     cd => 1,
252     genre => 1,
253     producer => 1,
254     track => 1
255   },
256   collection => {},
257   collection_object => {
258     collection => 1,
259     typed_object => 1
260   },
261   dummy => {},
262   employee => {
263     encoded => 1
264   },
265   encoded => {},
266   event => {},
267   forceforeign => {
268     artist => 1
269   },
270   fourkeys => {},
271   fourkeys_to_twokeys => {
272     fourkeys => 1
273   },
274   genre => {},
275   images => {
276     cd => 1,
277     cd_artwork => 1,
278     genre => 1,
279     track => 1
280   },
281   liner_notes => {
282     cd => 1,
283     genre => 1,
284     track => 1
285   },
286   link => {},
287   lyric_versions => {
288     cd => 1,
289     lyrics => 1,
290     track => 1
291   },
292   lyrics => {
293     cd => 1,
294     track => 1
295   },
296   money_test => {},
297   noprimarykey => {},
298   onekey => {},
299   owners => {},
300   producer => {},
301   self_ref => {},
302   self_ref_alias => {
303     self_ref => 1
304   },
305   sequence_test => {},
306   serialized => {},
307   tags => {
308     cd => 1,
309     genre => 1,
310     track => 1
311   },
312   timestamp_primary_key_test => {},
313   track => {
314     cd => 1
315   },
316   treelike => {},
317   twokeytreelike => {},
318   typed_object => {}
319 }, 'got correct source tree with limit_sources => { ... }');
320
321 # We probably also want a "collapsed" tree
322
323 done_testing;