diff options
Diffstat (limited to 'rt/t/api')
-rw-r--r-- | rt/t/api/attachment.t | 26 | ||||
-rw-r--r-- | rt/t/api/attachment_filename.t | 39 | ||||
-rw-r--r-- | rt/t/api/cf_rights.t | 51 | ||||
-rw-r--r-- | rt/t/api/link.t | 203 | ||||
-rw-r--r-- | rt/t/api/password-types.t | 31 | ||||
-rw-r--r-- | rt/t/api/scrip.t | 74 | ||||
-rw-r--r-- | rt/t/api/txn_content.t | 19 |
7 files changed, 432 insertions, 11 deletions
diff --git a/rt/t/api/attachment.t b/rt/t/api/attachment.t index 07c46bad0..282d2a3de 100644 --- a/rt/t/api/attachment.t +++ b/rt/t/api/attachment.t @@ -2,7 +2,7 @@ use strict; use warnings; use RT; -use RT::Test tests => 4; +use RT::Test tests => 7; { @@ -42,4 +42,28 @@ is ($#headers, 2, "testing a bunch of singline multiple headers" ); } + +{ + my $iso_8859_1_ticket_email = + RT::Test::get_relocatable_file( 'new-ticket-from-iso-8859-1', + ( File::Spec->updir(), 'data', 'emails' ) ); + my $content = RT::Test->file_content($iso_8859_1_ticket_email); + + my $parser = RT::EmailParser->new; + $parser->ParseMIMEEntityFromScalar($content); + my $attachment = RT::Attachment->new( $RT::SystemUser ); + my ( $id, $msg ) = + $attachment->Create( TransactionId => 1, Attachment => $parser->Entity ); + ok( $id, $msg ); + my $mime = $attachment->ContentAsMIME; + like( $mime->head->get('Content-Type'), + qr/charset="iso-8859-1"/, 'content type of ContentAsMIME is original' ); + require Encode; + is( + Encode::decode( 'iso-8859-1', $mime->stringify_body ), + Encode::decode( 'utf8', "HÃ¥vard\n" ), + 'body of ContentAsMIME is original' + ); +} + 1; diff --git a/rt/t/api/attachment_filename.t b/rt/t/api/attachment_filename.t new file mode 100644 index 000000000..2eced0127 --- /dev/null +++ b/rt/t/api/attachment_filename.t @@ -0,0 +1,39 @@ +use RT::Test tests => 5; +use MIME::Entity; +my $ticket = RT::Ticket->new($RT::SystemUser); +my $mime = MIME::Entity->build( + From => 'test@example.com', + Type => 'text/html', + Data => ["test attachment's filename\n"], +); + +$mime->attach( + Path => 'share/html/NoAuth/images/bplogo.gif', + Type => 'image/gif', +); + +$mime->attach( + Path => 'share/html/NoAuth/images/bplogo.gif', + Type => 'image/gif', + Filename => 'bplogo.gif', +); + +$mime->attach( + Path => 'share/html/NoAuth/images/bplogo.gif', + Filename => 'images/bplogo.gif', + Type => 'image/gif', +); + +my $id = $ticket->Create( MIMEObj => $mime, Queue => 'General' ); +ok( $id, "created ticket $id" ); + +my $atts = RT::Attachments->new( $RT::SystemUser ); +$atts->Limit( FIELD => 'ContentType', VALUE => 'image/gif' ); +is( $atts->Count, 3, 'got 3 gif files' ); + +# no matter if mime's filename include path or not, +# we should throw away the path all the time. +while ( my $att = $atts->Next ) { + is( $att->Filename, 'bplogo.gif', "attachment's filename" ); +} + diff --git a/rt/t/api/cf_rights.t b/rt/t/api/cf_rights.t new file mode 100644 index 000000000..f55214a66 --- /dev/null +++ b/rt/t/api/cf_rights.t @@ -0,0 +1,51 @@ +#!/usr/bin/perl +use warnings; +use strict; + +use RT; +use RT::Test tests => 12; + +my $q = RT::Queue->new($RT::SystemUser); +my ($id,$msg) =$q->Create(Name => "CF-Rights-".$$); +ok($id,$msg); + +my $cf = RT::CustomField->new($RT::SystemUser); +($id,$msg) = $cf->Create(Name => 'CF-'.$$, Type => 'Select', MaxValues => '1', Queue => $q->id); +ok($id,$msg); + + +($id,$msg) =$cf->AddValue(Name => 'First'); +ok($id,$msg); + +my $u = RT::User->new($RT::SystemUser); +($id,$msg) = $u->Create( Name => 'User1', Privileged => 1 ); +ok ($id,$msg); + +($id,$msg) = $u->PrincipalObj->GrantRight( Object => $cf, Right => 'SeeCustomField' ); +ok ($id,$msg); + +my $ucf = RT::CustomField->new($u); +($id,$msg) = $ucf->Load( $cf->Id ); +ok ($id,$msg); + +my $cfv = $ucf->Values->First; + +($id,$msg) = $cfv->SetName( 'First1' ); +ok (!$id,$msg); + +($id,$msg) = $u->PrincipalObj->GrantRight( Object => $cf, Right => 'AdminCustomFieldValues' ); +ok ($id,$msg); + +($id,$msg) = $cfv->SetName( 'First2' ); +ok ($id,$msg); + +($id,$msg) = $u->PrincipalObj->RevokeRight( Object => $cf, Right => 'AdminCustomFieldValues' ); +ok ($id,$msg); + +($id,$msg) = $u->PrincipalObj->GrantRight( Object => $cf, Right => 'AdminCustomField' ); +ok ($id,$msg); + +($id,$msg) = $cfv->SetName( 'First3' ); +ok ($id,$msg); + +1; diff --git a/rt/t/api/link.t b/rt/t/api/link.t index 1fd66bb64..eac9ae29a 100644 --- a/rt/t/api/link.t +++ b/rt/t/api/link.t @@ -1,24 +1,209 @@ use strict; use warnings; -use RT; -use RT::Test tests => 5; - - -{ +use RT::Test tests => 77; +use RT::Test::Web; use RT::Link; my $link = RT::Link->new($RT::SystemUser); ok (ref $link); -ok (UNIVERSAL::isa($link, 'RT::Link')); -ok (UNIVERSAL::isa($link, 'RT::Base')); -ok (UNIVERSAL::isa($link, 'RT::Record')); -ok (UNIVERSAL::isa($link, 'DBIx::SearchBuilder::Record')); +isa_ok( $link, 'RT::Link'); +isa_ok( $link, 'RT::Base'); +isa_ok( $link, 'RT::Record'); +isa_ok( $link, 'DBIx::SearchBuilder::Record'); + +my $queue = RT::Test->load_or_create_queue(Name => 'General'); +ok($queue->Id, "loaded the General queue"); + +my $parent = RT::Ticket->new($RT::SystemUser); +my ($pid, undef, $msg) = $parent->Create( + Queue => $queue->id, + Subject => 'parent', +); +ok $pid, 'created a ticket #'. $pid or diag "error: $msg"; + +my $child = RT::Ticket->new($RT::SystemUser); +my ($cid, undef, $msg) = $child->Create( + Queue => $queue->id, + Subject => 'child', +); +ok $cid, 'created a ticket #'. $cid or diag "error: $msg"; + +{ + clean_links(); + my ($status, $msg) = $parent->AddLink; + ok(!$status, "didn't create a link: $msg"); + + ($status, $msg) = $parent->AddLink( Base => $parent->id ); + ok(!$status, "didn't create a link: $msg"); + + ($status, $msg) = $parent->AddLink( Base => $parent->id, Type => 'HasMember' ); + ok(!$status, "didn't create a link: $msg"); +} + +{ + clean_links(); + my ($status, $msg) = $parent->AddLink( + Type => 'MemberOf', Base => $child->id, + ); + ok($status, "created a link: $msg"); + + my $children = $parent->Members; + $children->RedoSearch; $children->GotoFirstItem; + is $children->Count, 1, 'link is there'; + + my $link = $children->First; + ok $link->id, 'correct link'; + + is $link->Type, 'MemberOf', 'type'; + is $link->LocalTarget, $parent->id, 'local target'; + is $link->LocalBase, $child->id, 'local base'; + is $link->Target, 'fsck.com-rt://example.com/ticket/'. $parent->id, 'local target'; + is $link->Base, 'fsck.com-rt://example.com/ticket/'. $child->id, 'local base'; + + isa_ok $link->TargetObj, 'RT::Ticket'; + is $link->TargetObj->id, $parent->id, 'correct ticket'; + + isa_ok $link->TargetURI, 'RT::URI'; + is $link->TargetURI->Scheme, 'fsck.com-rt', 'correct scheme'; + is $link->TargetURI->URI, + 'fsck.com-rt://example.com/ticket/'. $parent->id, + 'correct URI' + ; + ok $link->TargetURI->IsLocal, 'local object'; + is $link->TargetURI->AsHREF, + RT::Test::Web->rt_base_url .'Ticket/Display.html?id='. $parent->id, + 'correct href' + ; + + isa_ok $link->BaseObj, 'RT::Ticket'; + is $link->BaseObj->id, $child->id, 'correct ticket'; + + isa_ok $link->BaseURI, 'RT::URI'; + is $link->BaseURI->Scheme, 'fsck.com-rt', 'correct scheme'; + is $link->BaseURI->URI, + 'fsck.com-rt://example.com/ticket/'. $child->id, + 'correct URI' + ; + ok $link->BaseURI->IsLocal, 'local object'; + is $link->BaseURI->AsHREF, + RT::Test::Web->rt_base_url .'Ticket/Display.html?id='. $child->id, + 'correct href' + ; +} + +{ + clean_links(); + my ($status, $msg) = $parent->AddLink( + Type => 'MemberOf', Base => $child->URI, + ); + ok($status, "created a link: $msg"); + + my $children = $parent->Members; + $children->RedoSearch; $children->GotoFirstItem; + is $children->Count, 1, 'link is there'; + + my $link = $children->First; + ok $link->id, 'correct link'; + + is $link->Type, 'MemberOf', 'type'; + is $link->LocalTarget, $parent->id, 'local target'; + is $link->LocalBase, $child->id, 'local base'; + is $link->Target, 'fsck.com-rt://example.com/ticket/'. $parent->id, 'local target'; + is $link->Base, 'fsck.com-rt://example.com/ticket/'. $child->id, 'local base'; + + isa_ok $link->TargetObj, 'RT::Ticket'; + is $link->TargetObj->id, $parent->id, 'correct ticket'; + + isa_ok $link->TargetURI, 'RT::URI'; + is $link->TargetURI->Scheme, 'fsck.com-rt', 'correct scheme'; + is $link->TargetURI->URI, + 'fsck.com-rt://example.com/ticket/'. $parent->id, + 'correct URI' + ; + ok $link->TargetURI->IsLocal, 'local object'; + is $link->TargetURI->AsHREF, + RT::Test::Web->rt_base_url .'Ticket/Display.html?id='. $parent->id, + 'correct href' + ; + + isa_ok $link->BaseObj, 'RT::Ticket'; + is $link->BaseObj->id, $child->id, 'correct ticket'; + + isa_ok $link->BaseURI, 'RT::URI'; + is $link->BaseURI->Scheme, 'fsck.com-rt', 'correct scheme'; + is $link->BaseURI->URI, + 'fsck.com-rt://example.com/ticket/'. $child->id, + 'correct URI' + ; + ok $link->BaseURI->IsLocal, 'local object'; + is $link->BaseURI->AsHREF, + RT::Test::Web->rt_base_url .'Ticket/Display.html?id='. $child->id, + 'correct href' + ; +} + +{ + clean_links(); + my ($status, $msg) = $parent->AddLink( + Type => 'MemberOf', Base => 't:'. $child->id, + ); + ok($status, "created a link: $msg"); + + my $children = $parent->Members; + $children->RedoSearch; $children->GotoFirstItem; + is $children->Count, 1, 'link is there'; + + my $link = $children->First; + ok $link->id, 'correct link'; + is $link->Type, 'MemberOf', 'type'; + is $link->LocalTarget, $parent->id, 'local target'; + is $link->LocalBase, $child->id, 'local base'; + is $link->Target, 'fsck.com-rt://example.com/ticket/'. $parent->id, 'local target'; + is $link->Base, 'fsck.com-rt://example.com/ticket/'. $child->id, 'local base'; + + isa_ok $link->TargetObj, 'RT::Ticket'; + is $link->TargetObj->id, $parent->id, 'correct ticket'; + + isa_ok $link->TargetURI, 'RT::URI'; + is $link->TargetURI->Scheme, 'fsck.com-rt', 'correct scheme'; + is $link->TargetURI->URI, + 'fsck.com-rt://example.com/ticket/'. $parent->id, + 'correct URI' + ; + ok $link->TargetURI->IsLocal, 'local object'; + is $link->TargetURI->AsHREF, + RT::Test::Web->rt_base_url .'Ticket/Display.html?id='. $parent->id, + 'correct href' + ; + + isa_ok $link->BaseObj, 'RT::Ticket'; + is $link->BaseObj->id, $child->id, 'correct ticket'; + + isa_ok $link->BaseURI, 'RT::URI'; + is $link->BaseURI->Scheme, 'fsck.com-rt', 'correct scheme'; + is $link->BaseURI->URI, + 'fsck.com-rt://example.com/ticket/'. $child->id, + 'correct URI' + ; + ok $link->BaseURI->IsLocal, 'local object'; + is $link->BaseURI->AsHREF, + RT::Test::Web->rt_base_url .'Ticket/Display.html?id='. $child->id, + 'correct href' + ; +} +sub clean_links { + my $links = RT::Links->new( $RT::SystemUser ); + while ( my $link = $links->Next ) { + my ($status, $msg) = $link->Delete; + $RT::Logger->error("Couldn't delete a link: $msg") + unless $status; + } } 1; diff --git a/rt/t/api/password-types.t b/rt/t/api/password-types.t new file mode 100644 index 000000000..267a6ede4 --- /dev/null +++ b/rt/t/api/password-types.t @@ -0,0 +1,31 @@ +#!/usr/bin/perl -w +use strict; +use warnings; + +use RT::Test; +use Digest::MD5; + +my $root = RT::User->new(RT->SystemUser); +$root->Load("root"); + +# Salted truncated SHA-256 +my $old = $root->__Value("Password"); +is(length($old), 40, "Stored as truncated salted SHA-256"); +ok($root->IsPassword("password")); +is($root->__Value("Password"), $old, "Unchanged after password check"); + +# Crypt +$root->_Set( Field => "Password", Value => crypt("something", "salt")); +ok($root->IsPassword("something"), "crypt()ed password works"); +is(length($root->__Value("Password")), 40, "And is now upgraded to truncated salted SHA-256"); + +# MD5, hex +$root->_Set( Field => "Password", Value => Digest::MD5::md5_hex("changed")); +ok($root->IsPassword("changed"), "Unsalted MD5 hex works"); +is(length($root->__Value("Password")), 40, "And is now upgraded to truncated salted SHA-256"); + +# MD5, base64 +$root->_Set( Field => "Password", Value => Digest::MD5::md5_base64("new")); +ok($root->IsPassword("new"), "Unsalted MD5 base64 works"); +is(length($root->__Value("Password")), 40, "And is now upgraded to truncated salted SHA-256"); + diff --git a/rt/t/api/scrip.t b/rt/t/api/scrip.t index 8e8f96213..9d97e7344 100644 --- a/rt/t/api/scrip.t +++ b/rt/t/api/scrip.t @@ -2,7 +2,7 @@ use strict; use warnings; use RT; -use RT::Test tests => 7; +use RT::Test tests => 25; { @@ -46,4 +46,76 @@ isnt ($ticket2->Priority , '87', "Ticket priority is set right"); } + +{ + my $scrip = RT::Scrip->new($RT::SystemUser); + my ( $val, $msg ) = $scrip->Create( + ScripCondition => 'On Comment', + ScripAction => 'Notify Owner', + ); + ok( !$val, "missing template: $msg" ); + ( $val, $msg ) = $scrip->Create( + ScripCondition => 'On Comment', + ScripAction => 'Notify Owner', + Template => 'not exists', + ); + ok( !$val, "invalid template: $msg" ); + + ( $val, $msg ) = $scrip->Create( + ScripAction => 'Notify Owner', + Template => 'Blank', + ); + ok( !$val, "missing condition: $msg" ); + ( $val, $msg ) = $scrip->Create( + ScripCondition => 'not exists', + ScripAction => 'Notify Owner', + Template => 'Blank', + ); + ok( !$val, "invalid condition: $msg" ); + + ( $val, $msg ) = $scrip->Create( + ScripCondition => 'On Comment', + Template => 'Blank', + ); + ok( !$val, "missing action: $msg" ); + ( $val, $msg ) = $scrip->Create( + ScripCondition => 'On Comment', + ScripAction => 'not exists', + Template => 'Blank', + ); + ok( !$val, "invalid action: $msg" ); + + ( $val, $msg ) = $scrip->Create( + ScripAction => 'Notify Owner', + ScripCondition => 'On Comment', + Template => 'Blank', + ); + ok( $val, "created scrip: $msg" ); + $scrip->Load($val); + ok( $scrip->id, 'loaded scrip ' . $scrip->id ); + + ( $val, $msg ) = $scrip->SetScripCondition(); + ok( !$val, "missing condition: $msg" ); + ( $val, $msg ) = $scrip->SetScripCondition('not exists'); + ok( !$val, "invalid condition: $msg" ); + ( $val, $msg ) = $scrip->SetScripCondition('On Correspond'); + ok( $val, "updated condition to 'On Correspond': $msg" ); + + ( $val, $msg ) = $scrip->SetScripAction(); + ok( !$val, "missing action: $msg" ); + ( $val, $msg ) = $scrip->SetScripAction('not exists'); + ok( !$val, "invalid action: $msg" ); + ( $val, $msg ) = $scrip->SetScripAction('Notify AdminCcs'); + ok( $val, "updated action to 'Notify AdminCcs': $msg" ); + + ( $val, $msg ) = $scrip->SetTemplate(); + ok( !$val, "missing template $msg" ); + ( $val, $msg ) = $scrip->SetTemplate('not exists'); + ok( !$val, "invalid template $msg" ); + ( $val, $msg ) = $scrip->SetTemplate('Forward'); + ok( $val, "updated template to 'Forward': $msg" ); + + ok( $scrip->Delete, 'delete the scrip' ); +} + 1; diff --git a/rt/t/api/txn_content.t b/rt/t/api/txn_content.t new file mode 100644 index 000000000..0f5d78ca9 --- /dev/null +++ b/rt/t/api/txn_content.t @@ -0,0 +1,19 @@ +use warnings; +use strict; + +use RT::Test tests => 3; +use MIME::Entity; +my $ticket = RT::Ticket->new($RT::SystemUser); +my $mime = MIME::Entity->build( + From => 'test@example.com', + Type => 'text/html', + Data => ["this is body\n"], +); +$mime->attach( Data => ['this is attachment'] ); +my $id = $ticket->Create( MIMEObj => $mime, Queue => 'General' ); +ok( $id, "created ticket $id" ); +my $txns = $ticket->Transactions; +$txns->Limit( FIELD => 'Type', VALUE => 'Create' ); +my $txn = $txns->First; +ok( $txn, 'got Create txn' ); +is( $txn->Content, "this is body\n", "txn's content" ); |