[otrs-cvs] GeneralCatalog/scripts/test GeneralCatalog.t,1.8,1.9
cvs-log at otrs.org
cvs-log at otrs.org
Thu Mar 6 14:26:56 GMT 2008
Comments:
Update of /home/cvs/GeneralCatalog/scripts/test
In directory lancelot:/tmp/cvs-serv4880/scripts/test
Modified Files:
GeneralCatalog.t
Log Message:
Add some unittest.
Author: mh
Index: GeneralCatalog.t
===================================================================
RCS file: /home/cvs/GeneralCatalog/scripts/test/GeneralCatalog.t,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** GeneralCatalog.t 14 Feb 2008 13:34:22 -0000 1.8
--- GeneralCatalog.t 6 Mar 2008 14:26:51 -0000 1.9
***************
*** 12,15 ****
--- 12,16 ----
use strict;
use warnings;
+ use utf8;
use vars qw($Self);
***************
*** 19,29 ****
$Self->{GeneralCatalogObject} = Kernel::System::GeneralCatalog->new( %{$Self} );
! # create some random numbers
! my $Rand1 = int( rand(1_000_000) );
! my $Rand2 = int( rand(1_000_000) );
! my $Rand3 = int( rand(1_000_000) );
! my $Rand4 = int( rand(1_000_000) );
! my $Rand5 = int( rand(1_000_000) );
! my $Rand6 = int( rand(1_000_000) );
my $ItemData = [
--- 20,27 ----
$Self->{GeneralCatalogObject} = Kernel::System::GeneralCatalog->new( %{$Self} );
! # create some random numbers for the classes
! my $ClassRand1 = int( rand(1_000_000) );
! my $ClassRand2 = int( rand(1_000_000) );
! my $ClassRand3 = int( rand(1_000_000) );
my $ItemData = [
***************
*** 32,36 ****
{
Add => {
! Name => 'TestItem' . $Rand1,
ValidID => 1,
UserID => 1,
--- 30,34 ----
{
Add => {
! Name => 'TestItem1',
ValidID => 1,
UserID => 1,
***************
*** 41,45 ****
{
Add => {
! Class => 'UniTest::TestClass1',
ValidID => 1,
UserID => 1,
--- 39,43 ----
{
Add => {
! Class => 'UnitTest::TestClass' . $ClassRand1,
ValidID => 1,
UserID => 1,
***************
*** 50,55 ****
{
Add => {
! Class => 'UniTest::TestClass1',
! Name => 'TestItem' . $Rand2,
UserID => 1,
},
--- 48,53 ----
{
Add => {
! Class => 'UnitTest::TestClass' . $ClassRand1,
! Name => 'TestItem2',
UserID => 1,
},
***************
*** 59,64 ****
{
Add => {
! Class => 'UniTest::TestClass1',
! Name => 'TestItem' . $Rand3,
ValidID => 1,
},
--- 57,62 ----
{
Add => {
! Class => 'UnitTest::TestClass' . $ClassRand1,
! Name => 'TestItem3',
ValidID => 1,
},
***************
*** 68,79 ****
{
Add => {
! Class => 'UniTest::TestClass1',
! Name => 'TestItem' . $Rand4,
ValidID => 1,
UserID => 1,
},
AddGet => {
! Class => 'UniTest::TestClass1',
! Name => 'TestItem' . $Rand4,
Functionality => '',
ValidID => 1,
--- 66,77 ----
{
Add => {
! Class => 'UnitTest::TestClass' . $ClassRand1,
! Name => 'TestItem4',
ValidID => 1,
UserID => 1,
},
AddGet => {
! Class => 'UnitTest::TestClass' . $ClassRand1,
! Name => 'TestItem4',
Functionality => '',
ValidID => 1,
***************
*** 87,92 ****
{
Add => {
! Class => 'UniTest::TestClass1',
! Name => 'TestItem' . $Rand4,
ValidID => 1,
UserID => 1,
--- 85,90 ----
{
Add => {
! Class => 'UnitTest::TestClass' . $ClassRand1,
! Name => 'TestItem4',
ValidID => 1,
UserID => 1,
***************
*** 94,102 ****
},
# this item must be inserted sucessfully
{
Add => {
! Class => 'UniTest::TestClass1',
! Name => 'TestItem' . $Rand5,
Functionality => 'Test1',
ValidID => 1,
--- 92,110 ----
},
+ # the item one add-test before must be NOT updated (Func '' is the last in this class)
+ {
+ Update => {
+ Name => 'TestItem4UPDATE1',
+ Functionality => 'Test',
+ ValidID => 2,
+ UserID => 2,
+ },
+ },
+
# this item must be inserted sucessfully
{
Add => {
! Class => 'UnitTest::TestClass' . $ClassRand1,
! Name => 'TestItem5',
Functionality => 'Test1',
ValidID => 1,
***************
*** 104,109 ****
},
AddGet => {
! Class => 'UniTest::TestClass1',
! Name => 'TestItem' . $Rand5,
Functionality => 'Test1',
ValidID => 1,
--- 112,117 ----
},
AddGet => {
! Class => 'UnitTest::TestClass' . $ClassRand1,
! Name => 'TestItem5',
Functionality => 'Test1',
ValidID => 1,
***************
*** 125,129 ****
{
Update => {
! Name => 'TestItem' . $Rand5 . 'Edit',
UserID => 2,
},
--- 133,137 ----
{
Update => {
! Name => 'TestItem5UPDATE1',
UserID => 2,
},
***************
*** 133,151 ****
{
Update => {
! Name => 'TestItem' . $Rand5 . 'Edit',
! ValidID => 2,
},
},
! # the item one add-test before must be updated (item update arguments are complete)
{
Update => {
! Name => 'TestItem' . $Rand5 . 'Edit',
ValidID => 2,
UserID => 2,
},
UpdateGet => {
! Name => 'TestItem' . $Rand5 . 'Edit',
! Functionality => '',
ValidID => 2,
Comment => '',
--- 141,179 ----
{
Update => {
! Functionality => 'Test1',
! ValidID => 2,
},
},
! # the item one add-test before must be NOT updated (Func 'test1' is the last in this class)
{
Update => {
! Name => 'TestItem5',
ValidID => 2,
UserID => 2,
},
+ },
+
+ # the item one add-test before must be NOT updated (Func 'test1' is the last in this class)
+ {
+ Update => {
+ Name => 'TestItem5',
+ Functionality => 'Test2',
+ ValidID => 2,
+ UserID => 2,
+ },
+ },
+
+ # the item one add-test before must be updated (item update arguments are complete)
+ {
+ Update => {
+ Name => 'TestItem5UPDATE2',
+ Functionality => 'Test1',
+ ValidID => 2,
+ UserID => 2,
+ },
UpdateGet => {
! Name => 'TestItem5UPDATE2',
! Functionality => 'Test1',
ValidID => 2,
Comment => '',
***************
*** 158,162 ****
{
Update => {
! Name => 'TestItem' . $Rand5 . 'Edit',
Functionality => 'Test1',
ValidID => 1,
--- 186,190 ----
{
Update => {
! Name => 'TestItem5UPDATE3',
Functionality => 'Test1',
ValidID => 1,
***************
*** 164,168 ****
},
UpdateGet => {
! Name => 'TestItem' . $Rand5 . 'Edit',
Functionality => 'Test1',
ValidID => 1,
--- 192,196 ----
},
UpdateGet => {
! Name => 'TestItem5UPDATE3',
Functionality => 'Test1',
ValidID => 1,
***************
*** 173,190 ****
},
! # the item one add-test before must be updated (item update arguments are complete)
{
Update => {
! Name => 'TestItem' . $Rand6 . 'Edit',
! Functionality => 'Test2',
ValidID => 1,
! Comment => 'This is a comment.',
UserID => 1,
},
UpdateGet => {
! Name => 'TestItem' . $Rand6 . 'Edit',
! Functionality => 'Test2',
ValidID => 1,
! Comment => 'This is a comment.',
CreateBy => 1,
ChangeBy => 1,
--- 201,317 ----
},
! # this template must be inserted sucessfully (check string cleaner function)
! {
! Add => {
! Class => " \t \n \r Unit Test :: Test Class \t \n \r " . $ClassRand1,
! Name => " \t \n \r Test Item \t \n \r ",
! Functionality => " \t \n \r Test Functionality \t \n \r ",
! ValidID => 1,
! Comment => " \t \n \r Test Comment \t \n \r ",
! UserID => 1,
! },
! AddGet => {
! Class => 'UnitTest::TestClass' . $ClassRand1,
! Name => 'Test Item',
! Functionality => 'TestFunctionality',
! ValidID => 1,
! Comment => 'Test Comment',
! CreateBy => 1,
! ChangeBy => 1,
! },
! },
!
! # the item one add-test before must be updated sucessfully (check string cleaner function)
{
Update => {
! Name => " \t \n \r Test Item UPDATED \t \n \r ",
! Functionality => " \t \n \r Test Func tiona lity \t \n \r ",
! ValidID => 2,
! Comment => " \t \n \r Test Comment UPDATED \t \n \r ",
! UserID => 2,
! },
! UpdateGet => {
! Name => 'Test Item UPDATED',
! Functionality => 'TestFunctionality',
! ValidID => 2,
! Comment => 'Test Comment UPDATED',
! CreateBy => 1,
! ChangeBy => 2,
! },
! },
!
! # this item must be inserted sucessfully (unicode checks)
! {
! Add => {
! Class => 'UnitTest::TestClass©' . $ClassRand2,
! Name => ' Ï Ï¡ Test Item Æ© Ï ',
! Functionality => ' Ñ Ñ¤ TestFunctionality Ï Î© ',
ValidID => 1,
! Comment => ' Ï Ð¯ Test Comment Ѭ Ñ ',
UserID => 1,
},
+ AddGet => {
+ Class => 'UnitTest::TestClass©' . $ClassRand2,
+ Name => 'Ï Ï¡ Test Item Æ© Ï',
+ Functionality => 'Ñ Ñ¤TestFunctionalityÏ Î©',
+ ValidID => 1,
+ Comment => 'Ï Ð¯ Test Comment Ѭ Ñ ',
+ CreateBy => 1,
+ ChangeBy => 1,
+ },
+ },
+
+ # the item one add-test before must be updated sucessfully (unicode checks)
+ {
+ Update => {
+ Name => 'Test Item Ʃ ɤ UPDATED',
+ Functionality => ' Ñ Ñ¤ TestFunctionality Ï Î© ',
+ ValidID => 2,
+ Comment => ' Test Comment Ñ Ñ UPDATED ',
+ UserID => 2,
+ },
UpdateGet => {
! Name => 'Test Item Ʃ ɤ UPDATED',
! Functionality => 'Ñ Ñ¤TestFunctionalityÏ Î©',
! ValidID => 2,
! Comment => 'Test Comment Ñ Ñ UPDATED',
! CreateBy => 1,
! ChangeBy => 2,
! },
! },
!
! # this item must be inserted sucessfully (a second item with Functionality 'test1')
! {
! Add => {
! Class => 'UnitTest::TestClass' . $ClassRand1,
! Name => 'TestItem6',
! Functionality => 'Test1',
ValidID => 1,
! UserID => 1,
! },
! AddGet => {
! Class => 'UnitTest::TestClass' . $ClassRand1,
! Name => 'TestItem6',
! Functionality => 'Test1',
! ValidID => 1,
! Comment => '',
! CreateBy => 1,
! ChangeBy => 1,
! },
! },
!
! # the item one add-test before must be updated (set functionality to '')
! {
! Update => {
! Name => 'TestItem6UPDATE1',
! Functionality => '',
! ValidID => 1,
! UserID => 1,
! },
! UpdateGet => {
! Name => 'TestItem6UPDATE1',
! Functionality => '',
! ValidID => 1,
! Comment => '',
CreateBy => 1,
ChangeBy => 1,
***************
*** 195,198 ****
--- 322,327 ----
my $TestCount = 1;
my $LastAddedItemID;
+ my %AddedItemCounter;
+
for my $Item ( @{$ItemData} ) {
***************
*** 200,214 ****
# add new item
! my $ItemID = $Self->{GeneralCatalogObject}->ItemAdd( %{ $Item->{Add} } );
# check if item was added successfully or not
if ( $Item->{AddGet} ) {
- $Self->True( $ItemID, "Test $TestCount: ItemAdd() - ItemKey: $ItemID" );
! # set last item id variable
! $LastAddedItemID = $ItemID;
}
else {
! $Self->False( $ItemID, "Test $TestCount: ItemAdd()" );
}
--- 329,358 ----
# add new item
! my $ItemID = $Self->{GeneralCatalogObject}->ItemAdd(
! %{ $Item->{Add} },
! );
# check if item was added successfully or not
if ( $Item->{AddGet} ) {
! $Self->True(
! $ItemID,
! "Test $TestCount: ItemAdd() - ItemKey: $ItemID",
! );
!
! if ($ItemID) {
!
! # set last item id variable
! $LastAddedItemID = $ItemID;
!
! # increment the added item counter
! $AddedItemCounter{ $Item->{AddGet}->{Class} }++;
! }
}
else {
! $Self->False(
! $ItemID,
! "Test $TestCount: ItemAdd()",
! );
}
***************
*** 233,251 ****
# check last item id varaible
if ( !$LastAddedItemID ) {
! $Self->False( 1, "Test $TestCount: NO LAST ITEM ID GIVEN" );
}
# update the item
! my $UpdateSucess = $Self->{GeneralCatalogObject}
! ->ItemUpdate( %{ $Item->{Update} }, ItemID => $LastAddedItemID );
# check if item was updated successfully or not
if ( $Item->{UpdateGet} ) {
$Self->True(
! $UpdateSucess, "Test $TestCount: ItemUpdate() - ItemKey: $LastAddedItemID",
);
}
else {
! $Self->False( $UpdateSucess, "Test $TestCount: ItemUpdate()" );
}
--- 377,404 ----
# check last item id varaible
if ( !$LastAddedItemID ) {
! $Self->False(
! 1,
! "Test $TestCount: NO LAST ITEM ID GIVEN",
! );
}
# update the item
! my $UpdateSucess = $Self->{GeneralCatalogObject}->ItemUpdate(
! %{ $Item->{Update} },
! ItemID => $LastAddedItemID,
! );
# check if item was updated successfully or not
if ( $Item->{UpdateGet} ) {
$Self->True(
! $UpdateSucess,
! "Test $TestCount: ItemUpdate() - ItemKey: $LastAddedItemID",
);
}
else {
! $Self->False(
! $UpdateSucess,
! "Test $TestCount: ItemUpdate()",
! );
}
***************
*** 266,272 ****
}
- # increment the counter
$TestCount++;
}
1;
--- 419,698 ----
}
$TestCount++;
}
+ # create needed arrays
+ my %ExistingClassesTmp;
+ ITEM:
+ for my $Item ( @{$ItemData} ) {
+ next ITEM if !$Item->{AddGet}->{Class};
+ $ExistingClassesTmp{ $Item->{AddGet}->{Class} } = 1;
+ }
+ my @ExistingClasses = sort keys %ExistingClassesTmp;
+
+ my %ExistingFunctionalitiesTmp;
+ ITEM:
+ for my $Item ( @{$ItemData} ) {
+ $Item->{UpdateGet}->{Functionality} ||= '';
+ $ExistingFunctionalitiesTmp{ $Item->{UpdateGet}->{Functionality} } = 1;
+ }
+ my @ExistingFunctionalities = sort keys %ExistingFunctionalitiesTmp;
+
+ my @NonExistingClasses = ( 'UnitTest::NoExistingClass1', 'UnitTest::NoExistingClass2' );
+
+ # ClassList test 1
+ my $ClassList1 = $Self->{GeneralCatalogObject}->ClassList();
+
+ for my $Class (@ExistingClasses) {
+
+ my $ClassCount = 0;
+ if ( $ClassList1 && ref $ClassList1 eq 'ARRAY' ) {
+ $ClassCount = grep { $_ eq $Class } @{$ClassList1};
+ }
+
+ $Self->Is(
+ $ClassCount,
+ 1,
+ "Test $TestCount: ClassList() - $Class listed",
+ );
+
+ $TestCount++;
+ }
+
+ # ItemList test 1
+ for my $Class (@NonExistingClasses) {
+
+ my $ItemList = $Self->{GeneralCatalogObject}->ItemList(
+ Class => $Class,
+ Valid => 0,
+ );
+
+ $Self->False(
+ $ItemList,
+ "Test $TestCount: ItemList() - $Class not exists",
+ );
+
+ $TestCount++;
+ }
+
+ # ItemList test 2
+ for my $Class (@ExistingClasses) {
+
+ my $ItemList = $Self->{GeneralCatalogObject}->ItemList(
+ Class => $Class,
+ Valid => 0,
+ );
+
+ my $ListCount = 'NULL';
+ if ( defined $ItemList && ref $ItemList eq 'HASH' ) {
+ $ListCount = keys %{$ItemList};
+ }
+
+ $Self->Is(
+ $ListCount,
+ $AddedItemCounter{$Class},
+ "Test $TestCount: ItemList() - $Class correct number of items",
+ );
+
+ $TestCount++;
+ }
+
+ # FunctionalityList test 1
+ my %FunctionalityList1;
+ map { $FunctionalityList1{$_} = 1 } @ExistingFunctionalities;
+
+ for my $Class (@ExistingClasses) {
+
+ my $FunctionalityList = $Self->{GeneralCatalogObject}->FunctionalityList(
+ Class => $Class,
+ );
+
+ $Self->True(
+ $FunctionalityList && ref $FunctionalityList eq 'ARRAY',
+ "Test $TestCount: FunctionalityList() - return a array reference",
+ );
+
+ for my $Functionality ( @{$FunctionalityList} ) {
+ delete $FunctionalityList1{$Functionality};
+ }
+
+ $TestCount++;
+ }
+
+ $Self->True(
+ !keys %FunctionalityList1,
+ "Test $TestCount: FunctionalityList()",
+ );
+
+ $TestCount++;
+
+ # ClassRename test 1 (check normal rename)
+ CLASS:
+ for my $Class (@ExistingClasses) {
+
+ my $OldItemList = $Self->{GeneralCatalogObject}->ItemList(
+ Class => $Class,
+ Valid => 0,
+ );
+
+ my $Success = $Self->{GeneralCatalogObject}->ClassRename(
+ ClassOld => $Class,
+ ClassNew => $Class . 'RENAME1',
+ );
+
+ if ( !$Success ) {
+ $Self->False(
+ 1,
+ "Test $TestCount: ClassRename() - Rename failed",
+ );
+ next CLASS;
+ }
+
+ my $NewItemList = $Self->{GeneralCatalogObject}->ItemList(
+ Class => $Class . 'RENAME1',
+ Valid => 0,
+ );
+
+ if (
+ !$OldItemList
+ || !$NewItemList
+ || ref $OldItemList ne 'HASH'
+ || ref $NewItemList ne 'HASH'
+ )
+ {
+ $Self->False(
+ 1,
+ "Test $TestCount: ClassRename() - ItemList failed",
+ );
+ next CLASS;
+ }
+
+ OLDKEY:
+ for my $OldKey ( keys %{$OldItemList} ) {
+
+ if ( !exists $NewItemList->{$OldKey} ) {
+ $NewItemList->{FailedDummy} = 1;
+ next OLDKEY;
+ }
+
+ next OLDKEY if $OldItemList->{$OldKey} ne $NewItemList->{$OldKey};
+
+ delete $NewItemList->{$OldKey};
+ }
+
+ $Self->True(
+ !keys %{$NewItemList},
+ "Test $TestCount: ClassRename()",
+ );
+
+ $TestCount++;
+ }
+
+ # ClassRename test 2 (check string cleaner function)
+ CLASS:
+ for my $Class (@ExistingClasses) {
+
+ my $OldItemList = $Self->{GeneralCatalogObject}->ItemList(
+ Class => $Class . 'RENAME1',
+ Valid => 0,
+ );
+
+ my $Success = $Self->{GeneralCatalogObject}->ClassRename(
+ ClassOld => $Class . 'RENAME1',
+ ClassNew => ' ' . $Class . "RE NA ME 2 \n \r \t ",
+ );
+
+ if ( !$Success ) {
+ $Self->False(
+ 1,
+ "Test $TestCount: ClassRename() - Rename failed",
+ );
+ next CLASS;
+ }
+
+ my $NewItemList = $Self->{GeneralCatalogObject}->ItemList(
+ Class => $Class . 'RENAME2',
+ Valid => 0,
+ );
+
+ if (
+ !$OldItemList
+ || !$NewItemList
+ || ref $OldItemList ne 'HASH'
+ || ref $NewItemList ne 'HASH'
+ )
+ {
+ $Self->False(
+ 1,
+ "Test $TestCount: ClassRename() - ItemList failed",
+ );
+ next CLASS;
+ }
+
+ OLDKEY:
+ for my $OldKey ( keys %{$OldItemList} ) {
+
+ if ( !exists $NewItemList->{$OldKey} ) {
+ $NewItemList->{FailedDummy} = 1;
+ next OLDKEY;
+ }
+
+ next OLDKEY if $OldItemList->{$OldKey} ne $NewItemList->{$OldKey};
+
+ delete $NewItemList->{$OldKey};
+ }
+
+ $Self->True(
+ !keys %{$NewItemList},
+ "Test $TestCount: ClassRename()",
+ );
+
+ $TestCount++;
+ }
+
+ # ClassRename test 2 (identical name test)
+ for my $Class (@ExistingClasses) {
+
+ my $Success = $Self->{GeneralCatalogObject}->ClassRename(
+ ClassOld => $Class . 'RENAME2',
+ ClassNew => $Class . 'RENAME2',
+ );
+
+ $Self->True(
+ $Success,
+ "Test $TestCount: ClassRename() - oldname and newname identical",
+ );
+
+ $TestCount++;
+ }
+
+ # ClassRename test 3 (new class name already exists)
+ $Self->{GeneralCatalogObject}->ItemAdd(
+ Class => 'UnitTest::TestClass' . $ClassRand3,
+ Name => 'Dummy',
+ Functionality => '',
+ ValidID => 1,
+ UserID => 1,
+ );
+
+ for my $Class (@ExistingClasses) {
+
+ my $Success = $Self->{GeneralCatalogObject}->ClassRename(
+ ClassOld => $Class . 'RENAME2',
+ ClassNew => 'UnitTest::TestClass' . $ClassRand3,
+ );
+
+ $Self->False(
+ $Success,
+ "Test $TestCount: ClassRename() - new class name already exists",
+ );
+
+ $TestCount++;
+ }
+
+ # clean the general catalog table
+ $Self->{DBObject}->Do(
+ SQL => "DELETE FROM general_catalog WHERE general_catalog_class LIKE 'UnitTest%'",
+ );
+
1;
More information about the cvs-log
mailing list