Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Http.test.php « core « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9ac7daabfd77d4bd224dc7ed44b419a4b9b986db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
if(!defined("PIWIK_PATH_TEST_TO_ROOT")) {
	define('PIWIK_PATH_TEST_TO_ROOT', getcwd().'/../..');
}
if(!defined('PIWIK_CONFIG_TEST_INCLUDED'))
{
	require_once PIWIK_PATH_TEST_TO_ROOT . "/tests/config_test.php";
}
class Test_Piwik_Http extends UnitTestCase
{
	public function test_fetchRemoteFile()
	{
		$methods = array(
			'curl', 'stream', 'socket'
		);

		$this->assertTrue( in_array(Piwik_Http::getTransportMethod(), $methods) );

		foreach($methods as $method)
		{
			$version = '';
			try {
				$version = Piwik_Http::sendHttpRequestBy($method, 'http://api.piwik.org/1.0/getLatestVersion/', 5);
			}
			catch(Exception $e) {
				var_dump($e->getMessage());
			}

			$this->assertTrue( preg_match('/^([0-9.]+)$/', $version) );
		}

		$destinationPath = PIWIK_USER_PATH . '/tmp/latest/LATEST';
		try {
			Piwik_Http::fetchRemoteFile('http://api.piwik.org/1.0/getLatestVersion/', $destinationPath, 3);
		}
		catch(Exception $e) {
			var_dump($e->getMessage());
		}

		$this->assertTrue( filesize($destinationPath) > 0 );

		$destinationPath = PIWIK_USER_PATH . '/tmp/latest/latest.zip';
		try {
			Piwik_Http::fetchRemoteFile('http://piwik.org/latest.zip', $destinationPath, 3);
		}
		catch(Exception $e) {
			var_dump($e->getMessage());
		}

		$this->assertTrue( filesize($destinationPath) > 0 );
	}
}