root/branches/release-36/t/21-callbacks.t @ 2069

Revision 2069, 2.6 kB (checked in by mpaschal, 19 months ago)

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

  • 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;
8use DB_File;
9
10use lib 'extlib';
11use lib 't/lib';
12use lib 'lib';
13
14use MT;
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
79=pod
80
81# TBD: generalize this
82my $driver = MT::ObjectDriver->new('DBI::SQLite');
83
84#my %entries;
85#tie %entries, "DB_File", $mt->{cfg}->DataSource . "/entry.db",
86#                         O_RDWR, 0400, $DB_BTREE
87#    || die $!;
88#my $rec = $entries{$id};
89#$rec = $driver->{serializer}->unserialize($rec);
90#is($$rec->{text}, rot13($TEST_TEXT), 'text rotated');
91
92#is($entry2->text_more, $TEST_TEXT_MORE, '$entry2->text_more()');
93#is($$rec->{text_more}, $TEST_TEXT_MORE, '$$rec->{text_more}');
94
95=cut
96
Note: See TracBrowser for help on using the browser.