14def61cfSAndreas Gohr<?php 24def61cfSAndreas Gohr 34def61cfSAndreas Gohrclass media_get_from_url_test extends DokuWikiTest { 44def61cfSAndreas Gohr 54def61cfSAndreas Gohr /** 64def61cfSAndreas Gohr * @group internet 74def61cfSAndreas Gohr */ 84def61cfSAndreas Gohr public function test_cache(){ 94def61cfSAndreas Gohr global $conf; 104def61cfSAndreas Gohr $conf['fetchsize'] = 500*1024; //500kb 114def61cfSAndreas Gohr 124def61cfSAndreas Gohr 134def61cfSAndreas Gohr $local = media_get_from_URL('http://www.google.com/images/srpr/logo3w.png','png',-1); 144def61cfSAndreas Gohr $this->assertTrue($local !== false); 154def61cfSAndreas Gohr $this->assertFileExists($local); 164def61cfSAndreas Gohr 174def61cfSAndreas Gohr // remember time stamp 184def61cfSAndreas Gohr $time = filemtime($local); 194def61cfSAndreas Gohr clearstatcache(false, $local); 20*aaf4f55eSAndreas Gohr $this->waitForTick(true); 214def61cfSAndreas Gohr 224def61cfSAndreas Gohr // fetch again and make sure we got a cache file 234def61cfSAndreas Gohr $local = media_get_from_URL('http://www.google.com/images/srpr/logo3w.png','png',-1); 244def61cfSAndreas Gohr clearstatcache(false, $local); 254def61cfSAndreas Gohr $this->assertTrue($local !== false); 264def61cfSAndreas Gohr $this->assertFileExists($local); 274def61cfSAndreas Gohr $this->assertEquals($time, filemtime($local)); 284def61cfSAndreas Gohr 294def61cfSAndreas Gohr unlink($local); 304def61cfSAndreas Gohr } 314def61cfSAndreas Gohr 324def61cfSAndreas Gohr /** 334def61cfSAndreas Gohr * @group internet 344def61cfSAndreas Gohr */ 354def61cfSAndreas Gohr public function test_nocache(){ 364def61cfSAndreas Gohr global $conf; 374def61cfSAndreas Gohr $conf['fetchsize'] = 500*1024; //500kb 384def61cfSAndreas Gohr 394def61cfSAndreas Gohr $local = media_get_from_URL('http://www.google.com/images/srpr/logo3w.png','png',0); 404def61cfSAndreas Gohr $this->assertFalse($local); 414def61cfSAndreas Gohr } 424def61cfSAndreas Gohr 434def61cfSAndreas Gohr /** 444def61cfSAndreas Gohr * @group internet 454def61cfSAndreas Gohr * @group slow 464def61cfSAndreas Gohr */ 474def61cfSAndreas Gohr public function test_recache(){ 484def61cfSAndreas Gohr global $conf; 494def61cfSAndreas Gohr $conf['fetchsize'] = 500*1024; //500kb 504def61cfSAndreas Gohr 514def61cfSAndreas Gohr 524def61cfSAndreas Gohr $local = media_get_from_URL('http://www.google.com/images/srpr/logo3w.png','png',5); 534def61cfSAndreas Gohr $this->assertTrue($local !== false); 544def61cfSAndreas Gohr $this->assertFileExists($local); 554def61cfSAndreas Gohr 564def61cfSAndreas Gohr // remember time stamp 574def61cfSAndreas Gohr $time = filemtime($local); 584def61cfSAndreas Gohr clearstatcache(false, $local); 594def61cfSAndreas Gohr sleep(1); 604def61cfSAndreas Gohr 614def61cfSAndreas Gohr // fetch again and make sure we got a cache file 624def61cfSAndreas Gohr $local = media_get_from_URL('http://www.google.com/images/srpr/logo3w.png','png',5); 634def61cfSAndreas Gohr clearstatcache(false, $local); 644def61cfSAndreas Gohr $this->assertTrue($local !== false); 654def61cfSAndreas Gohr $this->assertFileExists($local); 664def61cfSAndreas Gohr $this->assertEquals($time, filemtime($local)); 674def61cfSAndreas Gohr 684def61cfSAndreas Gohr clearstatcache(false, $local); 694def61cfSAndreas Gohr sleep(6); 704def61cfSAndreas Gohr 714def61cfSAndreas Gohr // fetch again and make sure we got a new file 724def61cfSAndreas Gohr $local = media_get_from_URL('http://www.google.com/images/srpr/logo3w.png','png',5); 734def61cfSAndreas Gohr clearstatcache(false, $local); 744def61cfSAndreas Gohr $this->assertTrue($local !== false); 754def61cfSAndreas Gohr $this->assertFileExists($local); 764def61cfSAndreas Gohr $this->assertNotEquals($time, filemtime($local)); 774def61cfSAndreas Gohr 784def61cfSAndreas Gohr unlink($local); 794def61cfSAndreas Gohr } 804def61cfSAndreas Gohr} 81