server/tests/lib/updater.php
Bjoern Schiessle 24993280ed Next step in server-to-server sharing next generation, see #12285
Beside some small improvements and bug fixes this will probably the final state for OC8.

To test this you need to set up two ownCloud instances. Let's say:

URL: myPC/firstOwnCloud user: user1
URL: myPC/secondOwnCloud user: user2
Now user1 can share a file with user2 by entering the username and the URL to the second ownCloud to the share-drop-down, in this case "user2@myPC/secondOwnCloud".

The next time user2 login he will get a notification that he received a server-to-server share with the option to accept/decline it. If he accept it the share will be mounted. In both cases a event will be send back to user1 and add a notification to the activity stream that the share was accepted/declined.

If user1 decides to unshare the file again from user2 the share will automatically be removed from the second ownCloud server and user2 will see a notification in his activity stream that user1@myPC/firstOwnCloud has unshared the file/folder from him.
2014-12-19 15:20:24 +01:00

107 lines
3.4 KiB
PHP

<?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;
class UpdaterTest extends \Test\TestCase {
public function versionCompatibilityTestData() {
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)
);
}
/**
* @dataProvider versionCompatibilityTestData
*/
public function testIsUpgradePossible($oldVersion, $newVersion, $result) {
$updater = new Updater(\OC::$server->getHTTPHelper(), \OC::$server->getConfig());
$this->assertSame($result, $updater->isUpgradePossible($oldVersion, $newVersion));
}
public function testBrokenXmlResponse(){
$invalidUpdater = $this->getUpdaterMock('OMG!');
$invalidResult = $invalidUpdater->check();
$this->assertEmpty($invalidResult);
}
public function testEmptyResponse(){
$emptyUpdater = $this->getUpdaterMock('');
$emptyResult = $emptyUpdater->check();
$this->assertEmpty($emptyResult);
// Error while fetching new contents e.g. too many redirects
$falseUpdater = $this->getUpdaterMock(false);
$falseResult = $falseUpdater->check();
$this->assertEmpty($falseResult);
}
public function testValidEmptyXmlResponse(){
$updater = $this->getUpdaterMock(
'<?xml version="1.0"?><owncloud><version></version><versionstring></versionstring><url></url><web></web></owncloud>'
);
$result = array_map('strval', $updater->check());
$this->assertArrayHasKey('version', $result);
$this->assertArrayHasKey('versionstring', $result);
$this->assertArrayHasKey('url', $result);
$this->assertArrayHasKey('web', $result);
$this->assertEmpty($result['version']);
$this->assertEmpty($result['versionstring']);
$this->assertEmpty($result['url']);
$this->assertEmpty($result['web']);
}
public function testValidUpdateResponse(){
$newUpdater = $this->getUpdaterMock(
'<?xml version="1.0"?>
<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>
</owncloud>'
);
$newResult = array_map('strval', $newUpdater->check());
$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']);
}
protected function getUpdaterMock($content){
// Invalidate cache
$mockedAppConfig = $this->getMockBuilder('\OC\AppConfig')
->disableOriginalConstructor()
->getMock()
;
$certificateManager = $this->getMock('\OCP\ICertificateManager');
$mockedHTTPHelper = $this->getMockBuilder('\OC\HTTPHelper')
->setConstructorArgs(array(\OC::$server->getConfig(), $certificateManager))
->getMock()
;
$mockedHTTPHelper->expects($this->once())->method('getUrlContent')->will($this->returnValue($content));
return new Updater($mockedHTTPHelper, $mockedAppConfig);
}
}