MDL-50888 antivirus_clamav: Unit tests refactoring.

Due to configurable nature of scanning method selection, unit test needs to
be updated to always point to commadline method. There is no need to write
separate tests for socket scanning method, as the scanning method needs to
be mocked anyway (i.e. will be identical to commandline scanning from test
perspective).
This commit is contained in:
Ruslan Kabalin 2016-03-04 14:32:09 +00:00
parent 7be0d4292a
commit 83a43b88fe

View File

@ -56,8 +56,11 @@ class antivirus_clamav_scanner_testcase extends advanced_testcase {
public function test_scan_file_no_virus() {
$antivirus = $this->getMockBuilder('\antivirus_clamav\scanner')
->setMethods(array('scan_file_execute_commandline', 'message_admins'))
->setMethods(array('scan_file_execute_commandline', 'message_admins', 'get_config'))
->getMock();
// Initiate mock scanning with configuration setting to use commandline.
$configmap = array(array('runningmethod', 'commandline'));
$antivirus->method('get_config')->will($this->returnValueMap($configmap));
// Configure scan_file_execute_commandline method stub to behave
// as if no virus has been found.
@ -79,8 +82,11 @@ class antivirus_clamav_scanner_testcase extends advanced_testcase {
public function test_scan_file_virus() {
$antivirus = $this->getMockBuilder('\antivirus_clamav\scanner')
->setMethods(array('scan_file_execute_commandline', 'message_admins'))
->setMethods(array('scan_file_execute_commandline', 'message_admins', 'get_config'))
->getMock();
// Initiate mock scanning with configuration setting to use commandline.
$configmap = array(array('runningmethod', 'commandline'));
$antivirus->method('get_config')->will($this->returnValueMap($configmap));
// Configure scan_file_execute_commandline method stub to behave
// as if virus has been found.
@ -121,8 +127,9 @@ class antivirus_clamav_scanner_testcase extends advanced_testcase {
// Set expectation that message_admins is called.
$antivirus->expects($this->atLeastOnce())->method('message_admins')->with($this->equalTo('someerror'));
// Initiate mock scanning with configuration setting to do nothing on scanning error.
$configmap = array(array('clamfailureonupload', 'donothing'));
// Initiate mock scanning with configuration setting to do nothing on
// scanning error and using commandline.
$configmap = array(array('clamfailureonupload', 'donothing'), array('runningmethod', 'commandline'));
$antivirus->method('get_config')->will($this->returnValueMap($configmap));
// Run mock scanning with deleting infected file.
@ -148,8 +155,9 @@ class antivirus_clamav_scanner_testcase extends advanced_testcase {
// Set expectation that message_admins is called.
$antivirus->expects($this->atLeastOnce())->method('message_admins')->with($this->equalTo('someerror'));
// Initiate mock scanning with configuration setting to act like virus on scanning error.
$configmap = array(array('clamfailureonupload', 'actlikevirus'));
// Initiate mock scanning with configuration setting to act like virus on
// scanning error and using commandline.
$configmap = array(array('clamfailureonupload', 'actlikevirus'), array('runningmethod', 'commandline'));
$antivirus->method('get_config')->will($this->returnValueMap($configmap));
// Run mock scanning without deleting infected file.