From 7b8eb725c3a9a2b30942db2bab84636a9958a2bb Mon Sep 17 00:00:00 2001 From: Victor Dubiniuk Date: Wed, 26 Nov 2014 19:18:22 +0300 Subject: [PATCH] Test OC\Updater::check --- tests/lib/updater.php | 59 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/tests/lib/updater.php b/tests/lib/updater.php index 155dccf78a79..49105dbe2b33 100644 --- a/tests/lib/updater.php +++ b/tests/lib/updater.php @@ -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( + '' + ) + ; + // 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(' + + 7.0.3.4 + ownCloud 7.0.3 + http://download.owncloud.org/community/owncloud-7.0.3.zip + http://owncloud.org/ +') + ; + + $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']); + } } \ No newline at end of file