diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2024-03-13 01:21:40 -0100 |
---|---|---|
committer | Maxence Lange <maxence@artificial-owl.com> | 2024-03-13 02:22:11 -0100 |
commit | 519e4345739876d2ae7e064e347d19524905b090 (patch) | |
tree | 0b997f8d18f54efcb97e9278503ae42e119fd9b6 /tests | |
parent | 5723c13dc0c7f4025c4d976c1f792f9bb3513fe2 (diff) | |
download | nextcloud-server-519e4345739876d2ae7e064e347d19524905b090.tar.gz nextcloud-server-519e4345739876d2ae7e064e347d19524905b090.zip |
fix(updatenotification): spread the use of new appconfig
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/Updater/VersionCheckTest.php | 201 | ||||
-rw-r--r-- | tests/lib/UpdaterTest.php | 7 |
2 files changed, 108 insertions, 100 deletions
diff --git a/tests/lib/Updater/VersionCheckTest.php b/tests/lib/Updater/VersionCheckTest.php index 0f073abc3ce..ed04975fc54 100644 --- a/tests/lib/Updater/VersionCheckTest.php +++ b/tests/lib/Updater/VersionCheckTest.php @@ -24,6 +24,7 @@ namespace Test\Updater; use OC\Updater\VersionCheck; use OCP\Http\Client\IClientService; +use OCP\IAppConfig; use OCP\IConfig; use OCP\IUserManager; use OCP\Support\Subscription\IRegistry; @@ -33,6 +34,8 @@ use Psr\Log\LoggerInterface; class VersionCheckTest extends \Test\TestCase { /** @var IConfig| \PHPUnit\Framework\MockObject\MockObject */ private $config; + /** @var IAppConfig| \PHPUnit\Framework\MockObject\MockObject */ + private $appConfig; /** @var VersionCheck | \PHPUnit\Framework\MockObject\MockObject*/ private $updater; /** @var IRegistry | \PHPUnit\Framework\Mo2ckObject\MockObject*/ @@ -45,6 +48,9 @@ class VersionCheckTest extends \Test\TestCase { $this->config = $this->getMockBuilder(IConfig::class) ->disableOriginalConstructor() ->getMock(); + $this->appConfig = $this->getMockBuilder(IAppConfig::class) + ->disableOriginalConstructor() + ->getMock(); $clientService = $this->getMockBuilder(IClientService::class) ->disableOriginalConstructor() ->getMock(); @@ -59,6 +65,7 @@ class VersionCheckTest extends \Test\TestCase { ->setConstructorArgs([ $clientService, $this->config, + $this->appConfig, $this->createMock(IUserManager::class), $this->registry, $this->logger, @@ -71,7 +78,7 @@ class VersionCheckTest extends \Test\TestCase { * @return string */ private function buildUpdateUrl($baseUrl) { - return $baseUrl . '?version='.implode('x', Util::getVersion()).'xinstalledatxlastupdatedatx'.\OC_Util::getChannel().'xxx'.PHP_MAJOR_VERSION.'x'.PHP_MINOR_VERSION.'x'.PHP_RELEASE_VERSION.'x0x0'; + return $baseUrl . '?version='.implode('x', Util::getVersion()).'xinstalledatx' . time() . 'x'.\OC_Util::getChannel().'xxx'.PHP_MAJOR_VERSION.'x'.PHP_MINOR_VERSION.'x'.PHP_RELEASE_VERSION.'x0x0'; } public function testCheckInCache() { @@ -88,17 +95,16 @@ class VersionCheckTest extends \Test\TestCase { ->method('getSystemValueBool') ->with('has_internet_connection', true) ->willReturn(true); + $this->appConfig + ->expects($this->once()) + ->method('getValueInt') + ->with('core', 'lastupdatedat') + ->willReturn(time()); $this->config - ->expects($this->exactly(2)) + ->expects($this->once()) ->method('getAppValue') - ->withConsecutive( - ['core', 'lastupdatedat'], - ['core', 'lastupdateResult'] - ) - ->willReturnOnConsecutiveCalls( - time(), - json_encode($expectedResult) - ); + ->with('core', 'lastupdateResult') + ->willReturn(json_encode($expectedResult)); $this->assertSame($expectedResult, $this->updater->check()); } @@ -119,33 +125,32 @@ class VersionCheckTest extends \Test\TestCase { ->method('getSystemValueBool') ->with('has_internet_connection', true) ->willReturn(true); - $this->config - ->expects($this->exactly(4)) - ->method('getAppValue') - ->withConsecutive( - ['core', 'lastupdatedat'], - ['core', 'installedat'], - ['core', 'installedat'], - ['core', 'lastupdatedat'], - ) + $this->appConfig + ->expects($this->exactly(2)) + ->method('getValueInt') + ->with('core', 'lastupdatedat') ->willReturnOnConsecutiveCalls( - '0', - 'installedat', - 'installedat', - 'lastupdatedat', + 0, + time(), ); $this->config + ->expects($this->exactly(2)) + ->method('getAppValue') + ->with('core', 'installedat') + ->willReturn('installedat'); + $this->config ->expects($this->once()) ->method('getSystemValueString') ->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/') ->willReturnArgument(1); + $this->appConfig + ->expects($this->once()) + ->method('setValueInt') + ->with('core', 'lastupdatedat', time()); $this->config - ->expects($this->exactly(2)) + ->expects($this->once()) ->method('setAppValue') - ->withConsecutive( - ['core', 'lastupdatedat', $this->isType('string')], - ['core', 'lastupdateResult', json_encode($expectedResult)] - ); + ->with('core', 'lastupdateResult', json_encode($expectedResult)); $updateXml = '<?xml version="1.0"?> <owncloud> @@ -171,33 +176,32 @@ class VersionCheckTest extends \Test\TestCase { ->method('getSystemValueBool') ->with('has_internet_connection', true) ->willReturn(true); - $this->config - ->expects($this->exactly(4)) - ->method('getAppValue') - ->withConsecutive( - ['core', 'lastupdatedat'], - ['core', 'installedat'], - ['core', 'installedat'], - ['core', 'lastupdatedat'], - ) + $this->appConfig + ->expects($this->exactly(2)) + ->method('getValueInt') + ->with('core', 'lastupdatedat') ->willReturnOnConsecutiveCalls( - '0', - 'installedat', - 'installedat', - 'lastupdatedat', + 0, + time(), ); $this->config + ->expects($this->exactly(2)) + ->method('getAppValue') + ->with('core', 'installedat') + ->willReturn('installedat'); + $this->config ->expects($this->once()) ->method('getSystemValueString') ->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/') ->willReturnArgument(1); + $this->appConfig + ->expects($this->once()) + ->method('setValueInt') + ->with('core', 'lastupdatedat', time()); $this->config - ->expects($this->exactly(2)) + ->expects($this->once()) ->method('setAppValue') - ->withConsecutive( - ['core', 'lastupdatedat', $this->isType('string')], - ['core', 'lastupdateResult', '[]'] - ); + ->with('core', 'lastupdateResult', $this->isType('string')); $updateXml = 'Invalid XML Response!'; $this->updater @@ -225,33 +229,32 @@ class VersionCheckTest extends \Test\TestCase { ->method('getSystemValueBool') ->with('has_internet_connection', true) ->willReturn(true); - $this->config - ->expects($this->exactly(4)) - ->method('getAppValue') - ->withConsecutive( - ['core', 'lastupdatedat'], - ['core', 'installedat'], - ['core', 'installedat'], - ['core', 'lastupdatedat'], - ) + $this->appConfig + ->expects($this->exactly(2)) + ->method('getValueInt') + ->with('core', 'lastupdatedat') ->willReturnOnConsecutiveCalls( - '0', - 'installedat', - 'installedat', - 'lastupdatedat', + 0, + time(), ); $this->config + ->expects($this->exactly(2)) + ->method('getAppValue') + ->with('core', 'installedat') + ->willReturn('installedat'); + $this->config ->expects($this->once()) ->method('getSystemValueString') ->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/') ->willReturnArgument(1); + $this->appConfig + ->expects($this->once()) + ->method('setValueInt') + ->with('core', 'lastupdatedat', time()); $this->config - ->expects($this->exactly(2)) + ->expects($this->once()) ->method('setAppValue') - ->withConsecutive( - ['core', 'lastupdatedat', $this->isType('string')], - ['core', 'lastupdateResult', $this->isType('string')] - ); + ->with('core', 'lastupdateResult', $this->isType('string')); $updateXml = '<?xml version="1.0"?> <owncloud> @@ -278,33 +281,32 @@ class VersionCheckTest extends \Test\TestCase { ->method('getSystemValueBool') ->with('has_internet_connection', true) ->willReturn(true); - $this->config - ->expects($this->exactly(4)) - ->method('getAppValue') - ->withConsecutive( - ['core', 'lastupdatedat'], - ['core', 'installedat'], - ['core', 'installedat'], - ['core', 'lastupdatedat'], - ) + $this->appConfig + ->expects($this->exactly(2)) + ->method('getValueInt') + ->with('core', 'lastupdatedat') ->willReturnOnConsecutiveCalls( - '0', - 'installedat', - 'installedat', - 'lastupdatedat', + 0, + time(), ); $this->config + ->expects($this->exactly(2)) + ->method('getAppValue') + ->with('core', 'installedat') + ->willReturn('installedat'); + $this->config ->expects($this->once()) ->method('getSystemValueString') ->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/') ->willReturnArgument(1); + $this->appConfig + ->expects($this->once()) + ->method('setValueInt') + ->with('core', 'lastupdatedat', time()); $this->config - ->expects($this->exactly(2)) + ->expects($this->once()) ->method('setAppValue') - ->withConsecutive( - ['core', 'lastupdatedat', $this->isType('string')], - ['core', 'lastupdateResult', json_encode($expectedResult)] - ); + ->with('core', 'lastupdateResult', $this->isType('string')); $updateXml = ''; $this->updater @@ -332,33 +334,32 @@ class VersionCheckTest extends \Test\TestCase { ->method('getSystemValueBool') ->with('has_internet_connection', true) ->willReturn(true); - $this->config - ->expects($this->exactly(4)) - ->method('getAppValue') - ->withConsecutive( - ['core', 'lastupdatedat'], - ['core', 'installedat'], - ['core', 'installedat'], - ['core', 'lastupdatedat'], - ) + $this->appConfig + ->expects($this->exactly(2)) + ->method('getValueInt') + ->with('core', 'lastupdatedat') ->willReturnOnConsecutiveCalls( - '0', - 'installedat', - 'installedat', - 'lastupdatedat', + 0, + time(), ); $this->config + ->expects($this->exactly(2)) + ->method('getAppValue') + ->with('core', 'installedat') + ->willReturn('installedat'); + $this->config ->expects($this->once()) ->method('getSystemValueString') ->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/') ->willReturnArgument(1); + $this->appConfig + ->expects($this->once()) + ->method('setValueInt') + ->with('core', 'lastupdatedat', time()); $this->config - ->expects($this->exactly(2)) + ->expects($this->once()) ->method('setAppValue') - ->withConsecutive( - ['core', 'lastupdatedat', $this->isType('string')], - ['core', 'lastupdateResult', $this->isType('string')] - ); + ->with('core', 'lastupdateResult', $this->isType('string')); // missing autoupdater element should still not fail $updateXml = '<?xml version="1.0"?> diff --git a/tests/lib/UpdaterTest.php b/tests/lib/UpdaterTest.php index 02b2189cdcc..bff50de47e2 100644 --- a/tests/lib/UpdaterTest.php +++ b/tests/lib/UpdaterTest.php @@ -25,6 +25,7 @@ namespace Test; use OC\Installer; use OC\IntegrityCheck\Checker; use OC\Updater; +use OCP\IAppConfig; use OCP\IConfig; use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; @@ -32,6 +33,8 @@ use Psr\Log\LoggerInterface; class UpdaterTest extends TestCase { /** @var IConfig|MockObject */ private $config; + /** @var IAppConfig|MockObject */ + private $appConfig; /** @var LoggerInterface|MockObject */ private $logger; /** @var Updater */ @@ -46,6 +49,9 @@ class UpdaterTest extends TestCase { $this->config = $this->getMockBuilder(IConfig::class) ->disableOriginalConstructor() ->getMock(); + $this->appConfig = $this->getMockBuilder(IAppConfig::class) + ->disableOriginalConstructor() + ->getMock(); $this->logger = $this->getMockBuilder(LoggerInterface::class) ->disableOriginalConstructor() ->getMock(); @@ -58,6 +64,7 @@ class UpdaterTest extends TestCase { $this->updater = new Updater( $this->config, + $this->appConfig, $this->checker, $this->logger, $this->installer |