xref: /plugin/davcal/vendor/sabre/dav/tests/Sabre/DAV/Issue33Test.php (revision a1a3b6794e0e143a4a8b51d3185ce2d339be61ab)
1*a1a3b679SAndreas Boehler<?php
2*a1a3b679SAndreas Boehler
3*a1a3b679SAndreas Boehlernamespace Sabre\DAV;
4*a1a3b679SAndreas Boehler
5*a1a3b679SAndreas Boehleruse Sabre\HTTP;
6*a1a3b679SAndreas Boehler
7*a1a3b679SAndreas Boehlerrequire_once 'Sabre/TestUtil.php';
8*a1a3b679SAndreas Boehler
9*a1a3b679SAndreas Boehlerclass Issue33Test extends \PHPUnit_Framework_TestCase {
10*a1a3b679SAndreas Boehler
11*a1a3b679SAndreas Boehler    function setUp() {
12*a1a3b679SAndreas Boehler
13*a1a3b679SAndreas Boehler        \Sabre\TestUtil::clearTempDir();
14*a1a3b679SAndreas Boehler
15*a1a3b679SAndreas Boehler    }
16*a1a3b679SAndreas Boehler
17*a1a3b679SAndreas Boehler    function testCopyMoveInfo() {
18*a1a3b679SAndreas Boehler
19*a1a3b679SAndreas Boehler        $bar = new SimpleCollection('bar');
20*a1a3b679SAndreas Boehler        $root = new SimpleCollection('webdav',array($bar));
21*a1a3b679SAndreas Boehler
22*a1a3b679SAndreas Boehler        $server = new Server($root);
23*a1a3b679SAndreas Boehler        $server->setBaseUri('/webdav/');
24*a1a3b679SAndreas Boehler
25*a1a3b679SAndreas Boehler        $serverVars = array(
26*a1a3b679SAndreas Boehler            'REQUEST_URI' => '/webdav/bar',
27*a1a3b679SAndreas Boehler            'HTTP_DESTINATION' => 'http://dev2.tribalos.com/webdav/%C3%A0fo%C3%B3',
28*a1a3b679SAndreas Boehler            'HTTP_OVERWRITE' => 'F',
29*a1a3b679SAndreas Boehler        );
30*a1a3b679SAndreas Boehler
31*a1a3b679SAndreas Boehler        $request = HTTP\Sapi::createFromServerArray($serverVars);
32*a1a3b679SAndreas Boehler
33*a1a3b679SAndreas Boehler        $server->httpRequest = $request;
34*a1a3b679SAndreas Boehler
35*a1a3b679SAndreas Boehler        $info = $server->getCopyAndMoveInfo($request);
36*a1a3b679SAndreas Boehler
37*a1a3b679SAndreas Boehler        $this->assertEquals('%C3%A0fo%C3%B3', urlencode($info['destination']));
38*a1a3b679SAndreas Boehler        $this->assertFalse($info['destinationExists']);
39*a1a3b679SAndreas Boehler        $this->assertFalse($info['destinationNode']);
40*a1a3b679SAndreas Boehler
41*a1a3b679SAndreas Boehler    }
42*a1a3b679SAndreas Boehler
43*a1a3b679SAndreas Boehler    function testTreeMove() {
44*a1a3b679SAndreas Boehler
45*a1a3b679SAndreas Boehler        mkdir(SABRE_TEMPDIR . '/issue33');
46*a1a3b679SAndreas Boehler        $dir = new FS\Directory(SABRE_TEMPDIR . '/issue33');
47*a1a3b679SAndreas Boehler
48*a1a3b679SAndreas Boehler        $dir->createDirectory('bar');
49*a1a3b679SAndreas Boehler
50*a1a3b679SAndreas Boehler        $tree = new Tree($dir);
51*a1a3b679SAndreas Boehler        $tree->move('bar',urldecode('%C3%A0fo%C3%B3'));
52*a1a3b679SAndreas Boehler
53*a1a3b679SAndreas Boehler        $node = $tree->getNodeForPath(urldecode('%C3%A0fo%C3%B3'));
54*a1a3b679SAndreas Boehler        $this->assertEquals(urldecode('%C3%A0fo%C3%B3'),$node->getName());
55*a1a3b679SAndreas Boehler
56*a1a3b679SAndreas Boehler    }
57*a1a3b679SAndreas Boehler
58*a1a3b679SAndreas Boehler    function testDirName() {
59*a1a3b679SAndreas Boehler
60*a1a3b679SAndreas Boehler        $dirname1 = 'bar';
61*a1a3b679SAndreas Boehler        $dirname2 = urlencode('%C3%A0fo%C3%B3');;
62*a1a3b679SAndreas Boehler
63*a1a3b679SAndreas Boehler        $this->assertTrue(dirname($dirname1)==dirname($dirname2));
64*a1a3b679SAndreas Boehler
65*a1a3b679SAndreas Boehler    }
66*a1a3b679SAndreas Boehler
67*a1a3b679SAndreas Boehler    /**
68*a1a3b679SAndreas Boehler     * @depends testTreeMove
69*a1a3b679SAndreas Boehler     * @depends testCopyMoveInfo
70*a1a3b679SAndreas Boehler     */
71*a1a3b679SAndreas Boehler    function testEverything() {
72*a1a3b679SAndreas Boehler
73*a1a3b679SAndreas Boehler        // Request object
74*a1a3b679SAndreas Boehler        $serverVars = array(
75*a1a3b679SAndreas Boehler            'REQUEST_METHOD' => 'MOVE',
76*a1a3b679SAndreas Boehler            'REQUEST_URI' => '/webdav/bar',
77*a1a3b679SAndreas Boehler            'HTTP_DESTINATION' => 'http://dev2.tribalos.com/webdav/%C3%A0fo%C3%B3',
78*a1a3b679SAndreas Boehler            'HTTP_OVERWRITE' => 'F',
79*a1a3b679SAndreas Boehler        );
80*a1a3b679SAndreas Boehler
81*a1a3b679SAndreas Boehler        $request = HTTP\Sapi::createFromServerArray($serverVars);
82*a1a3b679SAndreas Boehler        $request->setBody('');
83*a1a3b679SAndreas Boehler
84*a1a3b679SAndreas Boehler        $response = new HTTP\ResponseMock();
85*a1a3b679SAndreas Boehler
86*a1a3b679SAndreas Boehler        // Server setup
87*a1a3b679SAndreas Boehler        mkdir(SABRE_TEMPDIR . '/issue33');
88*a1a3b679SAndreas Boehler        $dir = new FS\Directory(SABRE_TEMPDIR . '/issue33');
89*a1a3b679SAndreas Boehler
90*a1a3b679SAndreas Boehler        $dir->createDirectory('bar');
91*a1a3b679SAndreas Boehler
92*a1a3b679SAndreas Boehler        $tree = new Tree($dir);
93*a1a3b679SAndreas Boehler
94*a1a3b679SAndreas Boehler        $server = new Server($tree);
95*a1a3b679SAndreas Boehler        $server->setBaseUri('/webdav/');
96*a1a3b679SAndreas Boehler
97*a1a3b679SAndreas Boehler        $server->httpRequest = $request;
98*a1a3b679SAndreas Boehler        $server->httpResponse = $response;
99*a1a3b679SAndreas Boehler        $server->sapi = new HTTP\SapiMock();
100*a1a3b679SAndreas Boehler        $server->exec();
101*a1a3b679SAndreas Boehler
102*a1a3b679SAndreas Boehler        $this->assertTrue(file_exists(SABRE_TEMPDIR  . '/issue33/' . urldecode('%C3%A0fo%C3%B3')));
103*a1a3b679SAndreas Boehler
104*a1a3b679SAndreas Boehler    }
105*a1a3b679SAndreas Boehler
106*a1a3b679SAndreas Boehler}
107