Added list of constants exported to the docs.
[dbsrgits/SQL-Translator.git] / t / 22xml-xmi-parser-visibility.t
CommitLineData
215c6c52 1#!/usr/bin/perl -w
2# vim:filetype=perl
3
4# Before `make install' is performed this script should be runnable with
5# `make test'. After `make install' it should work as `perl test.pl'
6
7#
fd5abbd7 8# Tests the visibility arg.
215c6c52 9#
10
11use strict;
fd5abbd7 12use FindBin qw/$Bin/;
215c6c52 13use Data::Dumper;
fd5abbd7 14
15# run test with -d for debug
215c6c52 16my %opt;
17BEGIN { map { $opt{$_}=1 if s/^-// } @ARGV; }
18use constant DEBUG => (exists $opt{d} ? 1 : 0);
19
fd5abbd7 20use Test::More;
21use Test::Exception;
22use SQL::Translator;
23use SQL::Translator::Schema::Constants;
215c6c52 24
215c6c52 25
26plan tests => 8;
27
215c6c52 28my $testschema = "$Bin/data/xmi/Foo.poseidon2.xmi";
29die "Can't find test schema $testschema" unless -e $testschema;
215c6c52 30
215c6c52 31my @testd = (
32 "" => [qw/Foo PrivateFoo Recording CD Track ProtectedFoo/],
33 [qw/fooid name protectedname privatename/],
34 "public" => [qw/Foo Recording CD Track/],
35 [qw/fooid name /],
36 "protected" => [qw/Foo Recording CD Track ProtectedFoo/],
37 [qw/fooid name protectedname/],
38 "private" => [qw/Foo PrivateFoo Recording CD Track ProtectedFoo/],
39 [qw/fooid name protectedname privatename/],
40);
41 while ( my ($vis,$tables,$foofields) = splice @testd,0,3 ) {
42 my $obj;
43 $obj = SQL::Translator->new(
44 filename => $testschema,
45 from => 'XML-XMI',
46 to => 'MySQL',
47 debug => DEBUG,
48 show_warnings => 1,
215c6c52 49 parser_args => {
50 visibility => $vis,
51 },
52 );
53 my $sql = $obj->translate;
fd5abbd7 54 print $sql if DEBUG;
215c6c52 55 my $scma = $obj->schema;
56
fd5abbd7 57 # Tables from classes
58 my @tblnames = map {$_->name} $scma->get_tables;
215c6c52 59 is_deeply( \@tblnames, $tables, "Tables with visibility => '$vis'");
60
fd5abbd7 61 # Fields from attributes
215c6c52 62 my @fldnames = map {$_->name} $scma->get_table("Foo")->get_fields;
63 is_deeply( \@fldnames, $foofields, "Foo fields with visibility => '$vis'");
215c6c52 64}