| 1 | package Class::PObject::Test::HAS_A; | ||||||||||
| 2 | |||||||||||
| 3 | # HAS_A.pm,v 1.5 2003/11/06 01:21:10 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 => 37); | |||||||||
| 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 | } | ||||||||||
| 15 | |||||||||||
| 16 | 1 | @ISA = ('Class::PObject::Test'); | |||||||||
| 17 | 1 | $VERSION = '1.00'; | |||||||||
| 18 | |||||||||||
| 19 | |||||||||||
| 20 | 1 | ▶ | sub run { | ||||||||
|
Subroutine
run: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||
| 21 | 1 | my $self = shift; | |||||||||
| 22 | |||||||||||
| 23 | pobject 'PO::Author' => { | ||||||||||
| 24 | columns => ['id', 'name'], | ||||||||||
| 25 | driver => $self->{driver}, | ||||||||||
| 26 | datasource => $self->{datasource}, | ||||||||||
| 27 | 1 | serializer => 'storable' | |||||||||
| 28 | }; | ||||||||||
| 29 | 1 | ok(1); | |||||||||
| 30 | |||||||||||
| 31 | pobject 'PO::Article' => { | ||||||||||
| 32 | columns => ['id', 'title', 'author'], | ||||||||||
| 33 | driver => $self->{driver}, | ||||||||||
| 34 | datasource => $self->{datasource}, | ||||||||||
| 35 | 1 | serializer => 'storable', | |||||||||
| 36 | tmap => { | ||||||||||
| 37 | author => 'PO::Author' | ||||||||||
| 38 | } | ||||||||||
| 39 | }; | ||||||||||
| 40 | 1 | ok(1); | |||||||||
| 41 | |||||||||||
| 42 | ################ | ||||||||||
| 43 | # | ||||||||||
| 44 | # Creating a new Author | ||||||||||
| 45 | # | ||||||||||
| 46 | 1 | my $author = new PO::Author(); | |||||||||
| 47 | |||||||||||
| 48 | ################ | ||||||||||
| 49 | # | ||||||||||
| 50 | # Is Segmentation fault still persistent? | ||||||||||
| 51 | # | ||||||||||
| 52 | 1 | ▶ | ok($author->name ? 0 : 1 ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | 1 | ▶ | ok($author->id ? 0 : 1 ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | |||||||||||
| 55 | |||||||||||
| 56 | ################ | ||||||||||
| 57 | # | ||||||||||
| 58 | # Filling in details of the author | ||||||||||
| 59 | # | ||||||||||
| 60 | 1 | $author->name("Sherzod Ruzmetov"); | |||||||||
| 61 | 1 | ok($author->name eq "Sherzod Ruzmetov"); | |||||||||
| 62 | 1 | ok(my $author_id = $author->save, $author->errstr); | |||||||||
| 63 | |||||||||||
| 64 | 1 | $author = undef; | |||||||||
| 65 | |||||||||||
| 66 | ################ | ||||||||||
| 67 | # | ||||||||||
| 68 | # Creating new article | ||||||||||
| 69 | # | ||||||||||
| 70 | 1 | my $article = new PO::Article(); | |||||||||
| 71 | #print $article->dump; | ||||||||||
| 72 | |||||||||||
| 73 | ################ | ||||||||||
| 74 | # | ||||||||||
| 75 | # Is segmentation fault problem fixed? | ||||||||||
| 76 | # | ||||||||||
| 77 | 1 | ok(!$article->id); | |||||||||
| 78 | |||||||||||
| 79 | 1 | ▶ | ok($article->title ? 0 : 1); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 80 | #print $article->dump; | ||||||||||
| 81 | TODO: { | ||||||||||
| 82 | #local $TODO = "Still not sure why this one keeps failing"; | ||||||||||
| 83 | 1 | ▶ | ok($article->author ? 0 : 1, $article->author . " is empty") | ||||||||
|
Branch: 1 branch
| |||||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | |||||||||||
| 87 | ################ | ||||||||||
| 88 | # | ||||||||||
| 89 | # Filling in details of the article | ||||||||||
| 90 | # | ||||||||||
| 91 | 1 | $article->title("Class::PObject now supports type-mapping"); | |||||||||
| 92 | |||||||||||
| 93 | 1 | $author = PO::Author->load($author_id); | |||||||||
| 94 | #print $article->dump; | ||||||||||
| 95 | 1 | $article->author( $author ); | |||||||||
| 96 | #print $article->dump; | ||||||||||
| 97 | #print $author->dump; | ||||||||||
| 98 | |||||||||||
| 99 | 1 | ok($article->author->name eq "Sherzod Ruzmetov", $article->author->name); | |||||||||
| 100 | 1 | ok(ref($article->author) eq "PO::Author", ref($article->author)); | |||||||||
| 101 | 1 | ok(my $article_id = $article->save(), $article->errstr ); | |||||||||
| 102 | |||||||||||
| 103 | #print $article->dump; | ||||||||||
| 104 | |||||||||||
| 105 | 1 | $article = $author = undef; | |||||||||
| 106 | |||||||||||
| 107 | 1 | $article = PO::Article->load($article_id); | |||||||||
| 108 | 1 | ok($article); | |||||||||
| 109 | |||||||||||
| 110 | #print $article->dump; | ||||||||||
| 111 | |||||||||||
| 112 | 1 | $author = $article->author; | |||||||||
| 113 | 1 | ok($article->title eq "Class::PObject now supports type-mapping", $article->title); | |||||||||
| 114 | 1 | ok($author->name eq "Sherzod Ruzmetov", $article->author->name); | |||||||||
| 115 | 1 | ok(ref ($author) eq "PO::Author", ref($article->author)); | |||||||||
| 116 | |||||||||||
| 117 | 1 | $article->author($author->id); | |||||||||
| 118 | |||||||||||
| 119 | 1 | ok($article->save == $article_id, $article->errstr); | |||||||||
| 120 | |||||||||||
| 121 | #print $article->dump; | ||||||||||
| 122 | 1 | $article = undef; | |||||||||
| 123 | |||||||||||
| 124 | 1 | $article = PO::Article->load({author=>$author}); | |||||||||
| 125 | 1 | ok($article, "article: $article"); | |||||||||
| 126 | |||||||||||
| 127 | #print $article->dump; | ||||||||||
| 128 | |||||||||||
| 129 | 1 | ok($article->title eq "Class::PObject now supports type-mapping"); | |||||||||
| 130 | 1 | ok($article->author->name eq "Sherzod Ruzmetov", ''.$article->author->name); | |||||||||
| 131 | 1 | ok(ref($article->author) eq "PO::Author", ref($article->author)); | |||||||||
| 132 | |||||||||||
| 133 | 1 | ok($article->save == $article_id, $article->errstr); | |||||||||
| 134 | |||||||||||
| 135 | 1 | $article = undef; | |||||||||
| 136 | |||||||||||
| 137 | 1 | my $result = PO::Article->fetch({author=>$author}); | |||||||||
| 138 | 1 | ok($article = $result->next); | |||||||||
| 139 | |||||||||||
| 140 | #print $article->dump; | ||||||||||
| 141 | |||||||||||
| 142 | 1 | ok($author = $article->author); | |||||||||
| 143 | #print $article->dump; | ||||||||||
| 144 | 1 | ok($article->title eq "Class::PObject now supports type-mapping"); | |||||||||
| 145 | 1 | ok($author->name eq "Sherzod Ruzmetov", ''.$article->author->name); | |||||||||
| 146 | 1 | ok(ref($author) eq "PO::Author", ref($article->author)); | |||||||||
| 147 | |||||||||||
| 148 | #print Dumper($article); | ||||||||||
| 149 | #print Dumper($author); | ||||||||||
| 150 | |||||||||||
| 151 | ################ | ||||||||||
| 152 | # FIX: | ||||||||||
| 153 | # If we created another article, but didn't assign any value to its | ||||||||||
| 154 | # author field, when we access author(), it used to return the Author object | ||||||||||
| 155 | # from the previous article's author. | ||||||||||
| 156 | 1 | my $article2 = new PO::Article(); | |||||||||
| 157 | 1 | $article2->title("Is this annoying bug fixed?"); | |||||||||
| 158 | 1 | ▶ | ok($article2->columns()->{author} ? 0 : 1, "Author shouldn't be set yet"); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 159 | 1 | ▶ | ok($article2->author ? 0 : 1, "Author shouldnt' be set yet"); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 160 | |||||||||||
| 161 | |||||||||||
| 162 | |||||||||||
| 163 | 1 | ok(PO::Article->count() == 1); | |||||||||
| 164 | 1 | ok(PO::Article->count({author=>$author}) == 1); | |||||||||
| 165 | 1 | ok(PO::Article->remove_all); | |||||||||
| 166 | 1 | ok(PO::Article->count({author=>$author}) == 0); | |||||||||
| 167 | |||||||||||
| 168 | 1 | ok(PO::Article->drop_datasource); | |||||||||
| 169 | 1 | ok(PO::Author->drop_datasource); | |||||||||
| 170 | } | ||||||||||
| 171 | |||||||||||
| 172 | 1 | 1; | |||||||||
| 173 | __END__ | ||||||||||