X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Finflate%2Fhri_torture.t;h=610a47b409570adb46f77c0451ef7babcb38ca44;hb=3aac91f35f319b3bf6bad743d956f037ba857012;hp=04237f92ab9dddcbacb17f4b3d6676f26ccdf5d9;hpb=ce556881780369e33743ef86a0cb183e976d3d19;p=dbsrgits%2FDBIx-Class.git diff --git a/t/inflate/hri_torture.t b/t/inflate/hri_torture.t index 04237f9..610a47b 100644 --- a/t/inflate/hri_torture.t +++ b/t/inflate/hri_torture.t @@ -1,8 +1,11 @@ +BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) } + use strict; use warnings; use Test::More; -use lib qw(t/lib); +use Test::Deep; + use DBICTest; # More tests like this in t/prefetch/manual.t @@ -37,6 +40,7 @@ $schema->resultset('CD')->create({ title => 'Oxygene', year => 1976, artist => { name => 'JMJ' }, + artwork => {}, tracks => [ { title => 'o2', position => 2}, # the position should not be needed here, bug in MC ], @@ -48,50 +52,50 @@ for (1,2) { $schema->resultset('CD')->create({ artist => 1, year => 1977, title => "fuzzy_$_" }); } -my $rs = $schema->resultset('CD'); +{ + package DBICTest::HRI::Subclass; + use base 'DBIx::Class::ResultClass::HashRefInflator'; +} + +{ + package DBICTest::HRI::Around; + use base 'DBIx::Class::ResultClass::HashRefInflator'; + + sub inflate_result { shift->next::method(@_) } +} + +for my $rs ( + $schema->resultset('CD')->search_rs({}, { result_class => 'DBIx::Class::ResultClass::HashRefInflator' }), + $schema->resultset('CD')->search_rs({}, { result_class => 'DBICTest::HRI::Subclass' }), + $schema->resultset('CD')->search_rs({}, { result_class => 'DBICTest::HRI::Around' }), +) { -is_deeply - $rs->search({}, { +cmp_deeply + [ $rs->search({}, { columns => { year => 'me.year', 'single_track.cd.artist.name' => 'artist.name', }, join => { single_track => { cd => 'artist' } }, order_by => [qw/me.cdid artist.artistid/], - })->all_hri, + })->all ], [ - { - single_track => undef, - year => 1981 - }, - { - single_track => undef, - year => 1976 - }, - { - single_track => { - cd => { - artist => { - name => "JMJ" - } - } + { year => 1981, single_track => undef }, + { year => 1976, single_track => undef }, + { year => 1978, single_track => { + cd => { + artist => { name => "JMJ" } }, - year => 1978 - }, - { - single_track => undef, - year => 1977 - }, - { - single_track => undef, - year => 1977 - }, + }}, + { year => 1977, single_track => undef }, + { year => 1977, single_track => undef }, + ], - 'plain 1:1 descending chain' + 'plain 1:1 descending chain ' . $rs->result_class ; -is_deeply - $rs->search({}, { +cmp_deeply + [ $rs->search({}, { columns => { 'artist' => 'me.artist', 'title' => 'me.title', @@ -102,232 +106,165 @@ is_deeply }, join => { single_track => { cd => { artist => { cds => 'tracks' } } } }, order_by => [qw/me.cdid artist.artistid cds.cdid tracks.trackid/], - })->all_hri, + })->all ], [ { - artist => 1, - single_track => undef, - title => "Magnetic Fields", - year => 1981 + artist => 1, title => "Magnetic Fields", year => 1981, single_track => undef, }, { - artist => 1, - single_track => undef, - title => "Oxygene", - year => 1976 + artist => 1, title => "Oxygene", year => 1976, single_track => undef, }, { - artist => 1, - single_track => { + artist => 1, title => "Equinoxe", year => 1978, single_track => { cd => { artist => { - artistid => 1, - cds => { - cdid => 1, - tracks => { + artistid => 1, cds => { + cdid => 1, tracks => { title => "m1" } } } } }, - title => "Equinoxe", - year => 1978 }, { - artist => 1, - single_track => { + artist => 1, title => "Equinoxe", year => 1978, single_track => { cd => { artist => { - artistid => 1, - cds => { - cdid => 1, - tracks => { + artistid => 1, cds => { + cdid => 1, tracks => { title => "m2" } } } } }, - title => "Equinoxe", - year => 1978 }, { - artist => 1, - single_track => { + artist => 1, title => "Equinoxe", year => 1978, single_track => { cd => { artist => { - artistid => 1, - cds => { - cdid => 1, - tracks => { + artistid => 1, cds => { + cdid => 1, tracks => { title => "m3" } } } } }, - title => "Equinoxe", - year => 1978 }, { - artist => 1, - single_track => { + artist => 1, title => "Equinoxe", year => 1978, single_track => { cd => { artist => { - artistid => 1, - cds => { - cdid => 1, - tracks => { + artistid => 1, cds => { + cdid => 1, tracks => { title => "m4" } } } } }, - title => "Equinoxe", - year => 1978 }, { - artist => 1, - single_track => { + artist => 1, title => "Equinoxe", year => 1978, single_track => { cd => { artist => { - artistid => 1, - cds => { - cdid => 2, - tracks => { + artistid => 1, cds => { + cdid => 2, tracks => { title => "o2" } } } } }, - title => "Equinoxe", - year => 1978 }, { - artist => 1, - single_track => { + artist => 1, title => "Equinoxe", year => 1978, single_track => { cd => { artist => { - artistid => 1, - cds => { - cdid => 2, - tracks => { + artistid => 1, cds => { + cdid => 2, tracks => { title => "o1" } } } } }, - title => "Equinoxe", - year => 1978 }, { - artist => 1, - single_track => { + artist => 1, title => "Equinoxe", year => 1978, single_track => { cd => { artist => { - artistid => 1, - cds => { - cdid => 3, - tracks => { + artistid => 1, cds => { + cdid => 3, tracks => { title => "e1" } } } } }, - title => "Equinoxe", - year => 1978 }, { - artist => 1, - single_track => { + artist => 1, title => "Equinoxe", year => 1978, single_track => { cd => { artist => { - artistid => 1, - cds => { - cdid => 3, - tracks => { + artistid => 1, cds => { + cdid => 3, tracks => { title => "e2" } } } } }, - title => "Equinoxe", - year => 1978 }, { - artist => 1, - single_track => { + artist => 1, title => "Equinoxe", year => 1978, single_track => { cd => { artist => { - artistid => 1, - cds => { - cdid => 3, - tracks => { + artistid => 1, cds => { + cdid => 3, tracks => { title => "e3" } } } } }, - title => "Equinoxe", - year => 1978 }, { - artist => 1, - single_track => { + artist => 1, title => "Equinoxe", year => 1978, single_track => { cd => { artist => { - artistid => 1, - cds => { - cdid => 4, - tracks => undef + artistid => 1, cds => { + cdid => 4, tracks => undef } } } }, - title => "Equinoxe", - year => 1978 }, { - artist => 1, - single_track => { + artist => 1, title => "Equinoxe", year => 1978, single_track => { cd => { artist => { - artistid => 1, - cds => { - cdid => 5, - tracks => undef + artistid => 1, cds => { + cdid => 5, tracks => undef } } } }, - title => "Equinoxe", - year => 1978 }, { - artist => 1, - single_track => undef, - title => "fuzzy_1", - year => 1977 + artist => 1, title => "fuzzy_1", year => 1977, single_track => undef, }, { - artist => 1, - single_track => undef, - title => "fuzzy_2", - year => 1977 + artist => 1, title => "fuzzy_2", year => 1977, single_track => undef, } ], - 'non-collapsing 1:1:1:M:M chain', + 'non-collapsing 1:1:1:M:M chain ' . $rs->result_class, ; -is_deeply - $rs->search({}, { +cmp_deeply + [ $rs->search({}, { columns => { 'artist' => 'me.artist', 'title' => 'me.title', @@ -338,99 +275,99 @@ is_deeply }, join => { single_track => { cd => { artist => { cds => 'tracks' } } } }, order_by => [qw/me.cdid artist.artistid cds.cdid tracks.trackid/], - collapse => {}, #hashref to keep older DBIC versions happy (doesn't actually work) - })->all_hri, + collapse => 1, + })->all ], [ { - artist => 1, - single_track => undef, - title => "Magnetic Fields", - year => 1981 + artist => 1, title => "Magnetic Fields", year => 1981, single_track => undef, }, { - artist => 1, - single_track => undef, - title => "Oxygene", - year => 1976 + artist => 1, title => "Oxygene", year => 1976, single_track => undef, }, { - artist => 1, - single_track => { + artist => 1, title => "Equinoxe", year => 1978, single_track => { cd => { artist => { - artistid => 1, - cds => [ + artistid => 1, cds => [ { - cdid => 1, - tracks => [ - { - title => "m1" - }, - { - title => "m2" - }, - { - title => "m3" - }, - { - title => "m4" - } + cdid => 1, tracks => [ + { title => "m1" }, + { title => "m2" }, + { title => "m3" }, + { title => "m4" }, ] }, { - cdid => 2, - tracks => [ - { - title => "o2" - }, - { - title => "o1" - } + cdid => 2, tracks => [ + { title => "o2" }, + { title => "o1" }, ] }, { - cdid => 3, - tracks => [ - { - title => "e1" - }, - { - title => "e2" - }, - { - title => "e3" - } + cdid => 3, tracks => [ + { title => "e1" }, + { title => "e2" }, + { title => "e3" }, ] }, { - cdid => 4, - tracks => [] + cdid => 4, tracks => [], }, { - cdid => 5, - tracks => [] + cdid => 5, tracks => [], } ] } } }, - title => "Equinoxe", - year => 1978 }, { - artist => 1, - single_track => undef, - title => "fuzzy_1", - year => 1977 + artist => 1, title => "fuzzy_1", year => 1977, single_track => undef, }, { - artist => 1, - single_track => undef, - title => "fuzzy_2", - year => 1977 + artist => 1, title => "fuzzy_2", year => 1977, single_track => undef, } ], - 'collapsing 1:1:1:M:M chain', + 'collapsing 1:1:1:M:M chain ' . $rs->result_class, +; + +cmp_deeply + [ $rs->search_rs ( + { + 'tracks.title' => 'e2', + 'cds.title' => 'Oxygene', + }, + { + collapse => 1, + join => [ + 'tracks', + { single_track => { cd => 'mandatory_artwork' } }, + { artist => { cds => 'mandatory_artwork'} }, + ], + columns => { + cdid => 'cdid', + 'single_track.cd.mandatory_artwork.cd_id' => 'mandatory_artwork.cd_id', + 'artist.cds.mandatory_artwork.cd_id' => 'mandatory_artwork_2.cd_id', + }, + }, + )->all ], + [ + { + cdid => 3, + single_track => { + cd => { + mandatory_artwork => { cd_id => 2 }, + }, + }, + artist => { + cds => [ + { mandatory_artwork => { cd_id => 2 } } + ] + }, + }, + ], ; +} + done_testing;