1<?php
2
3class media_get_from_url_test extends DokuWikiTest {
4
5    /**
6     * @group internet
7     */
8    public function test_cache(){
9        global $conf;
10        $conf['fetchsize'] = 500*1024; //500kb
11
12
13        $local = media_get_from_URL('http://www.google.com/images/srpr/logo3w.png','png',-1);
14        $this->assertTrue($local !== false);
15        $this->assertFileExists($local);
16
17        // remember time stamp
18        $time = filemtime($local);
19        clearstatcache(false, $local);
20        $this->waitForTick(true);
21
22        // fetch again and make sure we got a cache file
23        $local = media_get_from_URL('http://www.google.com/images/srpr/logo3w.png','png',-1);
24        clearstatcache(false, $local);
25        $this->assertTrue($local !== false);
26        $this->assertFileExists($local);
27        $this->assertEquals($time, filemtime($local));
28
29        unlink($local);
30    }
31
32    /**
33     * @group internet
34     */
35    public function test_nocache(){
36        global $conf;
37        $conf['fetchsize'] = 500*1024; //500kb
38
39        $local = media_get_from_URL('http://www.google.com/images/srpr/logo3w.png','png',0);
40        $this->assertFalse($local);
41    }
42
43    /**
44     * @group internet
45     * @group slow
46     */
47    public function test_recache(){
48        global $conf;
49        $conf['fetchsize'] = 500*1024; //500kb
50
51
52        $local = media_get_from_URL('http://www.google.com/images/srpr/logo3w.png','png',5);
53        $this->assertTrue($local !== false);
54        $this->assertFileExists($local);
55
56        // remember time stamp
57        $time = filemtime($local);
58        clearstatcache(false, $local);
59        sleep(1);
60
61        // fetch again and make sure we got a cache file
62        $local = media_get_from_URL('http://www.google.com/images/srpr/logo3w.png','png',5);
63        clearstatcache(false, $local);
64        $this->assertTrue($local !== false);
65        $this->assertFileExists($local);
66        $this->assertEquals($time, filemtime($local));
67
68        clearstatcache(false, $local);
69        sleep(6);
70
71        // fetch again and make sure we got a new file
72        $local = media_get_from_URL('http://www.google.com/images/srpr/logo3w.png','png',5);
73        clearstatcache(false, $local);
74        $this->assertTrue($local !== false);
75        $this->assertFileExists($local);
76        $this->assertNotEquals($time, filemtime($local));
77
78        unlink($local);
79    }
80}
81