[otrs-cvs] ITSMConfigurationManagement/scripts/test ITSMConfigItem.t, 1.14, 1.14.2.1

"CVS commits notifications of OTRS.org" <[email protected]>
Newsgroups gmane.comp.otrs.cvs
Message-ID <[email protected]>
Comments:
Update of /home/cvs/ITSMConfigurationManagement/scripts/test
In directory lancelot:/tmp/cvs-serv11903/scripts/test

Modified Files:
      Tag: rel-3_1
	ITSMConfigItem.t 
Log Message:
Added attachment support for ITSM config items.

Author: ub

Index: ITSMConfigItem.t
===================================================================
RCS file: /home/cvs/ITSMConfigurationManagement/scripts/test/ITSMConfigItem.t,v
retrieving revision 1.14
retrieving revision 1.14.2.1
diff -2 -u -d -r1.14 -r1.14.2.1
--- ITSMConfigItem.t	31 Oct 2012 13:30:05 -0000	1.14
+++ ITSMConfigItem.t	30 Nov 2012 17:07:57 -0000	1.14.2.1
@@ -3208,4 +3208,137 @@
 
 # ------------------------------------------------------------ #
+# testing support for attachments
+# ------------------------------------------------------------ #
+
+my $AttachmentTestConfigItemID = $ConfigItemIDs[0];
+
+# verify that initialy no attachment exists
+my @AttachmentList = $Self->{ConfigItemObject}->ConfigItemAttachmentList(
+    ConfigItemID => $AttachmentTestConfigItemID,
+);
+
+$Self->Is(
+    scalar @AttachmentList,
+    0,
+    'No attachments initially',
+);
+
+my @TestFileList = (
+    {
+        Filename    => 'first attachment',
+        Content     => 'First attachment from ITSMConfigItem.t',
+        ContentType => 'text/plain',
+    },
+    {
+        Filename    => 'second attachment',
+        Content     => 'Second attachment from ITSMConfigItem.t',
+        ContentType => 'text/plain',
+    },
+);
+
+my $FileCount;
+for my $TestFile (@TestFileList) {
+
+    $FileCount++;
+
+    my $AddOk = $Self->{ConfigItemObject}->ConfigItemAttachmentAdd(
+        %{$TestFile},
+        ConfigItemID => $AttachmentTestConfigItemID,
+        UserID       => 1,
+    );
+    $Self->True(
+        $AddOk,
+        "Attachment $FileCount: attachment added",
+    );
+
+    my @AttachmentList = $Self->{ConfigItemObject}->ConfigItemAttachmentList(
+        ConfigItemID => $AttachmentTestConfigItemID,
+        UserID       => 1,
+    );
+    $Self->Is(
+        scalar @AttachmentList,
+        $FileCount,
+        "Attachment $FileCount: number of attachments after adding",
+    );
+
+    # check whether the last added attachment is in the list
+    my %AttachmentLookup = map { $_ => 1 } @AttachmentList;
+    $Self->True(
+        $AttachmentLookup{ $TestFile->{Filename} },
+        "Attachment $FileCount: filename from ConfigItemAttachmentList()",
+    );
+
+    # get the attachment
+    my $Attachment = $Self->{ConfigItemObject}->ConfigItemAttachmentGet(
+        ConfigItemID => $AttachmentTestConfigItemID,
+        Filename     => $TestFile->{Filename},
+    );
+    $Self->True(
+        $Attachment,
+        "Attachment $FileCount: ConfigItemAttachmentGet() returned true",
+    );
+
+    # check attachment file attributes
+    for my $Attribute (qw(Filename Content ContentType)) {
+        $Self->Is(
+            $Attachment->{$Attribute},
+            $TestFile->{$Attribute},
+            "Attachment $FileCount: $Attribute from ConfigItemAttachmentGet",
+        );
+    }
+
+    # check existence of attachment
+    my $AttachmentExists = $Self->{ConfigItemObject}->ConfigItemAttachmentExists(
+        ConfigItemID => $AttachmentTestConfigItemID,
+        Filename     => $TestFile->{Filename},
+        UserID       => 1,
+    );
+    $Self->True(
+        $AttachmentExists,
+        "Attachment $FileCount: attachment exists",
+    );
+
+}
+
+# now delete the attachments
+$FileCount = 0;
+my $MaxTestFiles = scalar @TestFileList;
+for my $TestFile (@TestFileList) {
+
+    $FileCount++;
+
+    my $DeleteOk = $Self->{ConfigItemObject}->ConfigItemAttachmentDelete(
+        ConfigItemID => $AttachmentTestConfigItemID,
+        Filename     => $TestFile->{Filename},
+        UserID       => 1,
+    );
+    $Self->True(
+        $DeleteOk,
+        "Attachment $FileCount: attachment deleted",
+    );
+
+    my @AttachmentList = $Self->{ConfigItemObject}->ConfigItemAttachmentList(
+        ConfigItemID => $AttachmentTestConfigItemID,
+        UserID       => 1,
+    );
+
+    $Self->Is(
+        scalar @AttachmentList,
+        $MaxTestFiles - $FileCount,
+        "Attachment $FileCount: number of attachments after deletion",
+    );
+
+    my $AttachmentExists = $Self->{ConfigItemObject}->ConfigItemAttachmentExists(
+        Filename     => $TestFile->{Filename},
+        ConfigItemID => $AttachmentTestConfigItemID,
+        UserID       => 1,
+    );
+    $Self->False(
+        $AttachmentExists,
+        "Attachment $FileCount: attachment is gone",
+    );
+}
+
+# ------------------------------------------------------------ #
 # clean the system
 # ------------------------------------------------------------ #
---------------------------------------------------------------------
OTRS mailing list: cvs-log - Webpage: http://otrs.org/
Archive: http://lists.otrs.org/pipermail/cvs-log
To unsubscribe: http://lists.otrs.org/cgi-bin/listinfo/cvs-log
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.