summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2013-02-16 13:27:57 +0100
committerAndreas Gohr <andi@splitbrain.org>2013-02-16 13:27:57 +0100
commit4def61cfe42f331ab696463fa2fa4cfc452df23b (patch)
tree2a6a4714507c660a1cdc9a91f31603b5e4815240
parent8b48b31f60c1acd63fbe9f35207377209faac012 (diff)
downloadrpg-4def61cfe42f331ab696463fa2fa4cfc452df23b.tar.gz
rpg-4def61cfe42f331ab696463fa2fa4cfc452df23b.tar.bz2
test for media downloading (related to FS#2675
-rw-r--r--_test/tests/inc/media_get_from_url.test.php80
1 files changed, 80 insertions, 0 deletions
diff --git a/_test/tests/inc/media_get_from_url.test.php b/_test/tests/inc/media_get_from_url.test.php
new file mode 100644
index 000000000..3903b8a05
--- /dev/null
+++ b/_test/tests/inc/media_get_from_url.test.php
@@ -0,0 +1,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);
+ }
+} \ No newline at end of file