| 1 | #!/usr/bin/perl |
|---|
| 2 | |
|---|
| 3 | use strict; |
|---|
| 4 | use lib 'extlib', 'lib'; |
|---|
| 5 | |
|---|
| 6 | use Data::Dumper; |
|---|
| 7 | use Test::More tests => 13; |
|---|
| 8 | |
|---|
| 9 | use MT; |
|---|
| 10 | use MT::Object; |
|---|
| 11 | |
|---|
| 12 | my $mt = MT->instance; # plugins are go! |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | package MT::Awesome; |
|---|
| 16 | |
|---|
| 17 | our @ISA = qw( MT::Object ); |
|---|
| 18 | |
|---|
| 19 | __PACKAGE__->install_properties({ |
|---|
| 20 | column_defs => { |
|---|
| 21 | id => 'integer not null auto_increment', |
|---|
| 22 | title => 'string(255)', |
|---|
| 23 | file => 'string(255)', |
|---|
| 24 | }, |
|---|
| 25 | meta => 1, |
|---|
| 26 | class_type => 'foo', |
|---|
| 27 | }); |
|---|
| 28 | __PACKAGE__->install_meta({ |
|---|
| 29 | columns => [ 'mime_type' ] |
|---|
| 30 | }); |
|---|
| 31 | |
|---|
| 32 | package MT::Awesome::Image; |
|---|
| 33 | |
|---|
| 34 | our @ISA = qw( MT::Awesome ); |
|---|
| 35 | |
|---|
| 36 | __PACKAGE__->install_properties({ |
|---|
| 37 | class_type => 'image', |
|---|
| 38 | }); |
|---|
| 39 | __PACKAGE__->install_meta({ |
|---|
| 40 | columns => [ 'width', 'height' ] |
|---|
| 41 | }); |
|---|
| 42 | |
|---|
| 43 | package main; |
|---|
| 44 | |
|---|
| 45 | my $file = new MT::Awesome; |
|---|
| 46 | my $image = new MT::Awesome::Image; |
|---|
| 47 | |
|---|
| 48 | ok($file->has_column('meta'), 'having meta auto-adds meta column'); |
|---|
| 49 | ok(!defined $file->meta('mime_type'), 'unset metadata field is undefined'); |
|---|
| 50 | ok($file->meta('mime_type', 'archive/zip'), 'metadata field could be set'); |
|---|
| 51 | is($file->meta('mime_type'), 'archive/zip', 'new metadata value could be retrieved'); |
|---|
| 52 | ok($file->{changed_cols}{meta}, 'setting metadata field marked meta column as changed'); |
|---|
| 53 | is($file->mime_type, 'archive/zip', 'auto-installed metadata field method retrieved new value'); |
|---|
| 54 | ok(!$file->has_meta('width'), 'metadata field on subclass did not install on superclass'); |
|---|
| 55 | |
|---|
| 56 | ok(!defined $image->width, 'auto-installed metadata field method returned undef for unset field'); |
|---|
| 57 | ok($image->width(300), 'metadata field on subclass could be set with auto-installed method'); |
|---|
| 58 | is($image->width, 300, 'auto-installed metadata field method retrieved new value for subclass'); |
|---|
| 59 | ok($image->{changed_cols}{meta}, 'setting metadata field on subclass with auto-installed method marked meta column as changed'); |
|---|
| 60 | ok($image->has_meta('width'), 'subclass has metadata field that was declared for subclass'); |
|---|
| 61 | ok($image->has_meta('mime_type'), 'subclass has metadata field that was declared for superclass'); |
|---|
| 62 | |
|---|