aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/sabre/dav/tests/Sabre/DAV/FSExt/FileTest.php
blob: 3708594e0346202021e15c4e955e0d2b8a276410 (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php

namespace Sabre\DAV\FSExt;

use Sabre\DAV;

require_once 'Sabre/TestUtil.php';

class FileTest extends \PHPUnit_Framework_TestCase {

    function setUp() {

        file_put_contents(SABRE_TEMPDIR . '/file.txt', 'Contents');

    }

    function tearDown() {

        \Sabre\TestUtil::clearTempDir();

    }

    function testPut() {

        $filename = SABRE_TEMPDIR . '/file.txt';
        $file = new File($filename);
        $result = $file->put('New contents');

        $this->assertEquals('New contents',file_get_contents(SABRE_TEMPDIR . '/file.txt'));
        $this->assertEquals(
            '"' .
            sha1(
                fileinode($filename) .
                filesize($filename ) .
                filemtime($filename)
            ) . '"',
            $result
        );

    }

    function testRange() {

        $file = new File(SABRE_TEMPDIR . '/file.txt');
        $file->put('0000000');
        $file->patch('111', 2, 3);

        $this->assertEquals('0001110',file_get_contents(SABRE_TEMPDIR . '/file.txt'));

    }

    function testRangeStream() {

        $stream = fopen('php://memory','r+');
        fwrite($stream, "222");
        rewind($stream);

        $file = new File(SABRE_TEMPDIR . '/file.txt');
        $file->put('0000000');
        $file->patch($stream, 2, 3);

        $this->assertEquals('0002220',file_get_contents(SABRE_TEMPDIR . '/file.txt'));

    }


    function testGet() {

        $file = new File(SABRE_TEMPDIR . '/file.txt');
        $this->assertEquals('Contents',stream_get_contents($file->get()));

    }

    function testDelete() {

        $file = new File(SABRE_TEMPDIR . '/file.txt');
        $file->delete();

        $this->assertFalse(file_exists(SABRE_TEMPDIR . '/file.txt'));

    }

    function testGetETag() {

        $filename = SABRE_TEMPDIR . '/file.txt';
        $file = new File($filename);
        $this->assertEquals(
            '"' .
            sha1(
                fileinode($filename) .
                filesize($filename ) .
                filemtime($filename)
            ) . '"',
            $file->getETag()
        );
    }

    function testGetContentType() {

        $file = new File(SABRE_TEMPDIR . '/file.txt');
        $this->assertNull($file->getContentType());

    }

    function testGetSize() {

        $file = new File(SABRE_TEMPDIR . '/file.txt');
        $this->assertEquals(8,$file->getSize());

    }

}