root/branches/release-32/t/64-objectmeta.t @ 1548

Revision 1548, 1.9 kB (checked in by mpaschal, 21 months ago)

Test that metadata fields are unset before we set them, while we're at it
BugzID: 68749

  • Property svn:keywords set to Id Revision
Line 
1#!/usr/bin/perl
2
3use strict;
4use lib 'extlib', 'lib';
5
6use Data::Dumper;
7use Test::More tests => 13;
8
9use MT;
10use MT::Object;
11
12my $mt = MT->instance;  # plugins are go!
13
14
15package MT::Awesome;
16
17our @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
32package MT::Awesome::Image;
33
34our @ISA = qw( MT::Awesome );
35
36__PACKAGE__->install_properties({
37    class_type => 'image',
38});
39__PACKAGE__->install_meta({
40    columns => [ 'width', 'height' ]
41});
42
43package main;
44
45my $file = new MT::Awesome;
46my $image = new MT::Awesome::Image;
47
48ok($file->has_column('meta'), 'having meta auto-adds meta column');
49ok(!defined $file->meta('mime_type'), 'unset metadata field is undefined');
50ok($file->meta('mime_type', 'archive/zip'), 'metadata field could be set');
51is($file->meta('mime_type'), 'archive/zip', 'new metadata value could be retrieved');
52ok($file->{changed_cols}{meta}, 'setting metadata field marked meta column as changed');
53is($file->mime_type, 'archive/zip', 'auto-installed metadata field method retrieved new value');
54ok(!$file->has_meta('width'), 'metadata field on subclass did not install on superclass');
55
56ok(!defined $image->width, 'auto-installed metadata field method returned undef for unset field');
57ok($image->width(300), 'metadata field on subclass could be set with auto-installed method');
58is($image->width, 300, 'auto-installed metadata field method retrieved new value for subclass');
59ok($image->{changed_cols}{meta}, 'setting metadata field on subclass with auto-installed method marked meta column as changed');
60ok($image->has_meta('width'), 'subclass has metadata field that was declared for subclass');
61ok($image->has_meta('mime_type'), 'subclass has metadata field that was declared for superclass');
62
Note: See TracBrowser for help on using the browser.