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
|
<?php
class media_get_from_url_test extends DokuWikiTest {
/**
* @group internet
*/
public function test_cache(){
global $conf;
$conf['fetchsize'] = 500*1024; //500kb
$local = media_get_from_URL('http://www.google.com/images/srpr/logo3w.png','png',-1);
$this->assertTrue($local !== false);
$this->assertFileExists($local);
// remember time stamp
$time = filemtime($local);
clearstatcache(false, $local);
sleep(1);
// fetch again and make sure we got a cache file
$local = media_get_from_URL('http://www.google.com/images/srpr/logo3w.png','png',-1);
clearstatcache(false, $local);
$this->assertTrue($local !== false);
$this->assertFileExists($local);
$this->assertEquals($time, filemtime($local));
unlink($local);
}
/**
* @group internet
*/
public function test_nocache(){
global $conf;
$conf['fetchsize'] = 500*1024; //500kb
$local = media_get_from_URL('http://www.google.com/images/srpr/logo3w.png','png',0);
$this->assertFalse($local);
}
/**
* @group internet
* @group slow
*/
public function test_recache(){
global $conf;
$conf['fetchsize'] = 500*1024; //500kb
$local = media_get_from_URL('http://www.google.com/images/srpr/logo3w.png','png',5);
$this->assertTrue($local !== false);
$this->assertFileExists($local);
// remember time stamp
$time = filemtime($local);
clearstatcache(false, $local);
sleep(1);
// fetch again and make sure we got a cache file
$local = media_get_from_URL('http://www.google.com/images/srpr/logo3w.png','png',5);
clearstatcache(false, $local);
$this->assertTrue($local !== false);
$this->assertFileExists($local);
$this->assertEquals($time, filemtime($local));
clearstatcache(false, $local);
sleep(6);
// fetch again and make sure we got a new file
$local = media_get_from_URL('http://www.google.com/images/srpr/logo3w.png','png',5);
clearstatcache(false, $local);
$this->assertTrue($local !== false);
$this->assertFileExists($local);
$this->assertNotEquals($time, filemtime($local));
unlink($local);
}
}
|