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

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Steur <tsteur@users.noreply.github.com>2019-09-17 23:20:26 +0300
committerdiosmosis <diosmosis@users.noreply.github.com>2019-09-17 23:20:26 +0300
commit583d8d1c28cf0b96810a81dfb7c76a3c1140d764 (patch)
treed41249e5762a1f75192969ef600c18e33da3413d /tests/PHPUnit/Integration/HttpTest.php
parent93b7f61ae9ca341f889c1ac36c7fb6bc11ff7736 (diff)
Let plugins hook and listen into http requests (#14877)
* Let plugins hook and listen into http requests * fix test
Diffstat (limited to 'tests/PHPUnit/Integration/HttpTest.php')
-rw-r--r--tests/PHPUnit/Integration/HttpTest.php96
1 files changed, 96 insertions, 0 deletions
diff --git a/tests/PHPUnit/Integration/HttpTest.php b/tests/PHPUnit/Integration/HttpTest.php
index d42eedcf0f..f179276443 100644
--- a/tests/PHPUnit/Integration/HttpTest.php
+++ b/tests/PHPUnit/Integration/HttpTest.php
@@ -9,6 +9,7 @@
namespace Piwik\Tests\Integration;
use Piwik\Http;
+use Piwik\Piwik;
use Piwik\Tests\Framework\Fixture;
/**
@@ -317,4 +318,99 @@ class HttpTest extends \PHPUnit_Framework_TestCase
*/
$this->assertEquals(51, strlen($result));
}
+
+ public function test_http_postsEvent()
+ {
+ $params = null;
+ $params2 = null;
+ Piwik::addAction('Http.sendHttpRequest', function () use (&$params) {
+ $params = func_get_args();
+ });
+ Piwik::addAction('Http.sendHttpRequest.end', function () use (&$params2) {
+ $params2 = func_get_args();
+ });
+ $destinationPath = PIWIK_USER_PATH . '/tmp/latest/LATEST';
+ $url = Fixture::getRootUrl() . 'tests/PHPUnit/Integration/Http/Post.php';
+ Http::sendHttpRequestBy(
+ Http::getTransportMethod(),
+ $url,
+ 30,
+ $userAgent = null,
+ $destinationPath,
+ $file = null,
+ $followDepth = 0,
+ $acceptLanguage = false,
+ $acceptInvalidSslCertificate = false,
+ $byteRange = array(10, 20),
+ $getExtendedInfo = false,
+ $httpMethod = 'POST',
+ $httpUsername = '',
+ $httpPassword = '',
+ array('adf2' => '44', 'afc23' => 'ab12')
+ );
+
+ $this->assertEquals(array($url, array(
+ 'httpMethod' => 'POST',
+ 'body' => array('adf2' => '44','afc23' => 'ab12'),
+ 'userAgent' => 'Piwik/3.12.0-b3',
+ 'timeout' => 30,
+ 'headers' => array(
+ 'Range: bytes=10-20',
+ 'Via: 3.12.0-b3 (Piwik/3.12.0-b3)',
+ 'X-Forwarded-For: 127.0.0.1',
+ ),
+ 'verifySsl' => true,
+ 'destinationPath' => $destinationPath
+ ), null, null, array()), $params);
+
+ $this->assertNotEmpty($params2[4]);// headers
+ unset($params2[4]);
+ $this->assertEquals(array($url, array(
+ 'httpMethod' => 'POST',
+ 'body' => array('adf2' => '44','afc23' => 'ab12'),
+ 'userAgent' => 'Piwik/3.12.0-b3',
+ 'timeout' => 30,
+ 'headers' => array(
+ 'Range: bytes=10-20',
+ 'Via: 3.12.0-b3 (Piwik/3.12.0-b3)',
+ 'X-Forwarded-For: 127.0.0.1',
+ ),
+ 'verifySsl' => true,
+ 'destinationPath' => $destinationPath
+ ), '{"adf2":"44","afc23":"ab12","method":"post"}', 200), $params2);
+ }
+
+ public function test_http_returnsResultOfPostedEvent()
+ {
+ Piwik::addAction('Http.sendHttpRequest', function ($url, $args, &$response, &$status, &$headers) {
+ $response = '{test: true}';
+ $status = 204;
+ $headers = array('content-length' => 948);
+ });
+
+ $result = Http::sendHttpRequestBy(
+ Http::getTransportMethod(),
+ Fixture::getRootUrl() . 'tests/PHPUnit/Integration/Http/Post.php',
+ 30,
+ $userAgent = null,
+ $destinationPath = null,
+ $file = null,
+ $followDepth = 0,
+ $acceptLanguage = false,
+ $acceptInvalidSslCertificate = false,
+ $byteRange = array(10, 20),
+ $getExtendedInfo = true,
+ $httpMethod = 'POST',
+ $httpUsername = '',
+ $httpPassword = '',
+ array('adf2' => '44', 'afc23' => 'ab12')
+ );
+
+ $this->assertEquals(array(
+ 'data' => '{test: true}',
+ 'status' => 204,
+ 'headers' => array('content-length' => 948)
+ ), $result);
+ }
+
}