diff options
Diffstat (limited to 'site/app/tests/controllers/downloads_controller.test.php')
-rw-r--r-- | site/app/tests/controllers/downloads_controller.test.php | 45 |
1 files changed, 37 insertions, 8 deletions
diff --git a/site/app/tests/controllers/downloads_controller.test.php b/site/app/tests/controllers/downloads_controller.test.php index 94e889f..998eacc 100644 --- a/site/app/tests/controllers/downloads_controller.test.php +++ b/site/app/tests/controllers/downloads_controller.test.php @@ -49,29 +49,58 @@ class DownloadsTest extends WebTestHelper { $this->File->caching = false; } + function testDownloadCount() { + //This is really stupid because you can't easily change the active db, and of course gets on the + //main page get counted in the main db, not the test db, so we need to check that + $downloadcount = $this->Download->query("SELECT COUNT(id) FROM `" . DB_NAME . "`.downloads"); + $previouscount = $downloadcount[0][0]['COUNT(id)']; + + //get the file twice, make sure it's only counted once! + $this->getAction("/downloads/file/9/"); + $this->retry(); + + $count = $this->Download->query("SELECT COUNT(file_id) FROM `" . DB_NAME . "`.downloads"); + $downloadcount = $count[0][0]['COUNT(file_id)']; + $this->assertEqual($downloadcount-1, $previouscount); + $this->Download->query("DELETE FROM `" . DB_NAME . "`.downloads WHERE file_id='9' AND useragent='' AND userip='{$_SERVER['SERVER_ADDR']}'"); + } + function testNoCacheHeaders() { $action = $this->actionURI("/downloads/file/9/"); $this->get($action); $this->assertHeader('Cache-Control', 'no-store, must-revalidate, post-check=0, pre-check=0, private, max-age=0', "cache-control header for {$action}"); $this->assertHeader('Pragma', 'private', "Pragma private header for {$action}"); + } function testNoSandboxForYou() { $this->getAction("/downloads/file/25982/"); $this->assertWantedPattern("@Add-on not found@", "Sandbox Denied without Login?"); } + function testDownloadMD5() { + $this->getAction("/downloads/file/9/"); + $file_data = $this->File->findById('9'); - function assertFileDownload($file_id, $action, $message) { - $this->getAction($action); - $file_data = $this->File->findById($file_id); $file_loc = REPO_PATH . '/' . $file_data['Version']['addon_id'] . '/' . $file_data['File']['filename']; - $this->assertEqual(md5_file($file_loc), md5($this->_browser->getContent()), $message); + + $this->assertEqual(md5_file($file_loc), md5($this->_browser->getContent())); } + function testSearchEngineMD5() { + $this->getAction("/downloads/file/8/a9.src"); + $file_data = $this->File->findById('8'); - function testDownloads() { - $this->assertFileDownload(9, '/downloads/file/9/', 'Extension download works.'); - $this->assertFileDownload(8, '/downloads/file/8/a9.src', 'Search download works.'); - $this->assertFileDownload(23559, '/downloads/file/23559', 'Dictionary download works.'); + $file_loc = REPO_PATH . '/' . $file_data['Version']['addon_id'] . '/' . $file_data['File']['filename']; + + $this->assertEqual(md5_file($file_loc), md5($this->_browser->getContent())); } + function testDictionaryMD5() { + $file = $this->getAction("/downloads/file/23559"); + $file_data = $this->File->findById('23559'); + + $file_loc = REPO_PATH . '/' . $file_data['Version']['addon_id'] . '/' . $file_data['File']['filename']; + + $this->assertEqual(md5_file($file_loc), md5($this->_browser->getContent())); + } + } ?> |