diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php index 042a7f6d..e23f7961 100644 --- a/lib/Controller/SettingsController.php +++ b/lib/Controller/SettingsController.php @@ -14,30 +14,18 @@ namespace OCA\Files_Antivirus\Controller; use OCA\Files_Antivirus\ScannerFactory; -use \OCP\AppFramework\Controller; -use \OCP\IRequest; -use \OCP\IL10N; -use \OCA\Files_Antivirus\AppConfig; +use OCP\AppFramework\Controller; +use OCP\IRequest; +use OCP\IL10N; +use OCA\Files_Antivirus\AppConfig; -use \OCP\AppFramework\Http\TemplateResponse; -use \OCP\AppFramework\Http\JSONResponse; +use OCP\AppFramework\Http\TemplateResponse; +use OCP\AppFramework\Http\JSONResponse; class SettingsController extends Controller { - - /** - * @var AppConfig - */ - private $settings; - - /** - * @var ScannerFactory - */ - private $scannerFactory; - - /** - * @var IL10N - */ - private $l10n; + private AppConfig $settings; + private ScannerFactory $scannerFactory; + private IL10N $l10n; /** * SettingsController constructor. @@ -61,10 +49,8 @@ public function __construct( /** * Print config section - * - * @return TemplateResponse */ - public function index() { + public function index(): TemplateResponse { $data = $this->settings->getAllValues(); return new TemplateResponse('files_antivirus', 'settings', $data, 'blank'); } @@ -75,12 +61,13 @@ public function index() { * @param string $avMode - antivirus mode * @param string $avSocket - path to socket (Socket mode) * @param string $avHost - antivirus url - * @param int $avPort - port + * @param ?int $avPort - port * @param string $avInfectedAction - action performed on infected files * @param int $avStreamMaxLength - reopen socket after bytes * @param int $avMaxFileSize - file size limit * @param string $avRequestService * @param string $avResponseHeader + * @param string $avScanBackground * * @return JSONResponse */ @@ -93,8 +80,9 @@ public function save( $avStreamMaxLength, $avMaxFileSize, $avRequestService, - $avResponseHeader - ) { + $avResponseHeader, + $avScanBackground + ): JSONResponse { try { if ($avMode === 'daemon') { $this->settings->setAvPort($avPort); @@ -122,6 +110,7 @@ public function save( $this->settings->setAvStreamMaxLength($avStreamMaxLength); $this->settings->setAvMaxFileSize($avMaxFileSize); $this->settings->setAvMode($avMode); + $this->settings->setAvScanBackground($avScanBackground); $connectionStatus = (int)$this->scannerFactory->testConnection($this->settings); $response = [ diff --git a/templates/settings.php b/templates/settings.php index 657bf3d3..b34198b6 100644 --- a/templates/settings.php +++ b/templates/settings.php @@ -83,6 +83,10 @@ />
++ + +
diff --git a/tests/unit/Controller/SettingsControllerTest.php b/tests/unit/Controller/SettingsControllerTest.php index 97e08954..4712aca6 100644 --- a/tests/unit/Controller/SettingsControllerTest.php +++ b/tests/unit/Controller/SettingsControllerTest.php @@ -44,7 +44,7 @@ public function setUp(): void { $this->config = $this->getMockBuilder(AppConfig::class) ->disableOriginalConstructor() - ->setMethods(['setter', 'getAppValue']) + ->onlyMethods(['setter', 'getAppValue']) ->getMock(); $this->scannerFactory = $this->getMockBuilder(ScannerFactory::class) @@ -59,7 +59,8 @@ public function testSaveExecutable(): void { ['av_infected_action', ['delete']], ['av_stream_max_length', [100]], ['av_max_file_size', [800]], - ['av_mode', ['executable']] + ['av_mode', ['executable']], + ['av_scan_background', [true]], ); $settings = new SettingsController($this->request, $this->config, $this->scannerFactory, $this->l10n); @@ -72,7 +73,8 @@ public function testSaveExecutable(): void { 100, 800, '', - '' + '', + true ); } @@ -84,7 +86,8 @@ public function testSaveSocket(): void { ['av_infected_action', ['delete']], ['av_stream_max_length', [100]], ['av_max_file_size', [800]], - ['av_mode', ['socket']] + ['av_mode', ['socket']], + ['av_scan_background', [false]], ); $settings = new SettingsController($this->request, $this->config, $this->scannerFactory, $this->l10n); @@ -98,7 +101,8 @@ public function testSaveSocket(): void { 100, 800, '', - '' + '', + false ); } @@ -128,7 +132,8 @@ public function testSaveDaemon(): void { 100, 800, '', - '' + '', + true ); } }