App-SD

 view release on metacpan or  search on metacpan

t/sd-trac/basic.t  view on Meta::CPAN

use strict;

use Prophet::Test;
use App::SD::Test;
use Test::Script::Run qw/:all/;

BEGIN {
    require File::Temp;
    $ENV{'PROPHET_REPO'} = $ENV{'SD_REPO'} = File::Temp::tempdir( CLEANUP => 1 ) . '/_svb';
    diag "export SD_REPO=" . $ENV{'PROPHET_REPO'} . "\n";
}

unless (`which trac-admin`) { plan skip_all => 'You need trac installed to run the tests'; }
unless ( eval { require Net::Trac } ) {
    plan skip_all => 'You need Net::Trac installed to run the tests';
}
plan tests => 46;

use_ok('Net::Trac::Connection');
use_ok('Net::Trac::Ticket');
require 't/sd-trac/setup_trac.pl';

my $tr = Net::Trac::TestHarness->new();
ok( $tr->start_test_server(), "The server started!" );

my $trac = Net::Trac::Connection->new(
    url      => $tr->url,
    user     => 'hiro',
    password => 'yatta'
);

my $sd_trac_url = "trac:" . $tr->url;
$sd_trac_url =~ s|http://|http://hiro:yatta@|;

isa_ok( $trac, "Net::Trac::Connection" );
is( $trac->url, $tr->url );

is(count_tickets_in_trac(),0);


# 
# Create a ticket in trac
#

my $ticket = Net::Trac::Ticket->new( connection => $trac );
isa_ok( $ticket, 'Net::Trac::Ticket' );

ok( $ticket->create( summary => 'This product has only a moose, not a pony' ) );
is( $ticket->id, 1 );

is(count_tickets_in_trac(),1);


#
# Update a ticket in trac
#

can_ok( $ticket, 'load' );
ok( $ticket->load(1) );
like( $ticket->state->{'summary'}, qr/pony/ );
like( $ticket->summary, qr/moose/, "The summary looks like a moose" );

sleep 2; # to make trac happy
ok( $ticket->update( summary => 'The product does not contain a pony' ),
    "updated!" );
unlike( $ticket->summary, qr/moose/, "The summary does not look like a moose" );

my ($fh, $filename) = File::Temp::tempfile(SUFFIX => '.txt', UNLINK => 1);
print $fh "TIMTOWTDI\n";
close $fh;
sleep 2; # to make trac happy
ok($ticket->attach( file => $filename ), "Attaching file.");

my $history = $ticket->history;
ok( $history, "The ticket has some history" );
my @entries = @{ $history->entries };
is( scalar @entries, 3, "There are 3 txns");
my $first   = shift @entries;
is( $first->category, 'Ticket' );

# 
# Clone from trac
#

my ( $ret, $out, $err );
( $ret, $out, $err )
    = run_script( 'sd', [ 'clone', '--from', $sd_trac_url, '--non-interactive' ] );

is(count_tickets_in_sd(),1);

diag($out);
diag($err);
my $pony_id;


#
# Check our clone from trac
#

run_output_matches(
    'sd',
    [ 'ticket', 'list', '--regex', '.' ],
    [qr/(.*?)(?{ $pony_id = $1 }) The product does not contain a pony new/]
);

ok( $pony_id, "I got the ID of a pony - It's $pony_id" );

my ( $att_id, $att_name );
run_output_matches(
    'sd',
    [ 'attachment', 'list', ],
    [qr!(\d+)(?{ $att_id = $1 }) (\S+)(?{$att_name=$2}) text/plain!]
);

like( $filename, qr/$att_name/, 'filename of attachment' );

run_output_matches(
    'sd',
    [ 'attachment', 'content', $att_id ],
    [qr/TIMTOWTDI/]
);



( run in 2.553 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )