Remove deprecated HTTPHelper from InfoParser

This commit is contained in:
Thomas Müller 2016-04-19 12:19:39 +02:00
parent ded84bf571
commit d0030aad6c
No known key found for this signature in database
GPG Key ID: A943788A3BBEC44C
6 changed files with 33 additions and 27 deletions

View File

@ -32,7 +32,7 @@
/** @var $application Symfony\Component\Console\Application */
$application->add(new OC\Core\Command\Status);
$application->add(new OC\Core\Command\Check(\OC::$server->getConfig()));
$infoParser = new \OC\App\InfoParser(\OC::$server->getHTTPHelper(), \OC::$server->getURLGenerator());
$infoParser = new \OC\App\InfoParser(\OC::$server->getURLGenerator());
$application->add(new OC\Core\Command\App\CheckCode($infoParser));
$application->add(new OC\Core\Command\L10n\CreateJs());
$application->add(new \OC\Core\Command\Integrity\SignApp(

View File

@ -27,22 +27,14 @@ namespace OC\App;
use OCP\IURLGenerator;
class InfoParser {
/**
* @var \OC\HTTPHelper
*/
private $httpHelper;
/**
* @var IURLGenerator
*/
/** @var IURLGenerator */
private $urlGenerator;
/**
* @param \OC\HTTPHelper $httpHelper
* @param IURLGenerator $urlGenerator
*/
public function __construct(\OC\HTTPHelper $httpHelper, IURLGenerator $urlGenerator) {
$this->httpHelper = $httpHelper;
public function __construct(IURLGenerator $urlGenerator) {
$this->urlGenerator = $urlGenerator;
}
@ -79,12 +71,21 @@ class InfoParser {
if (!array_key_exists('types', $array)) {
$array['types'] = array();
}
if (!array_key_exists('repair-steps', $array)) {
$array['repair-steps'] = array();
}
if (!array_key_exists('pre-migration', $array['repair-steps'])) {
$array['repair-steps']['pre-migration'] = array();
}
if (!array_key_exists('post-migration', $array['repair-steps'])) {
$array['repair-steps']['post-migration'] = array();
}
if (array_key_exists('documentation', $array) && is_array($array['documentation'])) {
foreach ($array['documentation'] as $key => $url) {
// If it is not an absolute URL we assume it is a key
// i.e. admin-ldap will get converted to go.php?to=admin-ldap
if (!$this->httpHelper->isHTTPURL($url)) {
if (!$this->isHTTPURL($url)) {
$url = $this->urlGenerator->linkToDocs($url);
}
@ -103,7 +104,12 @@ class InfoParser {
$array['types'] = array();
}
}
if (isset($array['repair-steps']['pre-migration']['step']) && is_array($array['repair-steps']['pre-migration']['step'])) {
$array['repair-steps']['pre-migration'] = $array['repair-steps']['pre-migration']['step'];
}
if (isset($array['repair-steps']['post-migration']['step']) && is_array($array['repair-steps']['post-migration']['step'])) {
$array['repair-steps']['post-migration'] = $array['repair-steps']['post-migration']['step'];
}
return $array;
}
@ -161,4 +167,8 @@ class InfoParser {
return $array;
}
private function isHTTPURL($url) {
return stripos($url, 'https://') === 0 || stripos($url, 'http://') === 0;
}
}

View File

@ -626,7 +626,7 @@ class OC_App {
$file = $appPath . '/appinfo/info.xml';
}
$parser = new \OC\App\InfoParser(\OC::$server->getHTTPHelper(), \OC::$server->getURLGenerator());
$parser = new \OC\App\InfoParser(\OC::$server->getURLGenerator());
$data = $parser->parse($file);
if (is_array($data)) {

View File

@ -67,5 +67,9 @@
"max-version": "8"
}
}
},
"repair-steps": {
"pre-migration": [],
"post-migration": []
}
}

View File

@ -43,7 +43,7 @@ class InfoCheckerTest extends TestCase {
protected function setUp() {
parent::setUp();
$infoParser = new InfoParser(\OC::$server->getHTTPHelper(), \OC::$server->getURLGenerator());
$infoParser = new InfoParser(\OC::$server->getURLGenerator());
$this->infoChecker = new InfoChecker($infoParser);
}

View File

@ -10,35 +10,27 @@
namespace Test\App;
use OC;
use OCP\IURLGenerator;
use Test\TestCase;
class InfoParser extends TestCase {
/**
* @var \OC\App\InfoParser
*/
/** @var \OC\App\InfoParser */
private $parser;
public function setUp() {
$config = $this->getMockBuilder('\OCP\IConfig')
->disableOriginalConstructor()->getMock();
$clientService = $this->getMock('\OCP\Http\Client\IClientService');
$httpHelper = $this->getMockBuilder('\OC\HTTPHelper')
->setConstructorArgs([$config, $clientService])
->setMethods(['getHeaders'])
->getMock();
$urlGenerator = $this->getMockBuilder('\OCP\IURLGenerator')
->disableOriginalConstructor()
->getMock();
//linkToDocs
/** @var IURLGenerator | \PHPUnit_Framework_MockObject_MockObject $urlGenerator */
$urlGenerator->expects($this->any())
->method('linkToDocs')
->will($this->returnCallback(function ($url) {
return "https://docs.example.com/server/go.php?to=$url";
}));
$this->parser = new \OC\App\InfoParser($httpHelper, $urlGenerator);
$this->parser = new \OC\App\InfoParser($urlGenerator);
}
/**