Mercurial > pub > Impl
annotate _test/Test/ORM/Schema.pm @ 47:a9b70d836b28
Web::Application development (request controller)
Security development
author | Sergey |
---|---|
date | Tue, 23 Feb 2010 22:57:16 +0300 |
parents | 32d2350fccf9 |
children | 16ada169ca75 |
rev | line source |
---|---|
28 | 1 package Test::ORM::Schema; |
2 use strict; | |
3 use warnings; | |
30 | 4 use base qw(IMPL::Test::Unit); |
28 | 5 |
44 | 6 require IMPL::SQL::Schema::Traits::mysql; |
7 | |
30 | 8 __PACKAGE__->PassThroughArgs; |
9 | |
10 use IMPL::Test qw(test failed); | |
11 | |
38 | 12 require IMPL::ORM::Schema::TransformToSQL; |
13 | |
30 | 14 test ExtractClassSchema => sub { |
15 my ($this) = @_; | |
16 | |
17 my $schema = Test::ORM::Schema::Data::User->ormGetSchema('Test::ORM::Schema::Data'); | |
18 failed "Wrong number of the elements","expected: 4","got: ".$schema->childNodes->Count unless $schema->childNodes->Count == 4; | |
19 | |
20 return 1; | |
21 }; | |
22 | |
23 test StaticSchema => sub { | |
24 my ($this) = @_; | |
25 | |
26 my $schema = Test::ORM::Schema::Data->instance; | |
27 | |
28 return 1; | |
29 }; | |
30 | |
44 | 31 test GenerateSQL => sub { |
38 | 32 my $sqlSchema = IMPL::ORM::Schema::TransformToSQL->Std->Transform(Test::ORM::Schema::Data->instance) |
33 or failed("Failed to transform a schema"); | |
44 | 34 |
35 my $sqlEmpty = new IMPL::SQL::Schema(Name => 'empty'); | |
36 | |
37 my $traits = IMPL::SQL::Schema::Traits::mysql->new( | |
38 SrcSchema => $sqlEmpty, | |
39 DstSchema => $sqlSchema | |
40 ); | |
41 | |
42 $traits->UpdateSchema(); | |
43 | |
44 print "$_\n" foreach $traits->Handler->Sql; | |
45 | |
46 $sqlEmpty->Dispose; | |
38 | 47 $sqlSchema->Dispose; |
48 }; | |
49 | |
28 | 50 |
51 package Test::ORM::Schema::Data::User; | |
52 use base qw(IMPL::ORM::Object); | |
53 use IMPL::Class::Property; | |
54 | |
55 BEGIN { | |
56 public property Name => prop_all, { type => 'String' }; # Field | |
57 public property Id => prop_all, { type => 'String' }; # Field | |
58 public property Roles => prop_all | prop_list, { type=> 'Test::ORM::Schema::Data::Role'}; # HasMany | |
59 } | |
60 | |
61 package Test::ORM::Schema::Data::Role; | |
62 use base qw(IMPL::ORM::Object); | |
63 use IMPL::Class::Property; | |
64 | |
65 BEGIN { | |
66 public property Name => prop_all, { type => 'String' }; # Field | |
67 } | |
68 | |
69 package Test::ORM::Schema::Data::Session; | |
70 use base qw(IMPL::ORM::Object); | |
71 use IMPL::Class::Property; | |
72 use IMPL::ORM::Helpers qw(Map); | |
73 | |
74 BEGIN { | |
75 public property Id => prop_get, { type => 'String' }; # Field | |
76 public property User => prop_get, { type => 'Test::ORM::Schema::Data::User' }; # HasOne | |
31
d59526f6310e
Small fixes to Test framework (correct handlinf of the compilation errors in the test units)
Sergey
parents:
30
diff
changeset
|
77 #public property Data => prop_all, { type => Map( 'String','String' ) }; # HasOne |
d59526f6310e
Small fixes to Test framework (correct handlinf of the compilation errors in the test units)
Sergey
parents:
30
diff
changeset
|
78 public property AccessTime => prop_get, { type => 'DateTime' }; # Field |
28 | 79 } |
80 | |
81 package Test::ORM::Schema::Data; | |
82 use base qw(IMPL::ORM::Schema); | |
83 | |
84 __PACKAGE__->ValueTypes ( | |
38 | 85 String => 'IMPL::ORM::Value::String', |
86 DateTime => 'IMPL::ORM::Value::DateTime', | |
87 Integer => 'IMPL::ORM::Value::Inetger', | |
88 Float => 'IMPL::ORM::Value::Float', | |
89 Decimal => 'IMPL::ORM::Value::Decimal' | |
28 | 90 ); |
91 | |
30 | 92 __PACKAGE__->usePrefix(__PACKAGE__); |
93 __PACKAGE__->Classes qw( | |
94 User | |
95 Role | |
96 Session | |
97 ); | |
98 | |
31
d59526f6310e
Small fixes to Test framework (correct handlinf of the compilation errors in the test units)
Sergey
parents:
30
diff
changeset
|
99 __PACKAGE__->CompleteSchema; |
d59526f6310e
Small fixes to Test framework (correct handlinf of the compilation errors in the test units)
Sergey
parents:
30
diff
changeset
|
100 |
28 | 101 1; |