@@ -21,18 +21,18 @@ use warnings;
2121# core modules
2222
2323# CPAN modules
24+ use Test2::V0;
2425
2526# OTOBO modules
26- use Kernel::System::UnitTest::RegisterDriver; # Set up $Self and $Kernel::OM
27-
28- our $Self ;
27+ use Kernel::System::UnitTest::RegisterDriver; # Set up $Kernel::OM
28+ use Kernel::System::UnitTest::MockTime qw( :all) ;
2929
3030# get helper object
31- $Kernel::OM -> ObjectParamAdd(
32- ' Kernel::System::UnitTest::Helper' => {
33- RestoreDatabase => 1,
34- },
35- );
31+ # $Kernel::OM->ObjectParamAdd(
32+ # 'Kernel::System::UnitTest::Helper' => {
33+ # RestoreDatabase => 1,
34+ # },
35+ # );
3636my $Helper = $Kernel::OM -> Get(' Kernel::System::UnitTest::Helper' );
3737
3838# set config options
@@ -65,35 +65,33 @@ my %FAQAddTemplate = (
6565 StateID => 1,
6666 LanguageID => 1,
6767 Keywords => $RandomID ,
68- Field1 => ' Problem...' ,
6968 Field2 => ' Solution...' ,
7069 UserID => 1,
7170 ContentType => ' text/html' ,
7271);
7372
7473# freeze time
75- $Helper -> FixedTimeSet();
74+ FixedTimeSet(); # t=0m
7675
7776# get FAQ object
7877my $FAQObject = $Kernel::OM -> Get(' Kernel::System::FAQ' );
7978
79+ # add two FAQs with creation time 60 s apart
80+ my @Field1 ;
8081for my $Counter ( 1 .. 2 ) {
82+ push @Field1 , sprintf ' Field1 Counter: %d, time: %d' , $Counter , time ;
8183 my $ItemID = $FAQObject -> FAQAdd(
8284 %FAQAddTemplate ,
8385 UserID => $AddedUsers [ $Counter - 1 ],
86+ Field1 => $Field1 [-1],
8487 );
8588
86- $Self -> IsNot(
87- undef ,
88- $ItemID ,
89- " FAQAdd() ItemID:'$ItemID ' for FAQSearch()" ,
90- );
91-
89+ ok( defined $ItemID , " FAQAdd() $Counter ItemID:'$ItemID ' for FAQSearch()" , );
9290 push @AddedFAQs , $ItemID ;
9391
9492 # add 1 minute to frozen time
95- $Helper -> FixedTimeAddSeconds(60);
96- }
93+ FixedTimeAddSeconds(60);
94+ } # t=2m
9795
9896# add some votes
9997my @VotesToAdd = (
@@ -142,23 +140,20 @@ my @VotesToAdd = (
142140for my $Vote (@VotesToAdd ) {
143141 my $Success = $FAQObject -> VoteAdd( %{$Vote } );
144142
145- $Self -> True(
146- $Success ,
147- " VoteAdd(): ItemID:'$Vote ->{ItemID}' IP:'$Vote ->{IP}' Rate:'$Vote ->{Rate}' with true" ,
148- );
143+ ok( $Success , " VoteAdd(): ItemID:'$Vote ->{ItemID}' IP:'$Vote ->{IP}' Rate:'$Vote ->{Rate}' with true" );
149144}
150145
151146# do vote search tests
152147my %SearchConfigTemplate = (
153- Keyword => " $RandomID " ,
148+ Keyword => $RandomID ,
154149 States => [ ' public' , ' internal' ],
155150 OrderBy => [' FAQID' ],
156151 OrderByDirection => [' Up' ],
157152 Limit => 150,
158153 UserID => 1,
159154
160155);
161- my @Tests = (
156+ my @VotesTests = (
162157
163158 # votes tests
164159 {
@@ -490,18 +485,14 @@ my @Tests = (
490485);
491486
492487# execute the tests
493- for my $Test (@Tests ) {
488+ for my $Test (@VotesTests ) {
494489 my @ItemIDs = $FAQObject -> FAQSearch( %{ $Test -> {Config } } );
495490
496- $Self -> IsDeeply(
497- \@ItemIDs ,
498- $Test -> {ExpectedResults },
499- " $Test ->{Name} FAQSearch()" ,
500- );
491+ is( \@ItemIDs , $Test -> {ExpectedResults }, " $Test ->{Name} FAQSearch()" );
501492}
502493
503494# other tests
504- @Tests = (
495+ my @OtherTests = (
505496 {
506497 Name => ' States Hash Correct IDs' ,
507498 Config => {
@@ -542,14 +533,10 @@ for my $Test (@Tests) {
542533);
543534
544535# execute the tests
545- for my $Test (@Tests ) {
536+ for my $Test (@OtherTests ) {
546537 my @ItemIDs = $FAQObject -> FAQSearch( %{ $Test -> {Config } } );
547538
548- $Self -> IsDeeply(
549- \@ItemIDs ,
550- $Test -> {ExpectedResults },
551- " $Test ->{Name} FAQSearch()" ,
552- );
539+ is( \@ItemIDs , $Test -> {ExpectedResults }, " $Test ->{Name} FAQSearch()" );
553540}
554541
555542# time based tests
@@ -561,41 +548,36 @@ my %FAQUpdateTemplate = (
561548 StateID => 1,
562549 LanguageID => 1,
563550 Keywords => $RandomID ,
564- Field1 => ' Problem...' ,
565551 Field2 => ' Solution...' ,
566552 UserID => 1,
567553 ContentType => ' text/html' ,
568554);
569555
570556# add 1 minute to frozen time
571- $Helper -> FixedTimeAddSeconds(60);
557+ FixedTimeAddSeconds(60); # t=3m
572558
573559my $Success = $FAQObject -> FAQUpdate(
574560 %FAQUpdateTemplate ,
575561 ItemID => $AddedFAQs [0],
562+ Field1 => " Updated $Field1 [0]" ,
576563 UserID => $AddedUsers [2],
577564);
578565
579- $Self -> True(
580- $Success ,
581- " FAQUpdate() ItemID:'$AddedFAQs [0]' for FAQSearch()" ,
582- );
566+ ok( $Success , " FAQUpdate() ItemID:'$AddedFAQs [0]' for FAQSearch()" );
583567
584- $Helper -> FixedTimeAddSeconds(60);
568+ FixedTimeAddSeconds(60); # t=4m
585569
586570$Success = $FAQObject -> FAQUpdate(
587571 %FAQUpdateTemplate ,
588572 ItemID => $AddedFAQs [1],
573+ Field1 => " Updated $Field1 [1]" ,
589574 UserID => $AddedUsers [3],
590575);
591576
592- $Self -> True(
593- $Success ,
594- " FAQUpdate() ItemID:'$AddedFAQs [1]' for FAQSearch()" ,
595- );
577+ ok( $Success , " FAQUpdate() ItemID:'$AddedFAQs [1]' for FAQSearch()" );
596578
597579# add 2 minutes to frozen time
598- $Helper -> FixedTimeAddSeconds(120);
580+ FixedTimeAddSeconds(120); # t=6m
599581
600582my $DateTime = $Kernel::OM -> Create(' Kernel::System::DateTime' );
601583
@@ -611,7 +593,8 @@ my $DateMinus5Mins = $DateTime->ToString();
611593$DateTime -> Subtract( Seconds => 60 );
612594my $DateMinus6Mins = $DateTime -> ToString();
613595
614- @Tests = (
596+ # Two FAQs were added. One 6 minutes ago, the other 5 minutes ago
597+ my @TimeBasedTests = (
615598 {
616599 Name => ' CreateTimeOlderMinutes 3 min' ,
617600 Config => {
@@ -728,19 +711,14 @@ my $DateMinus6Mins = $DateTime->ToString();
728711);
729712
730713# execute the tests
731- for my $Test (@Tests ) {
732-
714+ for my $Test (@TimeBasedTests ) {
733715 my @ItemIDs = $FAQObject -> FAQSearch( %{ $Test -> {Config } } );
734716
735- $Self -> IsDeeply(
736- \@ItemIDs ,
737- $Test -> {ExpectedResults },
738- " $Test ->{Name} FAQSearch()" ,
739- );
717+ is( \@ItemIDs , $Test -> {ExpectedResults }, " $Test ->{Name} FAQSearch()" );
740718}
741719
742720# created user tests
743- @Tests = (
721+ my @CreatedUserTests = (
744722 {
745723 Name => ' CreatedUserIDs 1' ,
746724 Config => {
@@ -785,8 +763,15 @@ for my $Test (@Tests) {
785763 },
786764);
787765
766+ # execute the tests
767+ for my $Test (@CreatedUserTests ) {
768+ my @ItemIDs = $FAQObject -> FAQSearch( %{ $Test -> {Config } } );
769+
770+ is( \@ItemIDs , $Test -> {ExpectedResults }, " $Test ->{Name} FAQSearch()" );
771+ }
772+
788773# last changed user tests
789- @Tests = (
774+ my @LastChangedUserTests = (
790775 {
791776 Name => ' LastChangedUserIDs 3' ,
792777 Config => {
@@ -829,15 +814,10 @@ for my $Test (@Tests) {
829814);
830815
831816# execute the tests
832- for my $Test (@Tests ) {
833-
817+ for my $Test (@LastChangedUserTests ) {
834818 my @ItemIDs = $FAQObject -> FAQSearch( %{ $Test -> {Config } } );
835819
836- $Self -> IsDeeply(
837- \@ItemIDs ,
838- $Test -> {ExpectedResults },
839- " $Test ->{Name} FAQSearch()" ,
840- );
820+ is( \@ItemIDs , $Test -> {ExpectedResults }, " $Test ->{Name} FAQSearch()" );
841821}
842822
843823# approval tests
@@ -853,7 +833,7 @@ return if !$Kernel::OM->Get('Kernel::System::DB')->Do(
853833 ],
854834);
855835
856- @Tests = (
836+ my @ApprovalTests = (
857837 {
858838 Name => ' Approved 1' ,
859839 Config => {
@@ -877,22 +857,14 @@ return if !$Kernel::OM->Get('Kernel::System::DB')->Do(
877857);
878858
879859# execute the tests
880- for my $Test (@Tests ) {
881-
860+ for my $Test (@ApprovalTests ) {
882861 my @ItemIDs = $FAQObject -> FAQSearch( %{ $Test -> {Config } } );
883862
884- $Self -> IsDeeply(
885- \@ItemIDs ,
886- $Test -> {ExpectedResults },
887- " $Test ->{Name} FAQSearch()" ,
888- );
863+ is( \@ItemIDs , $Test -> {ExpectedResults }, " $Test ->{Name} FAQSearch()" );
889864}
890865
891866# execute old tests
892- $Self -> True(
893- 1,
894- " --Execute Former Tests--" ,
895- );
867+ diag(" Execute Former Tests" );
896868{
897869 my $ItemID1 = $FAQObject -> FAQAdd(
898870 CategoryID => 1,
@@ -906,13 +878,10 @@ $Self->True(
906878 UserID => 1,
907879 ContentType => ' text/html' ,
908880 );
909- $Self -> True(
910- $ItemID1 ,
911- " FAQAdd() - 1" ,
912- );
881+ ok( $ItemID1 , " FAQAdd() - 1" );
913882
914883 # add 1 minute to frozen time
915- $Helper -> FixedTimeAddSeconds(60);
884+ FixedTimeAddSeconds(60); # t=7m
916885
917886 my $ItemID2 = $FAQObject -> FAQAdd(
918887 Title => ' Title' . $RandomID ,
@@ -925,13 +894,10 @@ $Self->True(
925894 UserID => 1,
926895 ContentType => ' text/html' ,
927896 );
928- $Self -> True(
929- $ItemID2 ,
930- " FAQAdd() - 2" ,
931- );
897+ ok( $ItemID2 , " FAQAdd() - 2" );
932898
933899 # add 1 minute to frozen time
934- $Helper -> FixedTimeAddSeconds(60);
900+ FixedTimeAddSeconds(60); # t=8m
935901
936902 my %Keywords = (
937903 Keyword1 => " some1$RandomID " ,
@@ -950,13 +916,10 @@ $Self->True(
950916 UserID => 1,
951917 ContentType => ' text/html' ,
952918 );
953- $Self -> True(
954- $ItemID3 ,
955- " FAQAdd() - 3" ,
956- );
919+ ok( $ItemID3 , " FAQAdd() - 3" );
957920
958921 # add 1 minute to frozen time
959- $Helper -> FixedTimeAddSeconds(60);
922+ FixedTimeAddSeconds(60); # t=9m
960923
961924 my $ItemID4 = $FAQObject -> FAQAdd(
962925 Title => ' Test FAQ-4' ,
@@ -969,13 +932,10 @@ $Self->True(
969932 ContentType => ' text/html' ,
970933 );
971934
972- $Self -> True(
973- $ItemID4 ,
974- " FAQAdd() - 4" ,
975- );
935+ ok( $ItemID4 , " FAQAdd() - 4" );
976936
977937 # add 1 minute to frozen time
978- $Helper -> FixedTimeAddSeconds(60);
938+ FixedTimeAddSeconds(60); # t=10m
979939
980940 my $ItemID5 = $FAQObject -> FAQAdd(
981941 Title => ' Test FAQ-5' ,
@@ -988,15 +948,12 @@ $Self->True(
988948 ContentType => ' text/html' ,
989949 );
990950
991- $Self -> True(
992- $ItemID5 ,
993- " FAQAdd() - 4" ,
994- );
951+ ok( $ItemID5 , " FAQAdd() - 4" );
995952
996953 # restore time
997- $Helper -> FixedTimeUnset();
954+ FixedTimeUnset();
998955
999- @Tests = (
956+ my @Tests = (
1000957 {
1001958 Name => ' Keywords' ,
1002959 Config => {
@@ -1172,7 +1129,6 @@ $Self->True(
11721129 );
11731130
11741131 for my $Test (@Tests ) {
1175-
11761132 my @ItemIDs = $FAQObject -> FAQSearch(
11771133 Number => ' *' ,
11781134 States => [ ' public' , ' internal' ],
@@ -1182,12 +1138,8 @@ $Self->True(
11821138 %{ $Test -> {Config } },
11831139 );
11841140
1185- $Self -> IsDeeply(
1186- \@ItemIDs ,
1187- $Test -> {ExpectedResults },
1188- " $Test ->{Name}, FAQSearch()" ,
1189- );
1141+ is( \@ItemIDs , $Test -> {ExpectedResults }, " $Test ->{Name}, FAQSearch()" );
11901142 }
11911143}
11921144
1193- $Self -> DoneTesting ();
1145+ done_testing ();
0 commit comments