Changeset 2120

Show
Ignore:
Timestamp:
12/21/06 10:25:47
Author:
miyagawa
Message:

added test cases for X-JSON stuff

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Catalyst-View-JSON/trunk/t/01_server.t

    r1899 r2120  
    66 
    77use Encode; 
    8 use Test::More tests => 28; 
     8use Test::More tests => 38; 
    99use Catalyst::Test 'TestApp'; 
    1010use JSON (); 
     
    9292    ok decode('euc-jp', $response->content); 
    9393} 
     94 
     95{ 
     96    my $request = HTTP::Request->new( GET => "http://localhost/foo3" ); 
     97    $request->header("User-Agent", "Safari"); 
     98 
     99    ok( my $response = request($request), 'Request' ); 
     100    is_deeply( [ $response->content_type ], [ 'application/json', 'charset=utf-8' ] ); 
     101    my $bom = substr $response->content, 0, 3; 
     102    is $bom, "\xEF\xBB\xBF"; 
     103} 
     104 
     105{ 
     106    my $request = HTTP::Request->new( GET => "http://localhost/foo3" ); 
     107    $request->header("User-Agent", "Safari"); 
     108 
     109    ok( my $response = request($request), 'Request' ); 
     110    is_deeply( [ $response->content_type ], [ 'application/json', 'charset=utf-8' ] ); 
     111    my $bom = substr $response->content, 0, 3; 
     112    is $bom, "\xEF\xBB\xBF"; 
     113} 
     114 
     115{ 
     116    my $request = HTTP::Request->new( GET => "http://localhost/foo3" ); 
     117    $request->header("X-Prototype-Version", "1.5"); 
     118 
     119    ok( my $response = request($request), 'Request' ); 
     120    ok $response->header('X-JSON'); 
     121} 
     122 
     123{ 
     124    my $request = HTTP::Request->new( GET => "http://localhost/foo5" ); 
     125    $request->header("X-Prototype-Version", "1.5"); 
     126 
     127    ok( my $response = request($request), 'Request' ); 
     128    ok !$response->header('X-JSON'); 
     129} 
     130 
     131 
  • Catalyst-View-JSON/trunk/t/lib/TestApp.pm

    r1719 r2120  
    4242    my( $self, $c ) = @_; 
    4343    $c->stash->{json_foo} = "\x{5bae}\x{5ddd}"; 
     44    $c->component('View::JSON')->encoding('utf-8'); 
    4445    $c->forward('TestApp::View::JSON'); 
    4546} 
     
    5253} 
    5354 
     55sub foo5 : Global { 
     56    my( $self, $c ) = @_; 
     57    $c->stash->{json_foo} = "\x{5bae}\x{5ddd}"; 
     58    $c->component('View::JSON')->no_x_json_header(1); 
     59    $c->forward('TestApp::View::JSON'); 
     60} 
     61 
    5462sub finalize_error { 
    5563    my $c = shift;