ILIAS  release_8 Revision v8.24
VirusScannerPreProcessorTest.php
Go to the documentation of this file.
1<?php
2
19require_once('./libs/composer/vendor/autoload.php');
20
24use PHPUnit\Framework\TestCase;
25
36class VirusScannerPreProcessorTest extends TestCase
37{
38 use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
39
40
41 public function testVirusDetected()
42 {
43 $stream = Streams::ofString('Awesome stuff');
44 $mock = $this->getMockBuilder(\ilVirusScanner::class)
45 ->disableOriginalConstructor()
46 ->getMock();
47 $mock->expects($this->once())->method('scanFile')->with($stream->getMetadata('uri'))->willReturn("Virus found!!!");
48
49 $subject = new ilVirusScannerPreProcessor($mock);
50 $result = $subject->process($stream, new Metadata("MyVirus.exe", $stream->getSize(), 'application/vnd.microsoft.portable-executable'));
51 $this->assertSame(ProcessingStatus::DENIED, $result->getCode());
52 $this->assertSame('Virus detected.', $result->getMessage());
53 }
54
55
56 public function testNoVirusDetected()
57 {
58 $stream = Streams::ofString('Awesome stuff');
59
60 $mock = $this->getMockBuilder(\ilVirusScanner::class)
61 ->disableOriginalConstructor()
62 ->getMock();
63 $mock->expects($this->once())->method('scanFile')->with($stream->getMetadata('uri'))->willReturn("");
64
65 $subject = new ilVirusScannerPreProcessor($mock);
66 $result = $subject->process($stream, new Metadata("MyVirus.exe", $stream->getSize(), 'application/vnd.microsoft.portable-executable'));
67 $this->assertSame(ProcessingStatus::OK, $result->getCode());
68 }
69}
Class VirusScannerPreProcessorTest.