Show
Ignore:
Timestamp:
04/24/08 22:43:21 (19 months ago)
Author:
mpaschal
Message:

Split these tests up (can't instantiate two MTs in one run)

Files:
1 copied

Legend:

Unmodified
Added
Removed
  • branches/release-36/t/21-app-callbacks.t

    r1459 r2069  
    44use warnings; 
    55 
    6 use Test::More tests => 8; 
     6use Test::More tests => 3; 
    77use CGI; 
    88use DB_File; 
     9 
     10use lib 'extlib'; 
     11use lib 't/lib'; 
     12use lib 'lib'; 
    913 
    1014use MT; 
     
    1822use lib 't'; 
    1923require 'test-common.pl'; 
    20 require 'blog-common.pl'; 
    21  
    22 my $mt = MT->new(Config => $T_CFG); 
    23 die "Couldn't create MT (" . MT->errstr. ")" unless $mt; 
    24  
    25 sub rot13 { 
    26     $_[0] =~ tr/A-Za-z/N-ZA-Mn-za-m/; 
    27     return $_[0]; 
    28 } 
    29  
    30 my $plug = MT::Plugin->new(); 
    31  
    32 # my $blog = MT::Blog->new(); 
    33 # $blog->set_values({ name => 'none'}); 
    34 # $blog->save(); 
    35  
    36 my $plugin = MT::Plugin->new({name => "21-callbacks.t"}); 
    37  
    38 ### Test object callbacks 
    39  
    40 my ($pre_save_called, $post_load_called); 
    41 MT->add_callback('MT::Entry::pre_save', 1, $plugin,  
    42                  sub { my ($eh, $obj, $app_obj) = @_; 
    43                        $pre_save_called = 1; 
    44                        $obj->text(rot13($obj->text)); 
    45                        $app_obj->text($app_obj->text . '(rot13d)')} ) 
    46     || die "Couldn't add pre_save cb: " . MT->errstr; 
    47 MT->add_callback('MT::Entry::post_load', 1, $plugin, 
    48                  sub { my ($eh, $obj) = @_; 
    49                        $post_load_called = 1; 
    50                        $obj->text(rot13($obj->text)) } ) 
    51     || die "Couldn't add post_load cb: " . MT->errstr; 
    52  
    53 my $entry = MT::Entry->new(); 
    54 my $TEST_TEXT = "Come flow on the mic with the mighty mic master "; 
    55 my $TEST_TEXT_MORE = "beau-coup ducks, I'm a sucker to disaster. Scribble-dabbble scrabble, on the microphone I babble, as I fit the funky words! Into a puzzle! Yes, yes, yes, on and on as I flex, .... birds manifest, feel the vibe from here to Asia--dip trip, flip fantasia."; 
    56 $entry->author_id(1); 
    57 $entry->status(1); 
    58 $entry->text($TEST_TEXT); 
    59 $entry->text_more($TEST_TEXT_MORE); 
    60 $entry->title("Cantaloop"); 
    61 $entry->blog_id(1); 
    62 $entry->save() or die $entry->errstr(); 
    63  
    64 ok($pre_save_called, 'pre-save callback was called'); 
    65  
    66 is($entry->text, $TEST_TEXT . '(rot13d)', 'in-mem object altered'); 
    67  
    68 my $id = $entry->id(); 
    69 ok($id, 'new entry has an id'); 
    70  
    71 my $entry2 = MT::Entry->load($id); 
    72 ok($post_load_called, 'post-load callback was called'); 
    73 is($entry2->text, $TEST_TEXT, 'on-disk obj altered'); 
    74  
    75 =pod 
    76  
    77 # TBD: generalize this 
    78 my $driver = MT::ObjectDriver->new('DBI::SQLite'); 
    79  
    80 #my %entries; 
    81 #tie %entries, "DB_File", $mt->{cfg}->DataSource . "/entry.db", 
    82 #                         O_RDWR, 0400, $DB_BTREE 
    83 #    || die $!; 
    84 #my $rec = $entries{$id}; 
    85 #$rec = $driver->{serializer}->unserialize($rec); 
    86 #is($$rec->{text}, rot13($TEST_TEXT), 'text rotated'); 
    87  
    88 #is($entry2->text_more, $TEST_TEXT_MORE, '$entry2->text_more()'); 
    89 #is($$rec->{text_more}, $TEST_TEXT_MORE, '$$rec->{text_more}'); 
    90  
    91 =cut 
    9224 
    9325### Test app callbacks 
     
    9628 
    9729my $cms = MT::App::CMS->new(Config => $T_CFG); 
     30 
     31my $plugin = MT::Plugin->new({name => "21-callbacks.t"}); 
     32 
     33my $entry2 = MT::Entry->load({}, { limit => 1 }); 
    9834 
    9935my $app_post_save_called;