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