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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28
6d33f75c6e1f ORM in works
Sergey
parents:
diff changeset
1 package Test::ORM::Schema;
6d33f75c6e1f ORM in works
Sergey
parents:
diff changeset
2 use strict;
6d33f75c6e1f ORM in works
Sergey
parents:
diff changeset
3 use warnings;
30
dd4d72600c69 ORM in works
Sergey
parents: 28
diff changeset
4 use base qw(IMPL::Test::Unit);
28
6d33f75c6e1f ORM in works
Sergey
parents:
diff changeset
5
44
Sergey
parents: 38
diff changeset
6 require IMPL::SQL::Schema::Traits::mysql;
Sergey
parents: 38
diff changeset
7
30
dd4d72600c69 ORM in works
Sergey
parents: 28
diff changeset
8 __PACKAGE__->PassThroughArgs;
dd4d72600c69 ORM in works
Sergey
parents: 28
diff changeset
9
dd4d72600c69 ORM in works
Sergey
parents: 28
diff changeset
10 use IMPL::Test qw(test failed);
dd4d72600c69 ORM in works
Sergey
parents: 28
diff changeset
11
38
d660fb38b7cc small fixes
Sergey
parents: 31
diff changeset
12 require IMPL::ORM::Schema::TransformToSQL;
d660fb38b7cc small fixes
Sergey
parents: 31
diff changeset
13
30
dd4d72600c69 ORM in works
Sergey
parents: 28
diff changeset
14 test ExtractClassSchema => sub {
dd4d72600c69 ORM in works
Sergey
parents: 28
diff changeset
15 my ($this) = @_;
dd4d72600c69 ORM in works
Sergey
parents: 28
diff changeset
16
dd4d72600c69 ORM in works
Sergey
parents: 28
diff changeset
17 my $schema = Test::ORM::Schema::Data::User->ormGetSchema('Test::ORM::Schema::Data');
dd4d72600c69 ORM in works
Sergey
parents: 28
diff changeset
18 failed "Wrong number of the elements","expected: 4","got: ".$schema->childNodes->Count unless $schema->childNodes->Count == 4;
dd4d72600c69 ORM in works
Sergey
parents: 28
diff changeset
19
dd4d72600c69 ORM in works
Sergey
parents: 28
diff changeset
20 return 1;
dd4d72600c69 ORM in works
Sergey
parents: 28
diff changeset
21 };
dd4d72600c69 ORM in works
Sergey
parents: 28
diff changeset
22
dd4d72600c69 ORM in works
Sergey
parents: 28
diff changeset
23 test StaticSchema => sub {
dd4d72600c69 ORM in works
Sergey
parents: 28
diff changeset
24 my ($this) = @_;
dd4d72600c69 ORM in works
Sergey
parents: 28
diff changeset
25
dd4d72600c69 ORM in works
Sergey
parents: 28
diff changeset
26 my $schema = Test::ORM::Schema::Data->instance;
dd4d72600c69 ORM in works
Sergey
parents: 28
diff changeset
27
dd4d72600c69 ORM in works
Sergey
parents: 28
diff changeset
28 return 1;
dd4d72600c69 ORM in works
Sergey
parents: 28
diff changeset
29 };
dd4d72600c69 ORM in works
Sergey
parents: 28
diff changeset
30
44
Sergey
parents: 38
diff changeset
31 test GenerateSQL => sub {
38
d660fb38b7cc small fixes
Sergey
parents: 31
diff changeset
32 my $sqlSchema = IMPL::ORM::Schema::TransformToSQL->Std->Transform(Test::ORM::Schema::Data->instance)
d660fb38b7cc small fixes
Sergey
parents: 31
diff changeset
33 or failed("Failed to transform a schema");
44
Sergey
parents: 38
diff changeset
34
Sergey
parents: 38
diff changeset
35 my $sqlEmpty = new IMPL::SQL::Schema(Name => 'empty');
Sergey
parents: 38
diff changeset
36
Sergey
parents: 38
diff changeset
37 my $traits = IMPL::SQL::Schema::Traits::mysql->new(
Sergey
parents: 38
diff changeset
38 SrcSchema => $sqlEmpty,
Sergey
parents: 38
diff changeset
39 DstSchema => $sqlSchema
Sergey
parents: 38
diff changeset
40 );
Sergey
parents: 38
diff changeset
41
Sergey
parents: 38
diff changeset
42 $traits->UpdateSchema();
Sergey
parents: 38
diff changeset
43
Sergey
parents: 38
diff changeset
44 print "$_\n" foreach $traits->Handler->Sql;
Sergey
parents: 38
diff changeset
45
Sergey
parents: 38
diff changeset
46 $sqlEmpty->Dispose;
38
d660fb38b7cc small fixes
Sergey
parents: 31
diff changeset
47 $sqlSchema->Dispose;
d660fb38b7cc small fixes
Sergey
parents: 31
diff changeset
48 };
d660fb38b7cc small fixes
Sergey
parents: 31
diff changeset
49
28
6d33f75c6e1f ORM in works
Sergey
parents:
diff changeset
50
6d33f75c6e1f ORM in works
Sergey
parents:
diff changeset
51 package Test::ORM::Schema::Data::User;
6d33f75c6e1f ORM in works
Sergey
parents:
diff changeset
52 use base qw(IMPL::ORM::Object);
6d33f75c6e1f ORM in works
Sergey
parents:
diff changeset
53 use IMPL::Class::Property;
6d33f75c6e1f ORM in works
Sergey
parents:
diff changeset
54
6d33f75c6e1f ORM in works
Sergey
parents:
diff changeset
55 BEGIN {
6d33f75c6e1f ORM in works
Sergey
parents:
diff changeset
56 public property Name => prop_all, { type => 'String' }; # Field
6d33f75c6e1f ORM in works
Sergey
parents:
diff changeset
57 public property Id => prop_all, { type => 'String' }; # Field
6d33f75c6e1f ORM in works
Sergey
parents:
diff changeset
58 public property Roles => prop_all | prop_list, { type=> 'Test::ORM::Schema::Data::Role'}; # HasMany
6d33f75c6e1f ORM in works
Sergey
parents:
diff changeset
59 }
6d33f75c6e1f ORM in works
Sergey
parents:
diff changeset
60
6d33f75c6e1f ORM in works
Sergey
parents:
diff changeset
61 package Test::ORM::Schema::Data::Role;
6d33f75c6e1f ORM in works
Sergey
parents:
diff changeset
62 use base qw(IMPL::ORM::Object);
6d33f75c6e1f ORM in works
Sergey
parents:
diff changeset
63 use IMPL::Class::Property;
6d33f75c6e1f ORM in works
Sergey
parents:
diff changeset
64
6d33f75c6e1f ORM in works
Sergey
parents:
diff changeset
65 BEGIN {
6d33f75c6e1f ORM in works
Sergey
parents:
diff changeset
66 public property Name => prop_all, { type => 'String' }; # Field
6d33f75c6e1f ORM in works
Sergey
parents:
diff changeset
67 }
6d33f75c6e1f ORM in works
Sergey
parents:
diff changeset
68
6d33f75c6e1f ORM in works
Sergey
parents:
diff changeset
69 package Test::ORM::Schema::Data::Session;
6d33f75c6e1f ORM in works
Sergey
parents:
diff changeset
70 use base qw(IMPL::ORM::Object);
6d33f75c6e1f ORM in works
Sergey
parents:
diff changeset
71 use IMPL::Class::Property;
6d33f75c6e1f ORM in works
Sergey
parents:
diff changeset
72 use IMPL::ORM::Helpers qw(Map);
6d33f75c6e1f ORM in works
Sergey
parents:
diff changeset
73
6d33f75c6e1f ORM in works
Sergey
parents:
diff changeset
74 BEGIN {
6d33f75c6e1f ORM in works
Sergey
parents:
diff changeset
75 public property Id => prop_get, { type => 'String' }; # Field
6d33f75c6e1f ORM in works
Sergey
parents:
diff changeset
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
6d33f75c6e1f ORM in works
Sergey
parents:
diff changeset
79 }
6d33f75c6e1f ORM in works
Sergey
parents:
diff changeset
80
6d33f75c6e1f ORM in works
Sergey
parents:
diff changeset
81 package Test::ORM::Schema::Data;
6d33f75c6e1f ORM in works
Sergey
parents:
diff changeset
82 use base qw(IMPL::ORM::Schema);
6d33f75c6e1f ORM in works
Sergey
parents:
diff changeset
83
6d33f75c6e1f ORM in works
Sergey
parents:
diff changeset
84 __PACKAGE__->ValueTypes (
38
d660fb38b7cc small fixes
Sergey
parents: 31
diff changeset
85 String => 'IMPL::ORM::Value::String',
d660fb38b7cc small fixes
Sergey
parents: 31
diff changeset
86 DateTime => 'IMPL::ORM::Value::DateTime',
d660fb38b7cc small fixes
Sergey
parents: 31
diff changeset
87 Integer => 'IMPL::ORM::Value::Inetger',
d660fb38b7cc small fixes
Sergey
parents: 31
diff changeset
88 Float => 'IMPL::ORM::Value::Float',
d660fb38b7cc small fixes
Sergey
parents: 31
diff changeset
89 Decimal => 'IMPL::ORM::Value::Decimal'
28
6d33f75c6e1f ORM in works
Sergey
parents:
diff changeset
90 );
6d33f75c6e1f ORM in works
Sergey
parents:
diff changeset
91
30
dd4d72600c69 ORM in works
Sergey
parents: 28
diff changeset
92 __PACKAGE__->usePrefix(__PACKAGE__);
dd4d72600c69 ORM in works
Sergey
parents: 28
diff changeset
93 __PACKAGE__->Classes qw(
dd4d72600c69 ORM in works
Sergey
parents: 28
diff changeset
94 User
dd4d72600c69 ORM in works
Sergey
parents: 28
diff changeset
95 Role
dd4d72600c69 ORM in works
Sergey
parents: 28
diff changeset
96 Session
dd4d72600c69 ORM in works
Sergey
parents: 28
diff changeset
97 );
dd4d72600c69 ORM in works
Sergey
parents: 28
diff changeset
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
6d33f75c6e1f ORM in works
Sergey
parents:
diff changeset
101 1;