root/branches/release-40/t/21-app-callbacks.t @ 2573

Revision 2573, 1.9 kB (checked in by bchoate, 18 months ago)

Fixes for test suite.

  • Property svn:mime-type set to text/plain
  • Property svn:keywords set to Author Date Id Revision
Line 
1#!/usr/bin/perl
2# $Id$
3use strict;
4use warnings;
5
6use Test::More tests => 3;
7use CGI;
8
9use lib 'extlib';
10use lib 't/lib';
11use lib 'lib';
12
13use MT::Test;
14use MT;
15use MT::Plugin;
16use MT::Entry;
17use MT::App::CMS;
18use MT::Permission;
19
20use lib 't';
21require 'test-common.pl';
22
23### Test app callbacks
24
25my @result_cats = ();
26
27my $cms = MT::App::CMS->new();
28
29my $plugin = MT::Plugin->new({name => "21-callbacks.t"});
30
31my $entry2 = MT::Entry->load({}, { limit => 1 });
32
33my $app_post_save_called;
34MT->add_callback('AppPostEntrySave', 1, $plugin,
35                 sub {
36                       $app_post_save_called = 1;
37                       my @plcmts = MT::Placement->load({entry_id => $_[2]->id});
38                       for my $plcmt (@plcmts) {
39                           push @result_cats, $plcmt->category_id;
40                       }
41                   } );
42
43MT::unplug();
44my $q = CGI->new();
45#$q->param(id => $entry2->id);
46$q->param(blog_id => $entry2->blog_id);
47$q->param(category_ids => 17);
48$q->param(author_id => 1);
49$q->param(status => 1);
50# $q->param(username => 'Chuck D');
51# $q->param(password => 'bass');
52$q->param(text => "Buddha blessed and boo-ya blasted;
53these are the words that she manifested.");
54$cms->{query} = $q;
55$cms->{perms} = MT::Permission->new();
56$cms->{perms}->can_post(1);
57$cms->{author} = MT::Author->new();
58$cms->{author}->name("Mel E. Mel");
59$cms->{author}->id(1);
60
61# fake out the magic; we're not testing that right now
62no warnings qw(once redefine);
63*MT::App::CMS::validate_magic = sub { 1; };
64use warnings qw(once redefine);
65
66my $handler = $cms->handler_to_coderef( $cms->handlers_for_mode('save_entry') );
67my $ret = $handler->($cms);
68ok(!defined $ret && $cms->{redirect}, 'entry save was successful');
69diag('Error: ' . $cms->errstr) if !defined $ret && !$cms->{redirect};
70
71ok($app_post_save_called, 'AppPostEntrySave callback was called');
72is($result_cats[0], 17, 'result_cats = 17');
73
Note: See TracBrowser for help on using the browser.