xref: /plugin/davcal/vendor/sabre/dav/tests/Sabre/DAV/HttpMoveTest.php (revision a1a3b6794e0e143a4a8b51d3185ce2d339be61ab)
1*a1a3b679SAndreas Boehler<?php
2*a1a3b679SAndreas Boehler
3*a1a3b679SAndreas Boehlernamespace Sabre\DAV;
4*a1a3b679SAndreas Boehler
5*a1a3b679SAndreas Boehleruse Sabre\DAVServerTest;
6*a1a3b679SAndreas Boehleruse Sabre\HTTP;
7*a1a3b679SAndreas Boehler
8*a1a3b679SAndreas Boehler/**
9*a1a3b679SAndreas Boehler * Tests related to the MOVE request.
10*a1a3b679SAndreas Boehler *
11*a1a3b679SAndreas Boehler * @copyright Copyright (C) 2007-2015 fruux GmbH (https://fruux.com/).
12*a1a3b679SAndreas Boehler * @author Evert Pot (http://evertpot.com/)
13*a1a3b679SAndreas Boehler * @license http://sabre.io/license/ Modified BSD License
14*a1a3b679SAndreas Boehler */
15*a1a3b679SAndreas Boehlerclass HttpMoveTest extends DAVServerTest {
16*a1a3b679SAndreas Boehler
17*a1a3b679SAndreas Boehler    /**
18*a1a3b679SAndreas Boehler     * Sets up the DAV tree.
19*a1a3b679SAndreas Boehler     *
20*a1a3b679SAndreas Boehler     * @return void
21*a1a3b679SAndreas Boehler     */
22*a1a3b679SAndreas Boehler    function setUpTree() {
23*a1a3b679SAndreas Boehler
24*a1a3b679SAndreas Boehler        $this->tree = new Mock\Collection('root', [
25*a1a3b679SAndreas Boehler            'file1' => 'content1',
26*a1a3b679SAndreas Boehler            'file2' => 'content2',
27*a1a3b679SAndreas Boehler        ]);
28*a1a3b679SAndreas Boehler
29*a1a3b679SAndreas Boehler    }
30*a1a3b679SAndreas Boehler
31*a1a3b679SAndreas Boehler    function testMoveToSelf() {
32*a1a3b679SAndreas Boehler
33*a1a3b679SAndreas Boehler        $request = new HTTP\Request('MOVE', '/file1', [
34*a1a3b679SAndreas Boehler            'Destination' => '/file1'
35*a1a3b679SAndreas Boehler        ]);
36*a1a3b679SAndreas Boehler        $response = $this->request($request);
37*a1a3b679SAndreas Boehler        $this->assertEquals(403, $response->getStatus());
38*a1a3b679SAndreas Boehler        $this->assertEquals('content1', $this->tree->getChild('file1')->get());
39*a1a3b679SAndreas Boehler
40*a1a3b679SAndreas Boehler    }
41*a1a3b679SAndreas Boehler
42*a1a3b679SAndreas Boehler    function testMove() {
43*a1a3b679SAndreas Boehler
44*a1a3b679SAndreas Boehler        $request = new HTTP\Request('MOVE', '/file1', [
45*a1a3b679SAndreas Boehler            'Destination' => '/file3'
46*a1a3b679SAndreas Boehler        ]);
47*a1a3b679SAndreas Boehler        $response = $this->request($request);
48*a1a3b679SAndreas Boehler        $this->assertEquals(201, $response->getStatus(), print_r($response,true));
49*a1a3b679SAndreas Boehler        $this->assertEquals('content1', $this->tree->getChild('file3')->get());
50*a1a3b679SAndreas Boehler        $this->assertFalse($this->tree->childExists('file1'));
51*a1a3b679SAndreas Boehler
52*a1a3b679SAndreas Boehler    }
53*a1a3b679SAndreas Boehler
54*a1a3b679SAndreas Boehler    function testMoveToExisting() {
55*a1a3b679SAndreas Boehler
56*a1a3b679SAndreas Boehler        $request = new HTTP\Request('MOVE', '/file1', [
57*a1a3b679SAndreas Boehler            'Destination' => '/file2'
58*a1a3b679SAndreas Boehler        ]);
59*a1a3b679SAndreas Boehler        $response = $this->request($request);
60*a1a3b679SAndreas Boehler        $this->assertEquals(204, $response->getStatus(), print_r($response,true));
61*a1a3b679SAndreas Boehler        $this->assertEquals('content1', $this->tree->getChild('file2')->get());
62*a1a3b679SAndreas Boehler        $this->assertFalse($this->tree->childExists('file1'));
63*a1a3b679SAndreas Boehler
64*a1a3b679SAndreas Boehler    }
65*a1a3b679SAndreas Boehler
66*a1a3b679SAndreas Boehler    function testMoveToExistingOverwriteT() {
67*a1a3b679SAndreas Boehler
68*a1a3b679SAndreas Boehler        $request = new HTTP\Request('MOVE', '/file1', [
69*a1a3b679SAndreas Boehler            'Destination' => '/file2',
70*a1a3b679SAndreas Boehler            'Overwrite' => 'T',
71*a1a3b679SAndreas Boehler        ]);
72*a1a3b679SAndreas Boehler        $response = $this->request($request);
73*a1a3b679SAndreas Boehler        $this->assertEquals(204, $response->getStatus(), print_r($response,true));
74*a1a3b679SAndreas Boehler        $this->assertEquals('content1', $this->tree->getChild('file2')->get());
75*a1a3b679SAndreas Boehler        $this->assertFalse($this->tree->childExists('file1'));
76*a1a3b679SAndreas Boehler
77*a1a3b679SAndreas Boehler    }
78*a1a3b679SAndreas Boehler
79*a1a3b679SAndreas Boehler    function testMoveToExistingOverwriteF() {
80*a1a3b679SAndreas Boehler
81*a1a3b679SAndreas Boehler        $request = new HTTP\Request('MOVE', '/file1', [
82*a1a3b679SAndreas Boehler            'Destination' => '/file2',
83*a1a3b679SAndreas Boehler            'Overwrite' => 'F',
84*a1a3b679SAndreas Boehler        ]);
85*a1a3b679SAndreas Boehler        $response = $this->request($request);
86*a1a3b679SAndreas Boehler        $this->assertEquals(412, $response->getStatus(), print_r($response,true));
87*a1a3b679SAndreas Boehler        $this->assertEquals('content1', $this->tree->getChild('file1')->get());
88*a1a3b679SAndreas Boehler        $this->assertEquals('content2', $this->tree->getChild('file2')->get());
89*a1a3b679SAndreas Boehler        $this->assertTrue($this->tree->childExists('file1'));
90*a1a3b679SAndreas Boehler        $this->assertTrue($this->tree->childExists('file2'));
91*a1a3b679SAndreas Boehler
92*a1a3b679SAndreas Boehler    }
93*a1a3b679SAndreas Boehler
94*a1a3b679SAndreas Boehler    /**
95*a1a3b679SAndreas Boehler     * If we MOVE to an existing file, but a plugin prevents the original from
96*a1a3b679SAndreas Boehler     * being deleted, we need to make sure that the server does not delete
97*a1a3b679SAndreas Boehler     * the destination.
98*a1a3b679SAndreas Boehler     */
99*a1a3b679SAndreas Boehler    function testMoveToExistingBlockedDeleteSource() {
100*a1a3b679SAndreas Boehler
101*a1a3b679SAndreas Boehler        $this->server->on('beforeUnbind', function($path) {
102*a1a3b679SAndreas Boehler
103*a1a3b679SAndreas Boehler            if ($path==='file1') {
104*a1a3b679SAndreas Boehler                throw new \Sabre\DAV\Exception\Forbidden('uh oh');
105*a1a3b679SAndreas Boehler            }
106*a1a3b679SAndreas Boehler
107*a1a3b679SAndreas Boehler        });
108*a1a3b679SAndreas Boehler        $request = new HTTP\Request('MOVE', '/file1', [
109*a1a3b679SAndreas Boehler            'Destination' => '/file2'
110*a1a3b679SAndreas Boehler        ]);
111*a1a3b679SAndreas Boehler        $response = $this->request($request);
112*a1a3b679SAndreas Boehler        $this->assertEquals(403, $response->getStatus(), print_r($response,true));
113*a1a3b679SAndreas Boehler        $this->assertEquals('content1', $this->tree->getChild('file1')->get());
114*a1a3b679SAndreas Boehler        $this->assertEquals('content2', $this->tree->getChild('file2')->get());
115*a1a3b679SAndreas Boehler        $this->assertTrue($this->tree->childExists('file1'));
116*a1a3b679SAndreas Boehler        $this->assertTrue($this->tree->childExists('file2'));
117*a1a3b679SAndreas Boehler
118*a1a3b679SAndreas Boehler    }
119*a1a3b679SAndreas Boehler}
120