ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
FileTest.php
Go to the documentation of this file.
1<?php
2
3namespace Sabre\DAV\FSExt;
4
5require_once 'Sabre/TestUtil.php';
6
8
9 function setUp() {
10
11 file_put_contents(SABRE_TEMPDIR . '/file.txt', 'Contents');
12
13 }
14
15 function tearDown() {
16
18
19 }
20
21 function testPut() {
22
23 $filename = SABRE_TEMPDIR . '/file.txt';
24 $file = new File($filename);
25 $result = $file->put('New contents');
26
27 $this->assertEquals('New contents', file_get_contents(SABRE_TEMPDIR . '/file.txt'));
28 $this->assertEquals(
29 '"' .
30 sha1(
31 fileinode($filename) .
32 filesize($filename) .
33 filemtime($filename)
34 ) . '"',
36 );
37
38 }
39
40 function testRange() {
41
42 $file = new File(SABRE_TEMPDIR . '/file.txt');
43 $file->put('0000000');
44 $file->patch('111', 2, 3);
45
46 $this->assertEquals('0001110', file_get_contents(SABRE_TEMPDIR . '/file.txt'));
47
48 }
49
50 function testRangeStream() {
51
52 $stream = fopen('php://memory', 'r+');
53 fwrite($stream, "222");
54 rewind($stream);
55
56 $file = new File(SABRE_TEMPDIR . '/file.txt');
57 $file->put('0000000');
58 $file->patch($stream, 2, 3);
59
60 $this->assertEquals('0002220', file_get_contents(SABRE_TEMPDIR . '/file.txt'));
61
62 }
63
64
65 function testGet() {
66
67 $file = new File(SABRE_TEMPDIR . '/file.txt');
68 $this->assertEquals('Contents', stream_get_contents($file->get()));
69
70 }
71
72 function testDelete() {
73
74 $file = new File(SABRE_TEMPDIR . '/file.txt');
75 $file->delete();
76
77 $this->assertFalse(file_exists(SABRE_TEMPDIR . '/file.txt'));
78
79 }
80
81 function testGetETag() {
82
83 $filename = SABRE_TEMPDIR . '/file.txt';
84 $file = new File($filename);
85 $this->assertEquals(
86 '"' .
87 sha1(
88 fileinode($filename) .
89 filesize($filename) .
90 filemtime($filename)
91 ) . '"',
92 $file->getETag()
93 );
94 }
95
96 function testGetContentType() {
97
98 $file = new File(SABRE_TEMPDIR . '/file.txt');
99 $this->assertNull($file->getContentType());
100
101 }
102
103 function testGetSize() {
104
105 $file = new File(SABRE_TEMPDIR . '/file.txt');
106 $this->assertEquals(8, $file->getSize());
107
108 }
109
110}
$result
$filename
Definition: buildRTE.php:89
An exception for terminatinating execution or to throw for unit testing.
File class.
Definition: File.php:15
static clearTempDir()
This function deletes all the contents of the temporary directory.
Definition: TestUtil.php:12
$stream
PHP stream implementation.