Changeset 4155 for trunk/t

Show
Ignore:
Timestamp:
08/29/09 00:39:39 (3 months ago)
Author:
fumiakiy
Message:

Merged slapshot to trunk. "svn merge -r3786:4152 http://code.sixapart.com/svn/movabletype/branches/slapshot/ ."

Location:
trunk/t
Files:
8 modified
5 copied

Legend:

Unmodified
Added
Removed
  • trunk/t/27-context.t

    r1100 r4155  
    101101is(build($ctx, '<$MTEntryAuthor$>'), $entry->author->name, 'MTEntryAuthor'); 
    102102is(build($ctx, '<$MTEntryMore$>'), html_text_transform($entry->text_more), 'MTEntryMore'); 
    103 is(build($ctx, '<$MTEntryCommentCount$>'), 0, 'MTEntryCommentCount'); 
     103is(build($ctx, '<$MTEntryCommentCount$>'), 3, 'MTEntryCommentCount'); 
    104104is(build($ctx, '<$MTEntryDate format="%Y.%m.%d %H:%M:%S"$>'), $ts, 'MTEntryDate format'); 
    105105 
  • trunk/t/35-tags.dat

    r3886 r4155  
    353353{ "r" : "1", "t" : "<MTAuthors sort_by='email'><MTAuthorEmail>;</MTAuthors>", "e" : "bobd@example.com;chuckd@example.com;"}, #350 
    354354{ "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/;"}, #352 
     355{ "r" : "1", "t" : "<MTAuthors username='Chuck D'><MTAuthorName>;<MTAuthorDisplayName>;<MTAuthorEmail>;<MTAuthorURL>;</MTAuthors>", "e" : "Chuck D;Chucky Dee;chuckd@example.com;http://chuckd.com/;"}, #352 
    356356{ "r" : "0", "t" : "<MTArchiveList type='Monthly'><MTPages><MTPageTitle></MTPages></MTArchiveList>", "e" : "Watching the River Flow" }, #353 
    357357{ "r" : "1", "t" : "<MTAuthors sort_by='display_name' sort_order='descend'><MTAuthorID>;</MTAuthors>", "e" : "3;2;"}, #354 
     
    427427{ "r" : "1", "t" : "<mt:entries limit='1'><mt:EntryTitle></mt:Entries>", "e" : "A Rainy Day" }, #424 
    428428{ "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 
    430433] 
  • trunk/t/35-tags.t

    r3886 r4155  
    3737 
    3838# Ok. We are now ready to test! 
    39 plan tests => (scalar(@$test_suite) * 2) + 3; 
     39plan tests => (scalar(@$test_suite)) + 3; 
    4040 
    4141my $blog_name_tmpl = MT::Template->load({name => "blog-name", blog_id => 1}); 
     
    8686} 
    8787 
    88 php_tests($test_suite); 
    89  
    9088sub build { 
    9189    my($ctx, $markup) = @_; 
     
    9997    return $res; 
    10098} 
    101  
    102 sub php_tests { 
    103     my ($test_suite) = @_; 
    104     my $test_script = <<'PHP'; 
    105 <?php 
    106 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 PHP 
    234  
    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  
    3131    is($asset->image_width, 640, 'image_width');  
    3232    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'); 
    3636 
    3737    #metadata validation 
     
    103103    is($asset_f->class, 'file', 'class'); 
    104104    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'); 
    106106 
    107107    #metadata validation 
  • trunk/t/66-templatecache.t

    r3886 r4155  
    4949MT::Touch->touch($blog->id, 'entry'); 
    5050my $out2 = $tmpl->build($ctx, {}); 
    51 ok($out2 eq "hello", "Test template should be the same"); 
     51ok($out2 ne "hello", "Test template should be the same"); 
    5252 
    5353MT::Request->instance->reset; 
     
    6767$mt->rebuild( BlogId => $blog->id, Force  => 1 ) || print "Rebuild error: ", $mt->errstr; 
    6868my $out3 = $tmpl->build($ctx, {}); 
    69 ok($out3 ne "hello yay", "Test template should be different"); 
     69ok($out3 eq "hello yay", "Test template should be different"); 
  • trunk/t/92-pubqueue.t

    r3886 r4155  
    55 
    66use lib 't/lib', 'lib', 'extlib'; 
    7 use Test::More tests => 66; 
     7use Test::More tests => 67; 
    88 
    99use MT; 
  • trunk/t/98-check.t

    r3886 r4155  
    77use MT::Test; 
    88 
    9 use Test::More tests => 38; 
     9use Test::More tests => 39; 
    1010 
    1111# required modules in MT check 
     
    5252use_ok('File::Temp'); 
    5353use_ok('Net::LDAP'); 
     54use_ok('XML::Parser'); 
  • trunk/t/lib/MT/Test.pm

    r3886 r4155  
    11############################################################################# 
    2 # Copyright å© 2008-2009 Six Apart Ltd. 
     2# Copyright © 2008-2009 Six Apart Ltd. 
    33# $Id$ 
    44 
     
    88our $VERSION = 0.9; 
    99our @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 ); 
    1111 
    1212use strict; 
     
    1818use File::Basename; 
    1919use MT; 
     20 
     21MT->add_callback( 'post_init', 1, undef, \&add_plugin_test_libs ); 
     22 
     23sub 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} 
    2031 
    2132use Test::More; 
     
    286297        } 
    287298    }; 
     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    }; 
    288315} 
    289316 
     
    348375    ); 
    349376 
    350     MT->config->PluginSchemaVersion ({}); 
     377    MT->config->PluginSchemaVersion( {} ); 
    351378    MT::Upgrade->do_upgrade( 
    352         App     => __PACKAGE__, 
    353         User    => {}, 
    354         Blog    => {} 
     379        App  => __PACKAGE__, 
     380        User => {}, 
     381        Blog => {} 
    355382    ); 
    356      
    357383 
    358384    eval { 
     
    492518      ( 'Blog Administrator', 'Author' ); 
    493519 
    494     unless ($admin_role && $author_role) { 
     520    unless ( $admin_role && $author_role ) { 
    495521        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            }, 
    503538        ); 
    504539 
    505540        foreach my $r (@default_roles) { 
    506541            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} ) ); 
    509544            $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/ ) { 
    512547                $role->is_system(1); 
    513548            } 
    514             $role->role_mask($r->{role_mask}) if exists $r->{role_mask}; 
     549            $role->role_mask( $r->{role_mask} ) if exists $r->{role_mask}; 
    515550            $role->save; 
    516551        } 
     
    14951530} 
    14961531 
     1532sub 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 
    14971538sub _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`; 
    15501540 
    15511541    1;