root/trunk/t/21-app-callbacks.t

Revision 5086, 2.0 kB (checked in by takayama, 8 days ago)

* Fixed for work.

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