|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ProtocolsTests\WebDav; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use CommonTestClass; |
|
7
|
|
|
use kalanis\RemoteRequest\Connection; |
|
8
|
|
|
use kalanis\RemoteRequest\Protocols\Http; |
|
9
|
|
|
use kalanis\RemoteRequest\Protocols\WebDAV; |
|
10
|
|
|
use kalanis\RemoteRequest\Translations; |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
class AnswerMock extends Connection\Processor |
|
14
|
|
|
{ |
|
15
|
|
|
public function getResponseSimple() |
|
16
|
|
|
{ |
|
17
|
|
|
return CommonTestClass::stringToResource('HTTP/0.1 901 KO' . Http::DELIMITER |
|
18
|
|
|
. 'Server: PhpUnit/6.3.0' . Http::DELIMITER |
|
19
|
|
|
. 'Content-Length: 29' . Http::DELIMITER |
|
20
|
|
|
. 'Content-Type: text/plain' . Http::DELIMITER |
|
21
|
|
|
. 'Connection: Closed' . Http::DELIMITER |
|
22
|
|
|
. Http::DELIMITER |
|
23
|
|
|
. '{"foou":"barr","abcd":"efgh"}'); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function getResponseFile() |
|
27
|
|
|
{ |
|
28
|
|
|
return CommonTestClass::stringToResource('HTTP/0.1 902 KO' . Http::DELIMITER |
|
29
|
|
|
. 'Server: PhpUnit/6.3.0' . Http::DELIMITER |
|
30
|
|
|
. 'Content-Length: 109' . Http::DELIMITER |
|
31
|
|
|
. 'Content-Type: text/plain' . Http::DELIMITER |
|
32
|
|
|
. 'Connection: Closed' . Http::DELIMITER |
|
33
|
|
|
. Http::DELIMITER |
|
34
|
|
|
. '{"foou":"barr","up":{"type":"file","filename":"unknown.txt","mimetype":"text\/plain","content64":"bW5idmN4"}}'); |
|
35
|
|
|
} |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
class AnswerTest extends CommonTestClass |
|
40
|
|
|
{ |
|
41
|
|
|
public function testSimple(): void |
|
42
|
|
|
{ |
|
43
|
|
|
$method = new AnswerMock(new Translations()); |
|
44
|
|
|
$lib = $this->prepareAnswerSimple($method->getResponseSimple()); |
|
45
|
|
|
$this->assertEquals(901, $lib->getCode()); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function testFiles(): void |
|
49
|
|
|
{ |
|
50
|
|
|
$method = new AnswerMock(new Translations()); |
|
51
|
|
|
$lib = $this->prepareAnswerSimple($method->getResponseFile()); |
|
52
|
|
|
$this->assertEquals(902, $lib->getCode()); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
protected function prepareAnswerSimple($content): WebDAV\Answer |
|
56
|
|
|
{ |
|
57
|
|
|
return (new WebDAV\Answer(new Translations()))->setResponse($content); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|