root/trunk/t/21-callbacks.t

Revision 2562, 2.2 kB (checked in by bchoate, 18 months ago)

Test suite cleanup. Use MT::Test to force t/ based configuration file for all tests. Fixed several tests that had incorrect expected values.

  • 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 => 5;
7use CGI;
8
9use lib 'extlib';
10use lib 't/lib';
11use lib 'lib';
12
13use MT;
14use MT::Test;
15use MT::Plugin;
16use MT::Entry;
17use MT::App::CMS;
18use MT::Permission;
19
20use vars qw($T_CFG);
21
22use lib 't';
23require 'test-common.pl';
24require 'blog-common.pl';
25
26my $mt = MT->new(Config => $T_CFG);
27die "Couldn't create MT (" . MT->errstr. ")" unless $mt;
28
29sub rot13 {
30    $_[0] =~ tr/A-Za-z/N-ZA-Mn-za-m/;
31    return $_[0];
32}
33
34my $plug = MT::Plugin->new();
35
36# my $blog = MT::Blog->new();
37# $blog->set_values({ name => 'none'});
38# $blog->save();
39
40my $plugin = MT::Plugin->new({name => "21-callbacks.t"});
41
42### Test object callbacks
43
44my ($pre_save_called, $post_load_called);
45MT->add_callback('MT::Entry::pre_save', 1, $plugin,
46                 sub { my ($eh, $obj, $app_obj) = @_;
47                       $pre_save_called = 1;
48                       $obj->text(rot13($obj->text));
49                       $app_obj->text($app_obj->text . '(rot13d)')} )
50    || die "Couldn't add pre_save cb: " . MT->errstr;
51MT->add_callback('MT::Entry::post_load', 1, $plugin,
52                 sub { my ($eh, $obj) = @_;
53                       $post_load_called = 1;
54                       $obj->text(rot13($obj->text)) } )
55    || die "Couldn't add post_load cb: " . MT->errstr;
56
57my $entry = MT::Entry->new();
58my $TEST_TEXT = "Come flow on the mic with the mighty mic master ";
59my $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.";
60$entry->author_id(1);
61$entry->status(1);
62$entry->text($TEST_TEXT);
63$entry->text_more($TEST_TEXT_MORE);
64$entry->title("Cantaloop");
65$entry->blog_id(1);
66$entry->save() or die $entry->errstr();
67
68ok($pre_save_called, 'pre-save callback was called');
69
70is($entry->text, $TEST_TEXT . '(rot13d)', 'in-mem object altered');
71
72my $id = $entry->id();
73ok($id, 'new entry has an id');
74
75my $entry2 = MT::Entry->load($id);
76ok($post_load_called, 'post-load callback was called');
77is($entry2->text, $TEST_TEXT, 'on-disk obj altered');
78
Note: See TracBrowser for help on using the browser.