ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
VirusScannerPreProcessorTest.php
Go to the documentation of this file.
1 <?php
2 
4 
5 require_once('./libs/composer/vendor/autoload.php');
6 
10 use Mockery;
12 
23 class VirusScannerPreProcessorTest extends TestCase
24 {
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 }
const REJECTED
Upload got rejected by a processor.
$result
$stream
PHP stream implementation.
static ofString($string)
Creates a new stream with an initial value.
Definition: Streams.php:30