ILIAS  release_7 Revision v7.30-3-g800a261c036
VirusScannerPreProcessorTest.php
Go to the documentation of this file.
1<?php
2
4
5require_once('./libs/composer/vendor/autoload.php');
6
10use Mockery;
11use PHPUnit\Framework\TestCase;
12
23class VirusScannerPreProcessorTest extends TestCase
24{
25 use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
26
27
28 public function testVirusDetected()
29 {
30 $stream = Streams::ofString('Awesome stuff');
31 $mock = Mockery::mock(\ilVirusScanner::class);
32
33 $mock->shouldReceive("scanFile")->once()->withArgs(array( $stream->getMetadata('uri') ))->andReturn("Virus found!!!");
34
35 $subject = new VirusScannerPreProcessor($mock);
36 $result = $subject->process($stream, new Metadata("MyVirus.exe", $stream->getSize(), 'application/vnd.microsoft.portable-executable'));
37 $this->assertSame(ProcessingStatus::REJECTED, $result->getCode());
38 $this->assertSame('Virus detected.', $result->getMessage());
39 }
40
41
42 public function testNoVirusDetected()
43 {
44 $stream = Streams::ofString('Awesome stuff');
45 $mock = Mockery::mock(\ilVirusScanner::class);
46
47 $mock->shouldReceive("scanFile")->once()->withArgs(array( $stream->getMetadata('uri') ))->andReturn("");
48
49 $subject = new VirusScannerPreProcessor($mock);
50 $result = $subject->process($stream, new Metadata("MyVirus.exe", $stream->getSize(), 'application/vnd.microsoft.portable-executable'));
51 $this->assertSame(ProcessingStatus::OK, $result->getCode());
52 }
53}
$result
An exception for terminatinating execution or to throw for unit testing.
const REJECTED
Upload got rejected by a processor.
Class Streams Stream factory which enables the user to create streams without the knowledge of the co...
Definition: Streams.php:17
static ofString($string)
Creates a new stream with an initial value.
Definition: Streams.php:25
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...