2014-09-11 21:21:56 +04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Copyright (c) 2014 Lukas Reschke <lukas@owncloud.com>
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
2014-11-11 00:59:50 +03:00
|
|
|
class TestHTTPHelper extends \Test\TestCase {
|
2014-09-11 21:21:56 +04:00
|
|
|
|
2014-11-27 20:19:14 +03:00
|
|
|
/** @var \OCP\IConfig*/
|
2014-09-11 21:21:56 +04:00
|
|
|
private $config;
|
|
|
|
/** @var \OC\HTTPHelper */
|
|
|
|
private $httpHelperMock;
|
2014-12-04 21:51:04 +03:00
|
|
|
/** @var \OC\Security\CertificateManager */
|
|
|
|
private $certificateManager;
|
2014-09-11 21:21:56 +04:00
|
|
|
|
2014-11-11 00:59:50 +03:00
|
|
|
protected function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
|
2014-11-27 20:19:14 +03:00
|
|
|
$this->config = $this->getMockBuilder('\OCP\IConfig')
|
2014-09-11 21:21:56 +04:00
|
|
|
->disableOriginalConstructor()->getMock();
|
2014-12-04 21:51:04 +03:00
|
|
|
$this->certificateManager = $this->getMock('\OCP\ICertificateManager');
|
2014-09-11 21:21:56 +04:00
|
|
|
$this->httpHelperMock = $this->getMockBuilder('\OC\HTTPHelper')
|
2014-12-04 21:51:04 +03:00
|
|
|
->setConstructorArgs(array($this->config, $this->certificateManager))
|
2014-09-11 21:21:56 +04:00
|
|
|
->setMethods(array('getHeaders'))
|
|
|
|
->getMock();
|
|
|
|
}
|
|
|
|
|
2014-11-21 12:48:05 +03:00
|
|
|
public function isHttpTestData() {
|
2014-09-11 21:21:56 +04:00
|
|
|
return array(
|
|
|
|
array('http://wwww.owncloud.org/enterprise/', true),
|
|
|
|
array('https://wwww.owncloud.org/enterprise/', true),
|
|
|
|
array('HTTPS://WWW.OWNCLOUD.ORG', true),
|
|
|
|
array('HTTP://WWW.OWNCLOUD.ORG', true),
|
|
|
|
array('FILE://WWW.OWNCLOUD.ORG', false),
|
|
|
|
array('file://www.owncloud.org', false),
|
|
|
|
array('FTP://WWW.OWNCLOUD.ORG', false),
|
|
|
|
array('ftp://www.owncloud.org', false),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-11-21 12:48:05 +03:00
|
|
|
* @dataProvider isHttpTestData
|
2014-09-11 21:21:56 +04:00
|
|
|
*/
|
|
|
|
public function testIsHTTP($url, $expected) {
|
|
|
|
$this->assertSame($expected, $this->httpHelperMock->isHTTPURL($url));
|
|
|
|
}
|
|
|
|
|
2014-12-04 21:51:04 +03:00
|
|
|
/**
|
|
|
|
* @dataProvider postParameters
|
|
|
|
*/
|
2015-03-12 23:43:41 +03:00
|
|
|
public function testAssemblePostParameters($parameterList, $expectedResult) {
|
2014-12-04 21:51:04 +03:00
|
|
|
$helper = \OC::$server->getHTTPHelper();
|
|
|
|
$result = \Test_Helper::invokePrivate($helper, 'assemblePostParameters', array($parameterList));
|
|
|
|
$this->assertSame($expectedResult, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function postParameters() {
|
|
|
|
return array(
|
|
|
|
array(array('k1' => 'v1'), 'k1=v1'),
|
|
|
|
array(array('k1' => 'v1', 'k2' => 'v2'), 'k1=v1&k2=v2'),
|
|
|
|
array(array(), ''),
|
|
|
|
);
|
|
|
|
}
|
2014-09-11 21:21:56 +04:00
|
|
|
}
|