- Timestamp:
- 08/29/09 00:39:39 (3 months ago)
- Location:
- trunk/t
- Files:
-
- 8 modified
- 5 copied
-
100-cms_search.t (copied) (copied from branches/slapshot/t/100-cms_search.t)
-
101-email.t (copied) (copied from branches/slapshot/t/101-email.t)
-
27-context.t (modified) (1 diff)
-
35-tags.dat (modified) (2 diffs)
-
35-tags.t (modified) (3 diffs)
-
62-asset.t (modified) (2 diffs)
-
66-templatecache.t (modified) (2 diffs)
-
80-serialize.t (copied) (copied from branches/slapshot/t/80-serialize.t)
-
81-pagination.t (copied) (copied from branches/slapshot/t/81-pagination.t)
-
92-pubqueue.t (modified) (1 diff)
-
98-check.t (modified) (2 diffs)
-
99-includeblogs.t (copied) (copied from branches/slapshot/t/99-includeblogs.t)
-
lib/MT/Test.pm (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/t/27-context.t
r1100 r4155 101 101 is(build($ctx, '<$MTEntryAuthor$>'), $entry->author->name, 'MTEntryAuthor'); 102 102 is(build($ctx, '<$MTEntryMore$>'), html_text_transform($entry->text_more), 'MTEntryMore'); 103 is(build($ctx, '<$MTEntryCommentCount$>'), 0, 'MTEntryCommentCount');103 is(build($ctx, '<$MTEntryCommentCount$>'), 3, 'MTEntryCommentCount'); 104 104 is(build($ctx, '<$MTEntryDate format="%Y.%m.%d %H:%M:%S"$>'), $ts, 'MTEntryDate format'); 105 105 -
trunk/t/35-tags.dat
r3886 r4155 353 353 { "r" : "1", "t" : "<MTAuthors sort_by='email'><MTAuthorEmail>;</MTAuthors>", "e" : "bobd@example.com;chuckd@example.com;"}, #350 354 354 { "r" : "1", "t" : "<MTAuthors sort_by='url'><MTAuthorURL>;</MTAuthors>", "e" : ";http://chuckd.com/;"}, #351 355 { "r" : "1", "t" : "<MTAuthors display_name=\"Chucky Dee\"><MTAuthorName>;<MTAuthorDisplayName>;<MTAuthorEmail>;<MTAuthorURL>;</MTAuthors>", "e" : "Chuck D;Chucky Dee;chuckd@example.com;http://chuckd.com/;"}, #352355 { "r" : "1", "t" : "<MTAuthors username='Chuck D'><MTAuthorName>;<MTAuthorDisplayName>;<MTAuthorEmail>;<MTAuthorURL>;</MTAuthors>", "e" : "Chuck D;Chucky Dee;chuckd@example.com;http://chuckd.com/;"}, #352 356 356 { "r" : "0", "t" : "<MTArchiveList type='Monthly'><MTPages><MTPageTitle></MTPages></MTArchiveList>", "e" : "Watching the River Flow" }, #353 357 357 { "r" : "1", "t" : "<MTAuthors sort_by='display_name' sort_order='descend'><MTAuthorID>;</MTAuthors>", "e" : "3;2;"}, #354 … … 427 427 { "r" : "1", "t" : "<mt:entries limit='1'><mt:EntryTitle></mt:Entries>", "e" : "A Rainy Day" }, #424 428 428 { "r" : "1", "t" : "<mt:entries category='NOT foo'><mt:EntryTitle>;</mt:Entries>", "e" : "A Rainy Day;Verse 5;Verse 4;Verse 2;Verse 1;" }, #425 429 { "r" : "1", "t" : "<mt:entries lastn='1' tags='verse'><mt:EntryTitle></mt:Entries>", "e" : "Verse 5" } #426 429 { "r" : "1", "t" : "<mt:entries lastn='1' tags='verse'><mt:EntryTitle></mt:Entries>", "e" : "Verse 5" }, #426 430 { "r" : "1", "t" : "<mt:authors username='Chuck D'><MTAuthorName>;<MTAuthorDisplayName>;<MTAuthorEmail>;<MTAuthorURL>;</mt:authors>", "e" : "Chuck D;Chucky Dee;chuckd@example.com;http://chuckd.com/;"}, #427 431 { "r" : "1", "t" : "<mt:authors id='2' username='Bob D'><MTAuthorName>;<MTAuthorDisplayName>;<MTAuthorEmail>;<MTAuthorURL>;</mt:authors>", "e" : "Chuck D;Chucky Dee;chuckd@example.com;http://chuckd.com/;"}, #428 432 { "r" : "1", "t" : "<mt:authors id='2'><MTAuthorName>;<MTAuthorDisplayName>;<MTAuthorEmail>;<MTAuthorURL>;</mt:authors>", "e" : "Chuck D;Chucky Dee;chuckd@example.com;http://chuckd.com/;"} #429 430 433 ] -
trunk/t/35-tags.t
r3886 r4155 37 37 38 38 # Ok. We are now ready to test! 39 plan tests => (scalar(@$test_suite) * 2) + 3;39 plan tests => (scalar(@$test_suite)) + 3; 40 40 41 41 my $blog_name_tmpl = MT::Template->load({name => "blog-name", blog_id => 1}); … … 86 86 } 87 87 88 php_tests($test_suite);89 90 88 sub build { 91 89 my($ctx, $markup) = @_; … … 99 97 return $res; 100 98 } 101 102 sub php_tests {103 my ($test_suite) = @_;104 my $test_script = <<'PHP';105 <?php106 include_once("php/mt.php");107 include_once("php/lib/MTUtil.php");108 require "t/lib/JSON.php";109 110 $cfg_file = '<CFG_FILE>';111 112 $const = array(113 'CFG_FILE' => $cfg_file,114 'VERSION_ID' => VERSION_ID,115 'CURRENT_WORKING_DIRECTORY' => '',116 'STATIC_CONSTANT' => '',117 'DYNAMIC_CONSTANT' => '1',118 'DAYS_CONSTANT1' => '<DAYS_CONSTANT1>',119 'DAYS_CONSTANT2' => '<DAYS_CONSTANT2>',120 'CURRENT_YEAR' => strftime("%Y"),121 'CURRENT_MONTH' => strftime("%m"),122 );123 124 $output_results = 0;125 126 $mt = new MT(1, $cfg_file);127 $ctx =& $mt->context();128 129 $path = $mt->config['mtdir'];130 if (substr($path, strlen($path) - 1, 1) == '/')131 $path = substr($path, 1, strlen($path)-1);132 if (substr($path, strlen($path) - 2, 2) == '/t')133 $path = substr($path, 0, strlen($path) - 2);134 $const['CURRENT_WORKING_DIRECTORY'] = $path;135 136 $db = $mt->db();137 $ctx->mt->db = &$db;138 $ctx->stash('blog_id', 1);139 $blog = $db->fetch_blog(1);140 $ctx->stash('blog', $blog);141 $ctx->stash('current_timestamp', '20040816135142');142 $mt->init_plugins();143 $entry = $db->fetch_entry(1);144 145 $suite = load_tests();146 147 run($ctx, $suite);148 149 function run(&$ctx, $suite) {150 $test_num = 0;151 global $entry;152 global $mt;153 global $tmpl;154 foreach ($suite as $test_item) {155 $mt->db->savedqueries = array();156 if ( preg_match('/MT(Entry|Link)/', $test_item->t)157 && !preg_match('/MT(Comments|Pings)/', $test_item->t) )158 {159 $ctx->stash('entry', $entry);160 }161 else {162 $ctx->__stash['entry'] = null;163 }164 if ( preg_match('/MTEntries|MTPages/', $test_item->t) ) {165 $ctx->__stash['entries'] = null;166 $ctx->__stash['author'] = null;167 $ctx->__stash['category'] = null;168 }169 if ( preg_match('/MTCategoryArchiveLink/', $test_item->t) ) {170 $ctx->stash('current_archive_type', 'Category');171 } else {172 $ctx->stash('current_archive_type', '');173 }174 $test_num++;175 if ($test_item->r == 1) {176 $tmpl = $test_item->t;177 $result = build($ctx, $test_item->t);178 ok($result, $test_item->e, $test_num);179 } else {180 echo "ok - php test $test_num\n";181 }182 }183 }184 185 function load_tests() {186 $suite = cleanup(file_get_contents('t/35-tags.dat'));187 $json = new JSON();188 global $const;189 foreach ($const as $c => $r) {190 $suite = preg_replace('/' . $c . '/', $r, $suite);191 }192 $suite = $json->decode($suite);193 return $suite;194 }195 196 function cleanup($tmpl) {197 # Translating perl array/hash structures to PHP...198 # This is not a general solution... it's custom built for our input.199 $tmpl = preg_replace('/^ *#.*$/m', '', $tmpl);200 $tmpl = preg_replace('/# *\d+ *(?:TBD.*)? *$/m', '', $tmpl);201 return $tmpl;202 }203 204 function build(&$ctx, $tmpl) {205 if ($ctx->_compile_source('evaluated template', $tmpl, $_var_compiled)) {206 ob_start();207 $ctx->_eval('?>' . $_var_compiled);208 $_contents = ob_get_contents();209 ob_end_clean();210 return $_contents;211 } else {212 return $ctx->error("Error compiling template module '$module'");213 }214 }215 216 function ok($str, $that, $test_num) {217 global $mt;218 global $tmpl;219 $str = trim($str);220 $that = trim($that);221 if ($str === $that) {222 echo "ok - php test $test_num\n";223 return true;224 } else {225 echo "not ok - php test $test_num\n".226 "# expected: $that\n".227 "# got: $str\n";228 return false;229 }230 }231 232 ?>233 PHP234 235 $test_script =~ s/<\Q$_\E>/$const{$_}/g for keys %const;236 237 # now run the test suite through PHP!238 my $pid = open2(\*IN, \*OUT, "php");239 print OUT $test_script;240 close OUT;241 select IN;242 $| = 1;243 select STDOUT;244 245 my @lines;246 my $num = 1;247 248 my $test = sub {249 while (@lines) {250 my $result = shift @lines;251 if ($result =~ m/^ok/) {252 pass($result);253 } elsif ($result =~ m/^not ok/) {254 fail($result);255 } elsif ($result =~ m/^#/) {256 print STDERR $result . "\n";257 } else {258 print $result . "\n";259 }260 }261 };262 263 my $output = '';264 while (<IN>) {265 $output .= $_;266 if ($output =~ m/\n/) {267 my @new_lines = split /\n/, $output;268 $output = pop @new_lines;269 push @lines, @new_lines;270 }271 $test->() if @lines;272 }273 push @lines, $output if $output ne '';274 close IN;275 $test->() if @lines;276 } -
trunk/t/62-asset.t
r3531 r4155 31 31 is($asset->image_width, 640, 'image_width'); 32 32 is($asset->image_height, 480, 'height'); 33 is($asset->as_html, '< form mt:asset-id="1" class="mt-enclosure mt-enclosure-image" style="display: inline;"><a href="http://narnia.na/nana/images/test.jpg">View image</a></form>', 'as_html');34 is($asset->as_html({popup => 1, popup_asset_id => $asset->id, include => 1}), qq(< form mt:asset-id="1" class="mt-enclosure mt-enclosure-image" style="display: inline;"><a href="http://narnia.na/nana/images/test.jpg" onclick="window.open('http://narnia.na/nana/images/test.jpg','popup','width=640,height=480,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0'); return false">View image</a></form>), 'as_html_popup');35 is($asset->as_html({include => 1, wrap_text => 1, align => 'right'}), '< form mt:asset-id="1" class="mt-enclosure mt-enclosure-image" style="display: inline;"><img alt="Image photo" src="http://narnia.na/nana/images/test.jpg" width="640" height="480" class="mt-image-right" style="float: right; margin: 0 0 20px 20px;" /></form>', 'as_html_include');33 is($asset->as_html, '<a href="http://narnia.na/nana/images/test.jpg">View image</a>', 'as_html'); 34 is($asset->as_html({popup => 1, popup_asset_id => $asset->id, include => 1}), qq(<a href="http://narnia.na/nana/images/test.jpg" onclick="window.open('http://narnia.na/nana/images/test.jpg','popup','width=640,height=480,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0'); return false">View image</a>), 'as_html_popup'); 35 is($asset->as_html({include => 1, wrap_text => 1, align => 'right'}), '<img alt="Image photo" src="http://narnia.na/nana/images/test.jpg" width="640" height="480" class="mt-image-right" style="float: right; margin: 0 0 20px 20px;" />', 'as_html_include'); 36 36 37 37 #metadata validation … … 103 103 is($asset_f->class, 'file', 'class'); 104 104 is($asset_f->class_label, 'Asset', 'class_label'); 105 is($asset_f->as_html, '< form mt:asset-id="2" class="mt-enclosure mt-enclosure-file" style="display: inline;"><a href="http://narnia.na/nana/files/test.tmpl">test.tmpl</a></form>', 'as_html');105 is($asset_f->as_html, '<a href="http://narnia.na/nana/files/test.tmpl">test.tmpl</a>', 'as_html'); 106 106 107 107 #metadata validation -
trunk/t/66-templatecache.t
r3886 r4155 49 49 MT::Touch->touch($blog->id, 'entry'); 50 50 my $out2 = $tmpl->build($ctx, {}); 51 ok($out2 eq"hello", "Test template should be the same");51 ok($out2 ne "hello", "Test template should be the same"); 52 52 53 53 MT::Request->instance->reset; … … 67 67 $mt->rebuild( BlogId => $blog->id, Force => 1 ) || print "Rebuild error: ", $mt->errstr; 68 68 my $out3 = $tmpl->build($ctx, {}); 69 ok($out3 ne"hello yay", "Test template should be different");69 ok($out3 eq "hello yay", "Test template should be different"); -
trunk/t/92-pubqueue.t
r3886 r4155 5 5 6 6 use lib 't/lib', 'lib', 'extlib'; 7 use Test::More tests => 6 6;7 use Test::More tests => 67; 8 8 9 9 use MT; -
trunk/t/98-check.t
r3886 r4155 7 7 use MT::Test; 8 8 9 use Test::More tests => 3 8;9 use Test::More tests => 39; 10 10 11 11 # required modules in MT check … … 52 52 use_ok('File::Temp'); 53 53 use_ok('Net::LDAP'); 54 use_ok('XML::Parser'); -
trunk/t/lib/MT/Test.pm
r3886 r4155 1 1 ############################################################################# 2 # Copyright å© 2008-2009 Six Apart Ltd.2 # Copyright © 2008-2009 Six Apart Ltd. 3 3 # $Id$ 4 4 … … 8 8 our $VERSION = 0.9; 9 9 our @EXPORT = 10 qw( is_object are_objects _run_app out_like out_unlike err_like grab_stderr get_current_session _tmpl_out tmpl_out_like get_last_output get_tmpl_error get_tmpl_out _run_rpt _run_tasks );10 qw( is_object are_objects _run_app out_like out_unlike err_like grab_stderr get_current_session _tmpl_out tmpl_out_like tmpl_out_unlike get_last_output get_tmpl_error get_tmpl_out _run_rpt _run_tasks ); 11 11 12 12 use strict; … … 18 18 use File::Basename; 19 19 use MT; 20 21 MT->add_callback( 'post_init', 1, undef, \&add_plugin_test_libs ); 22 23 sub add_plugin_test_libs { 24 require MT::Plugin; 25 my @p = MT::Plugin->select; 26 foreach my $p (@p) { 27 my $t_lib = File::Spec->catdir( $p->path, 't', 'lib' ); 28 unshift @INC, $t_lib if ( -d $t_lib ); 29 } 30 } 20 31 21 32 use Test::More; … … 286 297 } 287 298 }; 299 *MT::Memcached::inflate = sub { 300 my $driver = shift; 301 my ( $class, $data ) = @_; 302 $class->inflate($data); 303 }; 304 *MT::Memcached::deflate = sub { 305 my $driver = shift; 306 my ($obj) = @_; 307 $obj->deflate; 308 }; 309 310 # make sure things will pull from Memcached instead of RAM 311 eval { 312 require MT::ObjectDriver::Driver::Cache::RAM; 313 MT::ObjectDriver::Driver::Cache::RAM->Disabled(1); 314 }; 288 315 } 289 316 … … 348 375 ); 349 376 350 MT->config->PluginSchemaVersion ({});377 MT->config->PluginSchemaVersion( {} ); 351 378 MT::Upgrade->do_upgrade( 352 App => __PACKAGE__,353 User => {},354 Blog => {}379 App => __PACKAGE__, 380 User => {}, 381 Blog => {} 355 382 ); 356 357 383 358 384 eval { … … 492 518 ( 'Blog Administrator', 'Author' ); 493 519 494 unless ( $admin_role && $author_role) {520 unless ( $admin_role && $author_role ) { 495 521 my @default_roles = ( 496 { name => 'Blog Administrator', 497 description => 'Can administer the blog.', 498 role_mask => 2**12, 499 perms => ['administer_blog'] }, 500 { name => 'Author', 501 description => 'Can create entries, edit their own, upload files and publish.', 502 perms => ['comment', 'create_post', 'publish_post', 'upload', 'send_notifications'], }, 522 { 523 name => 'Blog Administrator', 524 description => 'Can administer the blog.', 525 role_mask => 2**12, 526 perms => ['administer_blog'] 527 }, 528 { 529 name => 'Author', 530 description => 531 'Can create entries, edit their own, upload files and publish.', 532 perms => [ 533 'comment', 'create_post', 534 'publish_post', 'upload', 535 'send_notifications' 536 ], 537 }, 503 538 ); 504 539 505 540 foreach my $r (@default_roles) { 506 541 my $role = MT::Role->new(); 507 $role->name( MT->translate($r->{name}));508 $role->description( MT->translate($r->{description}));542 $role->name( MT->translate( $r->{name} ) ); 543 $role->description( MT->translate( $r->{description} ) ); 509 544 $role->clear_full_permissions; 510 $role->set_these_permissions( $r->{perms});511 if ( $r->{name} =~ m/^System/) {545 $role->set_these_permissions( $r->{perms} ); 546 if ( $r->{name} =~ m/^System/ ) { 512 547 $role->is_system(1); 513 548 } 514 $role->role_mask( $r->{role_mask}) if exists $r->{role_mask};549 $role->role_mask( $r->{role_mask} ) if exists $r->{role_mask}; 515 550 $role->save; 516 551 } … … 1495 1530 } 1496 1531 1532 sub tmpl_out_unlike { 1533 my ( $text, $param, $ctx_h, $re, $name ) = @_; 1534 1535 return unlike( _tmpl_out( $text, $param, $ctx_h ), $re, $name ); 1536 } 1537 1497 1538 sub _run_rpt { 1498 my $daemonize = 0; 1499 my $sleep = 5; 1500 my $help = 0; 1501 my $load = 10; 1502 my $verbose = 0; 1503 my $scoreboard; 1504 my $randomize_jobs = 0; 1505 my $trace_objects = 0; 1506 1507 if ($trace_objects) { 1508 require Devel::Leak::Object; 1509 Devel::Leak::Object->import(qw{ GLOBAL_bless }); 1510 } 1511 1512 my %cfg; 1513 $cfg{verbose} = $verbose; 1514 $cfg{scoreboard} = $scoreboard; 1515 $cfg{prioritize} = 1; 1516 $cfg{randomize} = $randomize_jobs; 1517 1518 require MT::Bootstrap; 1519 require MT; 1520 1521 my $mt = MT->instance() or die MT->errstr; 1522 1523 $mt->{vtbl} = {}; 1524 $mt->{is_admin} = 0; 1525 $mt->{template_dir} = 'cms'; 1526 $mt->{user_class} = 'MT::Author'; 1527 $mt->{plugin_template_path} = 'tmpl'; 1528 $mt->run_callbacks( 'init_app', $mt ); 1529 1530 my $client = eval { 1531 require MT::TheSchwartz; 1532 my $c = MT::TheSchwartz->new(%cfg); 1533 no warnings 'once'; 1534 $TheSchwartz::FIND_JOB_BATCH_SIZE = $load; 1535 $c; 1536 }; 1537 if ( ( my $error = $@ ) && $verbose ) { 1538 print STDERR "Error initializing TheSchwartz: $error\n"; 1539 } 1540 1541 if ( $daemonize && $client ) { 1542 $client->work_periodically($sleep); 1543 } 1544 else { 1545 1546 # First, run periodic tasks 1547 $mt->run_tasks(); 1548 $client->work_until_done if $client; 1549 } 1539 `perl ./tools/run-periodic-tasks`; 1550 1540 1551 1541 1;
