2014-09-18 19:45:30 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OC;
|
|
|
|
|
2014-11-11 00:59:50 +03:00
|
|
|
class UpdaterTest extends \Test\TestCase {
|
2014-09-18 19:45:30 +04:00
|
|
|
|
2014-11-21 12:48:05 +03:00
|
|
|
public function versionCompatibilityTestData() {
|
2014-09-18 19:45:30 +04:00
|
|
|
return array(
|
|
|
|
array('1.0.0.0', '2.2.0', true),
|
|
|
|
array('1.1.1.1', '2.0.0', true),
|
|
|
|
array('5.0.3', '4.0.3', false),
|
|
|
|
array('12.0.3', '13.4.5', true),
|
|
|
|
array('1', '2', true),
|
|
|
|
array('2', '2', true),
|
|
|
|
array('6.0.5', '6.0.6', true),
|
|
|
|
array('5.0.6', '7.0.4', false)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-11-21 12:48:05 +03:00
|
|
|
* @dataProvider versionCompatibilityTestData
|
2014-09-18 19:45:30 +04:00
|
|
|
*/
|
2014-11-26 19:18:22 +03:00
|
|
|
public function testIsUpgradePossible($oldVersion, $newVersion, $result) {
|
2014-12-10 01:13:38 +03:00
|
|
|
$updater = new Updater(\OC::$server->getHTTPHelper(), \OC::$server->getConfig());
|
2014-09-18 19:45:30 +04:00
|
|
|
$this->assertSame($result, $updater->isUpgradePossible($oldVersion, $newVersion));
|
|
|
|
}
|
2014-12-04 21:51:04 +03:00
|
|
|
|
2014-12-10 01:13:38 +03:00
|
|
|
public function testBrokenXmlResponse(){
|
|
|
|
$invalidUpdater = $this->getUpdaterMock('OMG!');
|
|
|
|
$invalidResult = $invalidUpdater->check();
|
|
|
|
$this->assertEmpty($invalidResult);
|
|
|
|
}
|
2014-12-04 21:51:04 +03:00
|
|
|
|
2014-12-10 01:13:38 +03:00
|
|
|
public function testEmptyResponse(){
|
|
|
|
$emptyUpdater = $this->getUpdaterMock('');
|
|
|
|
$emptyResult = $emptyUpdater->check();
|
|
|
|
$this->assertEmpty($emptyResult);
|
2014-12-04 21:51:04 +03:00
|
|
|
|
2014-12-10 01:13:38 +03:00
|
|
|
// Error while fetching new contents e.g. too many redirects
|
|
|
|
$falseUpdater = $this->getUpdaterMock(false);
|
|
|
|
$falseResult = $falseUpdater->check();
|
|
|
|
$this->assertEmpty($falseResult);
|
|
|
|
}
|
2014-12-04 21:51:04 +03:00
|
|
|
|
2014-12-10 01:13:38 +03:00
|
|
|
public function testValidEmptyXmlResponse(){
|
2014-12-08 17:38:56 +03:00
|
|
|
$updater = $this->getUpdaterMock(
|
|
|
|
'<?xml version="1.0"?><owncloud><version></version><versionstring></versionstring><url></url><web></web></owncloud>'
|
|
|
|
);
|
|
|
|
$result = array_map('strval', $updater->check());
|
2014-12-04 21:51:04 +03:00
|
|
|
|
2014-12-08 17:38:56 +03:00
|
|
|
$this->assertArrayHasKey('version', $result);
|
|
|
|
$this->assertArrayHasKey('versionstring', $result);
|
|
|
|
$this->assertArrayHasKey('url', $result);
|
|
|
|
$this->assertArrayHasKey('web', $result);
|
2014-11-26 19:18:22 +03:00
|
|
|
$this->assertEmpty($result['version']);
|
|
|
|
$this->assertEmpty($result['versionstring']);
|
|
|
|
$this->assertEmpty($result['url']);
|
|
|
|
$this->assertEmpty($result['web']);
|
2014-12-10 01:13:38 +03:00
|
|
|
}
|
2014-12-04 21:51:04 +03:00
|
|
|
|
2014-12-10 01:13:38 +03:00
|
|
|
public function testValidUpdateResponse(){
|
2014-12-08 17:38:56 +03:00
|
|
|
$newUpdater = $this->getUpdaterMock(
|
|
|
|
'<?xml version="1.0"?>
|
2014-11-26 19:18:22 +03:00
|
|
|
<owncloud>
|
|
|
|
<version>7.0.3.4</version>
|
|
|
|
<versionstring>ownCloud 7.0.3</versionstring>
|
|
|
|
<url>http://download.owncloud.org/community/owncloud-7.0.3.zip</url>
|
|
|
|
<web>http://owncloud.org/</web>
|
2014-12-08 17:38:56 +03:00
|
|
|
</owncloud>'
|
|
|
|
);
|
|
|
|
$newResult = array_map('strval', $newUpdater->check());
|
2014-12-04 21:51:04 +03:00
|
|
|
|
2014-12-08 17:38:56 +03:00
|
|
|
$this->assertArrayHasKey('version', $newResult);
|
|
|
|
$this->assertArrayHasKey('versionstring', $newResult);
|
|
|
|
$this->assertArrayHasKey('url', $newResult);
|
|
|
|
$this->assertArrayHasKey('web', $newResult);
|
|
|
|
$this->assertEquals('7.0.3.4', $newResult['version']);
|
|
|
|
$this->assertEquals('ownCloud 7.0.3', $newResult['versionstring']);
|
|
|
|
$this->assertEquals('http://download.owncloud.org/community/owncloud-7.0.3.zip', $newResult['url']);
|
|
|
|
$this->assertEquals('http://owncloud.org/', $newResult['web']);
|
|
|
|
}
|
2014-12-04 21:51:04 +03:00
|
|
|
|
2014-12-08 17:38:56 +03:00
|
|
|
protected function getUpdaterMock($content){
|
|
|
|
// Invalidate cache
|
2015-02-17 14:00:39 +03:00
|
|
|
$mockedConfig = $this->getMockBuilder('\OCP\IConfig')
|
2014-12-10 01:13:38 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock()
|
|
|
|
;
|
2014-12-04 21:51:04 +03:00
|
|
|
|
|
|
|
$certificateManager = $this->getMock('\OCP\ICertificateManager');
|
2014-12-08 17:38:56 +03:00
|
|
|
$mockedHTTPHelper = $this->getMockBuilder('\OC\HTTPHelper')
|
2014-12-04 21:51:04 +03:00
|
|
|
->setConstructorArgs(array(\OC::$server->getConfig(), $certificateManager))
|
2014-12-08 17:38:56 +03:00
|
|
|
->getMock()
|
2014-11-26 19:18:22 +03:00
|
|
|
;
|
2014-12-04 21:51:04 +03:00
|
|
|
|
|
|
|
$mockedHTTPHelper->expects($this->once())->method('getUrlContent')->will($this->returnValue($content));
|
|
|
|
|
2015-02-17 14:00:39 +03:00
|
|
|
return new Updater($mockedHTTPHelper, $mockedConfig);
|
2014-11-26 19:18:22 +03:00
|
|
|
}
|
2014-09-18 19:45:30 +04:00
|
|
|
|
2014-12-08 17:38:56 +03:00
|
|
|
}
|