1# -- 2# Copyright (C) 2001-2020 OTRS AG, https://otrs.com/ 3# -- 4# This software comes with ABSOLUTELY NO WARRANTY. For details, see 5# the enclosed file COPYING for license information (GPL). If you 6# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt. 7# -- 8 9## no critic (Modules::RequireExplicitPackage) 10use strict; 11use warnings; 12use utf8; 13 14use Kernel::System::VariableCheck qw( IsArrayRefWithData IsHashRefWithData ); 15 16use vars (qw($Self)); 17 18$Kernel::OM->ObjectParamAdd( 19 'Kernel::System::UnitTest::Helper' => { 20 RestoreDatabase => 1, 21 }, 22); 23 24my $HelperObject = $Kernel::OM->Get('Kernel::System::UnitTest::Helper'); 25 26# disable check email address 27my $ConfigObject = $Kernel::OM->Get('Kernel::Config'); 28$ConfigObject->Set( 29 Key => 'CheckEmailAddresses', 30 Value => 0 31); 32 33my $DBObject = $Kernel::OM->Get('Kernel::System::DB'); 34 35# Get default from database. 36return if !$DBObject->Prepare( 37 SQL => " 38 SELECT COUNT(sd.id) 39 FROM sysconfig_default sd 40 WHERE 41 sd.xml_filename IN ( 42 'Calendar.xml' ,'CloudServices.xml', 'Daemon.xml', 'Framework.xml', 'GenericInterface.xml', 43 'ProcessManagement.xml', 'Ticket.xml' 44 ) 45 AND is_invisible != '1' 46 ", 47); 48 49my $OTRSSettings; 50while ( my @Data = $DBObject->FetchrowArray() ) { 51 $OTRSSettings = $Data[0]; 52} 53 54my $SysConfigObject = $Kernel::OM->Get('Kernel::System::SysConfig'); 55 56my @Tests = ( 57 { 58 Name => 'Correct Search', 59 Params => { 60 Search => 'LogModule::SysLog', 61 }, 62 ExpectedResult => [ 63 'LogModule::SysLog::Charset', 64 'LogModule::SysLog::Facility', 65 ], 66 Success => 1, 67 }, 68 { 69 Name => 'Multiple Term Search', 70 Params => { 71 Search => 'look-up DNS', 72 }, 73 ExpectedResult => [ 74 'CheckMXRecord::Nameserver', 75 ], 76 Success => 1, 77 }, 78 { 79 Name => 'Multiple Term Search 2', 80 Params => { 81 Search => 'look-up DNS', 82 }, 83 ExpectedResult => [ 84 'CheckMXRecord::Nameserver', 85 ], 86 Success => 1, 87 }, 88 { 89 Name => 'Empty Result', 90 Params => { 91 Search => 'WatcherType', 92 }, 93 ExpectedResult => [], 94 Success => 1, 95 }, 96 { 97 Name => 'Size Result', 98 Params => { 99 Category => 'OTRS', 100 }, 101 ExpectedResult => $OTRSSettings, 102 Success => 1, 103 }, 104 { 105 Name => 'Invisible Search', 106 Params => { 107 Search => 'SystemConfiguration::MaximumDeployments', 108 IncludeInvisible => 1, 109 }, 110 ExpectedResult => [ 111 'SystemConfiguration::MaximumDeployments', 112 ], 113 Success => 1, 114 }, 115 { 116 Name => '!Invisible Search', 117 Params => { 118 Search => 'SystemConfiguration::MaximumDeployments', 119 IncludeInvisible => 0, 120 }, 121 ExpectedResult => [], 122 Success => 1, 123 }, 124); 125 126TEST: 127for my $Test (@Tests) { 128 129 my @Result = $SysConfigObject->ConfigurationSearch( %{ $Test->{Params} } ); 130 131 if ( $Test->{Name} =~ m{Size} ) { 132 $Self->Is( 133 scalar @Result, 134 $Test->{ExpectedResult}, 135 "$Test->{Name} correct", 136 ); 137 next TEST; 138 } 139 140 my %LookupResult = map { $_ => 1 } @Result; 141 142 for my $ExpectedItem ( @{ $Test->{ExpectedResult} } ) { 143 144 $Self->True( 145 $LookupResult{$ExpectedItem}, 146 "$Test->{Name} correct - Found '$ExpectedItem'", 147 ); 148 } 149} 150 1511; 152