From 81d571241991926f8820c43020a0250eb305a0b0 Mon Sep 17 00:00:00 2001 From: Victor Dubiniuk Date: Mon, 8 Dec 2014 17:38:56 +0300 Subject: Fix tests. Add two more test cases --- tests/lib/updater.php | 91 +++++++++++++++++++++++++++++---------------------- 1 file changed, 52 insertions(+), 39 deletions(-) (limited to 'tests') diff --git a/tests/lib/updater.php b/tests/lib/updater.php index 5a05bc09bb7..832f60fac06 100644 --- a/tests/lib/updater.php +++ b/tests/lib/updater.php @@ -33,58 +33,71 @@ class UpdaterTest extends \Test\TestCase { public function testCheck(){ - $httpHelper = $this->getMockBuilder('\OC\HTTPHelper') - ->getMock(); - - $httpHelper->method('getUrlContent') - ->willReturn( - '' - ) - ; + // Valid XML. Empty values + $updater = $this->getUpdaterMock( + '' + ); + $result = array_map('strval', $updater->check()); - $updater = new Updater($httpHelper); - // 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->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']); - // Invalidate cache - \OC_Appconfig::setValue('core', 'lastupdatedat', 0); - $httpHelper->method('getUrlContent') - ->willReturn('') - ; - - $emptyResult = $updater->check(); + // Empty feed + $emptyUpdater = $this->getUpdaterMock(''); + $emptyResult = $emptyUpdater->check(); $this->assertEmpty($emptyResult); - - // Invalidate cache - \OC_Appconfig::setValue('core', 'lastupdatedat', 0); - $httpHelper->method('getUrlContent') - ->willReturn(' + + // Error while fetching new contents e.g. too many redirects + $falseUpdater = $this->getUpdaterMock(false); + $falseResult = $falseUpdater->check(); + $this->assertEmpty($falseResult); + + // Valid XML. New version available + $newUpdater = $this->getUpdaterMock( + ' 7.0.3.4 ownCloud 7.0.3 http://download.owncloud.org/community/owncloud-7.0.3.zip http://owncloud.org/ -') +' + ); + $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']); + + // Invalid XML + $invalidUpdater = $this->getUpdaterMock('OMG!'); + $invalidResult = $invalidUpdater->check(); + $this->assertEmpty($invalidResult); + } + + protected function getUpdaterMock($content){ + // Invalidate cache + \OC_Appconfig::setValue('core', 'lastupdatedat', 0); + + $mockedHTTPHelper = $this->getMockBuilder('\OC\HTTPHelper') + ->setConstructorArgs(array(\OC::$server->getConfig())) + ->getMock() ; - $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']); + $mockedHTTPHelper->method('getUrlContent') + ->willReturn($content) + ; + return new Updater($mockedHTTPHelper); } -} \ No newline at end of file +} -- cgit v1.2.3