aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/SpecificationTest.php
blob: 31be2a1b1c6d89c22852679e2b75d1af0ddfc804 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php

namespace Sabre\DAV\PartialUpdate;

use Sabre\DAV\FSExt\File;
use Sabre\DAV\Server;
use Sabre\HTTP;

/**
 * This test is an end-to-end sabredav test that goes through all
 * the cases in the specification.
 *
 * See: http://sabre.io/dav/http-patch/
 */
class SpecificationTest extends \PHPUnit_Framework_TestCase {

    protected $server;

    public function setUp() {

        $tree = array(
            new File(SABRE_TEMPDIR . '/foobar.txt')
        );
        $server = new Server($tree);
        $server->debugExceptions = true;
        $server->addPlugin(new Plugin());

        $tree[0]->put('1234567890');

        $this->server = $server;

    }

    public function tearDown() {

        \Sabre\TestUtil::clearTempDir();

    }

    /**
     * @dataProvider data
     */
    public function testUpdateRange($headerValue, $httpStatus, $endResult, $contentLength = 4) {

        $headers = [
            'Content-Type' => 'application/x-sabredav-partialupdate',
            'X-Update-Range' => $headerValue,
        ];

        if ($contentLength) {
            $headers['Content-Length'] = (string)$contentLength;
        }

        $request = new HTTP\Request('PATCH', '/foobar.txt', $headers, '----');

        $request->setBody('----');
        $this->server->httpRequest = $request;
        $this->server->httpResponse = new HTTP\ResponseMock();
        $this->server->sapi = new HTTP\SapiMock();
        $this->server->exec();

        $this->assertEquals($httpStatus, $this->server->httpResponse->status, 'Incorrect http status received: ' . $this->server->httpResponse->body);
        if (!is_null($endResult)) {
            $this->assertEquals($endResult, file_get_contents(SABRE_TEMPDIR . '/foobar.txt'));
        }

    } 

    public function data() {

        return array(
            // Problems
            array('foo',       400, null),
            array('bytes=0-3', 411, null, 0),
            array('bytes=4-1', 416, null),

            array('bytes=0-3', 204, '----567890'),
            array('bytes=1-4', 204, '1----67890'),
            array('bytes=0-',  204, '----567890'),
            array('bytes=-4',  204, '123456----'),
            array('bytes=-2',  204, '12345678----'),
            array('bytes=2-',  204, '12----7890'),
            array('append',    204, '1234567890----'),

        );

    }

}