Changeset 2069

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

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

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • 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; 
  • branches/release-36/t/21-callbacks.t

    r1459 r2069  
    44use warnings; 
    55 
    6 use Test::More tests => 8
     6use Test::More tests => 5
    77use CGI; 
    88use DB_File; 
     9 
     10use lib 'extlib'; 
     11use lib 't/lib'; 
     12use lib 'lib'; 
    913 
    1014use MT; 
     
    9195=cut 
    9296 
    93 ### Test app callbacks 
    94  
    95 my @result_cats = (); 
    96  
    97 my $cms = MT::App::CMS->new(Config => $T_CFG); 
    98  
    99 my $app_post_save_called; 
    100 MT->add_callback('AppPostEntrySave', 1, $plugin,  
    101                  sub {  
    102                        $app_post_save_called = 1; 
    103                        my @plcmts = MT::Placement->load({entry_id => $_[2]->id}); 
    104                        for my $plcmt (@plcmts) { 
    105                            push @result_cats, $plcmt->category_id; 
    106                        } 
    107                    } ); 
    108  
    109 MT::unplug(); 
    110 my $q = CGI->new(); 
    111 #$q->param(id => $entry2->id); 
    112 $q->param(blog_id => $entry2->blog_id); 
    113 $q->param(category_ids => 17); 
    114 # $q->param(username => 'Chuck D'); 
    115 # $q->param(password => 'bass'); 
    116 $q->param(text => "Buddha blessed and boo-ya blasted;  
    117 these are the words that she manifested."); 
    118 $cms->{query} = $q; 
    119 $cms->{perms} = MT::Permission->new(); 
    120 $cms->{perms}->can_post(1); 
    121 $cms->{author} = MT::Author->new(); 
    122 $cms->{author}->name("Mel E. Mel"); 
    123 $cms->{author}->id(1); 
    124  
    125 # fake out the magic; we're not testing that right now 
    126 no warnings qw(once redefine); 
    127 *MT::App::CMS::validate_magic = sub { 1; }; 
    128 use warnings qw(once redefine); 
    129  
    130 my $handler = $cms->handler_to_coderef( $cms->handlers_for_mode('save_entry') ); 
    131 my $ret = $handler->($cms); 
    132 ok(!defined $ret && $cms->{redirect}, 'entry save was successful'); 
    133 diag('Error: ' . $cms->errstr) if !defined $ret && !$cms->{redirect}; 
    134  
    135 ok($app_post_save_called, 'AppPostEntrySave callback was called'); 
    136 is($result_cats[0], 17, 'result_cats = 17'); 
    137