Skip to content

Commit

Permalink
Test OC\Updater::check
Browse files Browse the repository at this point in the history
  • Loading branch information
VicDeo committed Nov 26, 2014
1 parent b64fafc commit 7b8eb72
Showing 1 changed file with 57 additions and 2 deletions.
59 changes: 57 additions & 2 deletions tests/lib/updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,64 @@ public function versionCompatibilityTestData() {
/**
* @dataProvider versionCompatibilityTestData
*/
function testIsUpgradePossible($oldVersion, $newVersion, $result) {
$updater = new Updater();
public function testIsUpgradePossible($oldVersion, $newVersion, $result) {
$updater = new Updater(\OC::$server->getHTTPHelper());
$this->assertSame($result, $updater->isUpgradePossible($oldVersion, $newVersion));
}


public function testCheck(){
$updater = new Updater($httpHelper);
$httpHelper = $this->getMockBuilder('\OC\HTTPHelper')
->getMock();

$httpHelper->method('getUrlContent')
->willReturn(
'<?xml version="1.0"?><owncloud><version></version><versionstring></versionstring><url></url><web></web></owncloud>'
)
;
// Invalidate cache
\OC_Appconfig::setValue('core', 'lastupdatedat', 0);
$result = $updater->check();
$this->assertContains('version', $result);
$this->assertContains('versionstring', $result);
$this->assertContains('url', $result);
$this->assertContains('web', $result);
$this->assertEmpty($result['version']);
$this->assertEmpty($result['versionstring']);
$this->assertEmpty($result['url']);
$this->assertEmpty($result['web']);

// Invalidate cache
\OC_Appconfig::setValue('core', 'lastupdatedat', 0);
$httpHelper->method('getUrlContent')
->willReturn('')
;

$emptyResult = $updater->check();
$this->assertEmpty($emptyResult);

// Invalidate cache
\OC_Appconfig::setValue('core', 'lastupdatedat', 0);
$httpHelper->method('getUrlContent')
->willReturn('<?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 = $updater->check();
$this->assertContains('version', $newResult);
$this->assertContains('versionstring', $newResult);
$this->assertContains('url', $newResult);
$this->assertContains('web', $newResult);
$this->assertEqual('7.0.3.4', $newResult['version']);
$this->assertEqual('ownCloud 7.0.3', $newResult['versionstring']);
$this->assertEqual('http://download.owncloud.org/community/owncloud-7.0.3.zip', $newResult['url']);
$this->assertEqual('http://owncloud.org/', $newResult['web']);
}

}

0 comments on commit 7b8eb72

Please sign in to comment.