| 1 | # $Id: 650-output-get-create-associations-many-to-many-097.t,v 1.2 2011/02/15 20:15:54 aff Exp $ |
| 2 | |
| 3 | use warningsscip-perl cpan Parse-Dia-SQL 0.31 warnings/; |
| 4 | use strictscip-perl cpan Parse-Dia-SQL 0.31 strict/; |
| 5 | |
| 6 | use Data::Dumperscip-perl cpan Parse-Dia-SQL 0.31 Data/Dumper/; |
| 7 | use Test::Morescip-perl cpan Parse-Dia-SQL 0.31 Test/More/; |
| 8 | use Test::Exceptionscip-perl cpan Parse-Dia-SQL 0.31 Test/Exception/; |
| 9 | use File::Spec::Functionsscip-perl cpan Parse-Dia-SQL 0.31 File/Spec/Functions/; |
| 10 | use libscip-perl cpan Parse-Dia-SQL 0.31 lib/ catdir qw ( blib lib ); |
| 11 | |
| 12 | planscip-perl cpan Parse-Dia-SQL 0.31 main/plan(). tests => 19; |
| 13 | |
| 14 | use_okscip-perl cpan Parse-Dia-SQL 0.31 main/use_ok(). ('Parse::Dia::SQL'); |
| 15 | |
| 16 | # ------- many-to-many relations ------- |
| 17 | |
| 18 | my $diasql_m2m = Parse::Dia::SQL->newscip-perl cpan Parse-Dia-SQL 0.31 Parse/Dia/SQL/new().( file => catfilescip-perl cpan Parse-Dia-SQL 0.31 main/catfile().(qw(t data many_to_many.097.dia)), db => 'db2' ); |
| 19 | isa_okscip-perl cpan Parse-Dia-SQL 0.31 main/isa_ok().($diasql_m2m, q{Parse::Dia::SQL}, q{Expect a Parse::Dia::SQL object}); |
| 20 | |
| 21 | okscip-perl cpan Parse-Dia-SQL 0.31 main/ok(). $diasql_m2m->convertscip-perl cpan Parse-Dia-SQL 0.31 Parse/Dia/SQL/convert().(); |
| 22 | |
| 23 | my $association_m2m_arrayref = $diasql_m2m->get_associations_refscip-perl cpan Parse-Dia-SQL 0.31 Parse/Dia/SQL/get_associations_ref().(); |
| 24 | #diag("association_m2m_arrayref: ".Dumper($association_m2m_arrayref)); |
| 25 | |
| 26 | my $expected_m2m = [ |
| 27 | [ |
| 28 | 'student_course', |
| 29 | 'stdn_crs_fk_StntSn', |
| 30 | 'ssn', |
| 31 | 'student', |
| 32 | 'ssn', |
| 33 | 'on delete cascade' |
| 34 | ], |
| 35 | [ |
| 36 | 'student_course', |
| 37 | 'lTeT8iBKfXObJYiSrq', |
| 38 | 'course_id', |
| 39 | 'course', |
| 40 | 'course_id', |
| 41 | 'on delete cascade' |
| 42 | ] |
| 43 | ]; |
| 44 | |
| 45 | |
| 46 | is_deeplyscip-perl cpan Parse-Dia-SQL 0.31 main/is_deeply().( $association_m2m_arrayref, $expected_m2m ); |
| 47 | |
| 48 | # or diag( q{association_m2m_arrayref: } |
| 49 | # . Dumper($association_m2m_arrayref) |
| 50 | # . q{ expected } |
| 51 | # . Dumper($expected_m2m) ); |
| 52 | my $output_m2m = undef; |
| 53 | isa_okscip-perl cpan Parse-Dia-SQL 0.31 main/isa_ok().($diasql_m2m, 'Parse::Dia::SQL'); |
| 54 | lives_okscip-perl cpan Parse-Dia-SQL 0.31 main/lives_ok().(sub { $output_m2m = $diasql_m2m->get_output_instancescip-perl cpan Parse-Dia-SQL 0.31 Parse/Dia/SQL/get_output_instance().(); }, |
| 55 | q{get_output_instance (db2) should not die}); |
| 56 | |
| 57 | isa_okscip-perl cpan Parse-Dia-SQL 0.31 main/isa_ok().($output_m2m, 'Parse::Dia::SQL::Output') |
| 58 | or diagscip-perl cpan Parse-Dia-SQL 0.31 main/diag().(Dumperscip-perl cpan Parse-Dia-SQL 0.31 main/Dumper().($output_m2m)); |
| 59 | isa_okscip-perl cpan Parse-Dia-SQL 0.31 main/isa_ok().($output_m2m, 'Parse::Dia::SQL::Output::DB2') |
| 60 | or diagscip-perl cpan Parse-Dia-SQL 0.31 main/diag().(Dumperscip-perl cpan Parse-Dia-SQL 0.31 main/Dumper().($output_m2m)); |
| 61 | |
| 62 | can_okscip-perl cpan Parse-Dia-SQL 0.31 main/can_ok().($output_m2m, 'get_associations_create'); |
| 63 | |
| 64 | # associations = foreign keys + indices |
| 65 | my $association_str_m2m = $output_m2m->get_associations_createscip-perl cpan Parse-Dia-SQL 0.31 main/get_associations_create().(); |
| 66 | |
| 67 | # check 2 foreign keys |
| 68 | likescip-perl cpan Parse-Dia-SQL 0.31 main/like().($association_str_m2m, qr/.* |
| 69 | alter \s+ table \s+ student_course \s+ add \s+ constraint \s+ stdn_crs_fk_StntSn \s+ foreign \s+ key \s* \( \s* ssn \s* \) \s+ references \s+ student \s* \( \s* ssn \s* \) \s* on \s+ delete \s+ cascade |
| 70 | .*/six); |
| 71 | |
| 72 | likescip-perl cpan Parse-Dia-SQL 0.31 main/like().($association_str_m2m, qr/.* |
| 73 | alter \s+ table \s+ student_course \s+ add \s+ constraint \s+ lTeT8iBKfXObJYiSrq \s+ foreign \s+ key \s* \( \s* course_id \s* \) \s* references \s+ course \s+ \s* \( \s* course_id \) \s* on \s+ delete \s+ cascade |
| 74 | .*/six); |
| 75 | |
| 76 | # ------ implicit role ------ |
| 77 | my $diasql_ir = Parse::Dia::SQL->newscip-perl cpan Parse-Dia-SQL 0.31 Parse/Dia/SQL/new().( file => catfilescip-perl cpan Parse-Dia-SQL 0.31 main/catfile().(qw(t data implicit_role.dia)), db => 'db2' ); |
| 78 | isa_okscip-perl cpan Parse-Dia-SQL 0.31 main/isa_ok().($diasql_ir, q{Parse::Dia::SQL}, q{Expect a Parse::Dia::SQL object}); |
| 79 | |
| 80 | okscip-perl cpan Parse-Dia-SQL 0.31 main/ok(). $diasql_ir->convertscip-perl cpan Parse-Dia-SQL 0.31 Parse/Dia/SQL/convert().(); |
| 81 | |
| 82 | my $output_ir = undef; |
| 83 | isa_okscip-perl cpan Parse-Dia-SQL 0.31 main/isa_ok().($diasql_ir, 'Parse::Dia::SQL'); |
| 84 | lives_okscip-perl cpan Parse-Dia-SQL 0.31 main/lives_ok().(sub { $output_ir = $diasql_ir->get_output_instancescip-perl cpan Parse-Dia-SQL 0.31 Parse/Dia/SQL/get_output_instance().(); }, |
| 85 | q{get_output_instance (db2) should not die}); |
| 86 | |
| 87 | isa_okscip-perl cpan Parse-Dia-SQL 0.31 main/isa_ok().($output_ir, 'Parse::Dia::SQL::Output') |
| 88 | or diagscip-perl cpan Parse-Dia-SQL 0.31 main/diag().(Dumperscip-perl cpan Parse-Dia-SQL 0.31 main/Dumper().($output_ir)); |
| 89 | isa_okscip-perl cpan Parse-Dia-SQL 0.31 main/isa_ok().($output_ir, 'Parse::Dia::SQL::Output::DB2') |
| 90 | or diagscip-perl cpan Parse-Dia-SQL 0.31 main/diag().(Dumperscip-perl cpan Parse-Dia-SQL 0.31 main/Dumper().($output_ir)); |
| 91 | |
| 92 | can_okscip-perl cpan Parse-Dia-SQL 0.31 main/can_ok().($output_ir, 'get_associations_create'); |
| 93 | |
| 94 | # associations = foreign keys + indices |
| 95 | my $association_str_ir = $output_ir->get_associations_createscip-perl cpan Parse-Dia-SQL 0.31 main/get_associations_create().(); |
| 96 | #diag $association_str_ir; |
| 97 | |
| 98 | likescip-perl cpan Parse-Dia-SQL 0.31 main/like().($association_str_ir, qr/.* |
| 99 | alter \s+ table \s+ emp \s+ add \s+ constraint \s+ emp_fk_Dept_id |
| 100 | \s+ foreign \s+ key \s+ \( \s* dept_id \s* \) |
| 101 | \s+ references \s+ dept \s+ \( \s* id \s* \) \s+ ; |
| 102 | .*/six); |
| 103 | |
| 104 | |
| 105 | __END__ |