PObject/Test/Types.pm

filter: Statementstmt 100% 103 / 103 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 1 totaltotal 99.1% 114 / 115 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« PObject/Type/VARCHAR.pm ↑ Summary
1 package Class::PObject::Test::Types;
2  
3 # Types.pm,v 1.7 2005/01/26 19:21:58 sherzodr Exp
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 #use diagnostics;
7 1 ▶use Test::More;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use vars ('$VERSION', '@ISA');
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 plan(tests => 46);
12 1 ▶ use_ok("Class::PObject");
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶ use_ok("Class::PObject::Test");
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶ use_ok("Class::PObject::Type");
Subroutine BEGIN: called CC=1 SCAR=0.0
15 }
16  
17 1 @ISA = ('Class::PObject::Test');
18 1 $VERSION = '1.03';
19  
20  
21 1 ▶sub run {
Subroutine run: called CC=1 SCAR=0.0
Pod undocumented
22 1 my $self = shift;
23  
24 pobject User => {
25 columns => ['id', 'name', 'login', 'psswd', 'activation_key'],
26 driver => $self->{driver},
27 # datasource => $self->{datasource},
28 1 serializer => 'storable',
29 tmap => {
30 login => 'CHAR(18)',
31 psswd => 'ENCRYPT',
32 name => 'VARCHAR(40)',
33 id => 'INTEGER',
34 activation_key => 'MD5'
35 }
36 };
37 1 ok(1);
38  
39  
40 {
41 1 package User;
42 5 ▶ *pobject_init = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
43 5 $_[0]->set_datasource( $self->{datasource} );
44 }
45 1 }
46  
47  
48 ################
49 #
50 # Creating a new user
51 #
52 1 my $u = new User();
53 1 ok(ref $u);
54 1 $u->name("Sherzod Ruzmetov");
55 1 $u->login("sherzodr");
56 1 $u->psswd("marley01");
57 1 $u->activation_key("geek");
58  
59 #print $u->dump;
60 #exit(0);
61  
62 ################
63 #
64 # checking integrity of data before saving to disk
65 #
66 1 ok($u->name eq "Sherzod Ruzmetov");
67 1 ok($u->login eq "sherzodr");
68 1 ok($u->psswd eq "marley01", ''.$u->psswd);
69 1 ok($u->activation_key eq "geek", ''.$u->activation_key);
70  
71 1 ok(ref($u->name) eq 'VARCHAR');
72 1 ok(ref($u->login) eq 'CHAR');
73 TODO: {
74 # If a value of a column is undef, even ref() doesn't work.
75 # Should it?
76 1 local $TODO = "Not sure if it is a bug or a feature";
77 1 ok(ref($u->id) eq 'INTEGER');
78 }
79
80 1 ok(ref($u->psswd) eq 'ENCRYPT');
81 1 ok(ref($u->activation_key) eq 'MD5');
82  
83 #print $u->dump;
84  
85 # let's check if we can assign objects directly
86 1 my $name = VARCHAR->new(id=>"Sherzod Ruzmetov (e)", args=>40);
87 1 ok($name, $name);
88 1 $u->name( $name );
89 1 ok($u->name eq "Sherzod Ruzmetov (e)");
90 1 ok(ref($u->name) eq "VARCHAR", ref($u->name));
91  
92 #print $u->dump;
93  
94 1 $u->name( "Sherzod Ruzmetov" );
95 1 ok($u->name eq "Sherzod Ruzmetov", ''.$u->name);
96 1 ok(ref($u->name) eq "VARCHAR", ref($u->name));
97  
98 #print $u->dump;
99  
100 1 ok(my $id = $u->save, $u->errstr);
101  
102 1 $u = undef;
103  
104 1 $u = User->load($id);
105 1 ok($u);
106  
107 #print $u->dump;
108  
109 ################
110 #
111 # checking integrity of data after loaded from disk
112 #
113 1 ok($u->name eq "Sherzod Ruzmetov");
114 1 ok($u->login eq "sherzodr");
115 1 ok($u->psswd eq "marley01", ''.$u->psswd);
116  
117 1 ok(ref($u->name) eq 'VARCHAR');
118 1 ok(ref($u->login) eq 'CHAR');
119 1 ok(ref($u->id) eq 'INTEGER');
120 1 ok(ref($u->psswd) eq 'ENCRYPT');
121  
122 ################
123 #
124 # Updating the values again
125 #
126 1 $u->name("Sherzod Ruzmetov (e)");
127 1 $u->psswd("marley02)");
128  
129 1 ok($u->psswd eq "marley02", ''.$u->psswd);
130 1 ok($u->name eq "Sherzod Ruzmetov (e)");
131 1 ok($u->activation_key eq "geek");
132 1 ok(ref($u->psswd) eq 'ENCRYPT');
133 1 ok(ref($u->activation_key), 'MD5');
134 1 ok($u->save == $id, $u->errstr);
135  
136  
137 ################
138 #
139 # Checking col. member functions (inside Type.pm)
140 #
141 1 my $substr = $u->name()->substr(0, 6);
142 1 ok($substr eq "Sherzo", $substr);
143  
144 1 my $lcfirst = $u->name()->lcfirst();
145 1 ok($lcfirst eq 'sherzod Ruzmetov (e)');
146  
147 1 my $ucfirst = $u->name()->ucfirst();
148 1 ok($ucfirst eq 'Sherzod Ruzmetov (e)');
149  
150 1 my $lc = $u->name()->lc();
151 1 ok($lc eq 'sherzod ruzmetov (e)');
152  
153 1 my $uc = $u->name()->uc();
154 1 ok($uc eq 'SHERZOD RUZMETOV (E)');
155  
156  
157 ################
158 #
159 # Checking load(\%terms, undef) syntax
160 #
161
162 1 $u = User->load({login=>'sherzodr'});
163 1 ok($u);
164 1 ok($u->psswd eq "marley02");
165 1 ok($u->activation_key eq "geek");
166  
167 1 ok(User->count == 1);
168 1 ok(User->remove_all());
169 1 ok(User->count == 0);
170  
171 1 ok(User->drop_datasource);
172 }
173  
174  
175  
176  
177  
178  
179 package VARCHAR;
180 1 ▶use vars ('@ISA');
Subroutine BEGIN: called CC=1 SCAR=0.0
181 1 ▶use Class::PObject::Type::VARCHAR;
Subroutine BEGIN: called CC=1 SCAR=0.0
182 1 @ISA = ("Class::PObject::Type::VARCHAR");
183  
184  
185 1 1;
186 __END__
« PObject/Type/VARCHAR.pm ↑ Summary