]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix unit tests and improve appstore logic 3287/head
authorMorris Jobke <hey@morrisjobke.de>
Thu, 23 Feb 2017 20:56:28 +0000 (14:56 -0600)
committerJoas Schilling <coding@schilljs.com>
Fri, 24 Feb 2017 07:34:14 +0000 (08:34 +0100)
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
lib/private/App/AppStore/Fetcher/Fetcher.php
tests/lib/App/AppStore/Fetcher/AppFetcherTest.php
tests/lib/App/AppStore/Fetcher/CategoryFetcherTest.php
tests/lib/App/AppStore/Fetcher/FetcherBase.php

index 7f38e72be2ddb6bea18ec3a97f057694aa3e43e9..ab0e299f0a27afb0c57c302b3d8f483fa9134b54 100644 (file)
@@ -69,9 +69,7 @@ abstract class Fetcher {
         * @return array
         */
        protected function fetch($ETag, $content) {
-
-               $systemConfig = \OC::$server->getSystemConfig();
-               $appstoreenabled = $systemConfig->getValue('appstoreenabled', true);
+               $appstoreenabled = $this->config->getSystemValue('appstoreenabled', true);
 
                if (!$appstoreenabled) {
                        return [];
@@ -111,8 +109,7 @@ abstract class Fetcher {
         * @return array
         */
        public function get() {
-               $systemConfig = \OC::$server->getSystemConfig();
-               $appstoreenabled = $systemConfig->getValue('appstoreenabled', true);
+               $appstoreenabled = $this->config->getSystemValue('appstoreenabled', true);
 
                if (!$appstoreenabled) {
                        return [];
index 9d09898bb95c9b15c039153f28531ad2eb5766bf..4a5222fa915e4f2d8df665f2d5abad6578a97427 100644 (file)
@@ -59,11 +59,10 @@ EOD;
                $this->config = $this->createMock(IConfig::class);
 
                $this->config
-                       ->expects($this->atLeastOnce())
+                       ->expects($this->at(0))
                        ->method('getSystemValue')
                        ->with('version')
                        ->willReturn('11.0.0.2');
-
                $this->fetcher = new AppFetcher(
                        $this->appData,
                        $this->clientService,
@@ -73,6 +72,27 @@ EOD;
        }
 
        public function testGetWithFilter() {
+               $this->config
+                       ->expects($this->at(0))
+                       ->method('getSystemValue')
+                       ->with('appstoreenabled', true)
+                       ->willReturn(true);
+               $this->config
+                       ->expects($this->at(1))
+                       ->method('getSystemValue')
+                       ->with('appstoreenabled', true)
+                       ->willReturn(true);
+               $this->config
+                       ->expects($this->at(2))
+                       ->method('getSystemValue')
+                       ->with('version')
+                       ->willReturn('11.0.0.2');
+               $this->config
+                       ->expects($this->at(3))
+                       ->method('getSystemValue')
+                       ->with('version')
+                       ->willReturn('11.0.0.2');
+
                $file = $this->createMock(ISimpleFile::class);
                $folder = $this->createMock(ISimpleFolder::class);
                $folder
@@ -1920,4 +1940,17 @@ EJL3BaQAQaASSsvFrcozYxrQG4VzEg==
 
                $this->assertEquals($expected['data'], $this->fetcher->get());
        }
+
+       public function testAppstoreDisabled() {
+               $this->config
+                       ->expects($this->once())
+                       ->method('getSystemValue')
+                       ->with('appstoreenabled', true)
+                       ->willReturn(false);
+               $this->appData
+                       ->expects($this->never())
+                       ->method('getFolder');
+
+               $this->assertEquals([], $this->fetcher->get());
+       }
 }
index 9955715bca421348b2a9f70b0faa817a34b9b1c3..27f33bed99729683858bbbf117a853aa5507f3a2 100644 (file)
@@ -36,4 +36,18 @@ class CategoryFetcherTest extends FetcherBase  {
                        $this->config
                );
        }
+
+       public function testAppstoreDisabled() {
+               $this->config
+                       ->expects($this->once())
+                       ->method('getSystemValue')
+                       ->with('appstoreenabled', true)
+                       ->willReturn(false);
+               $this->appData
+                       ->expects($this->never())
+                       ->method('getFolder');
+
+               $this->assertEquals([], $this->fetcher->get());
+
+       }
 }
index 73fcbbaab6f55220c1736f9bb0d3bafbfa42ab65..1cec52700004d19c8a7856ee7c64c7900e3887ea 100644 (file)
@@ -55,16 +55,22 @@ abstract class FetcherBase extends TestCase {
                $this->clientService = $this->createMock(IClientService::class);
                $this->timeFactory = $this->createMock(ITimeFactory::class);
                $this->config = $this->createMock(IConfig::class);
+       }
 
+       public function testGetWithAlreadyExistingFileAndUpToDateTimestampAndVersion() {
                $this->config
+                       ->expects($this->at(0))
+                       ->method('getSystemValue')
+                       ->with('appstoreenabled', true)
+                       ->willReturn(true);
+               $this->config
+                       ->expects($this->at(1))
                        ->method('getSystemValue')
                        ->with(
                                $this->equalTo('version'),
                                $this->anything()
                        )->willReturn('11.0.0.2');
-       }
 
-       public function testGetWithAlreadyExistingFileAndUpToDateTimestampAndVersion() {
                $folder = $this->createMock(ISimpleFolder::class);
                $file = $this->createMock(ISimpleFile::class);
                $this->appData
@@ -95,6 +101,24 @@ abstract class FetcherBase extends TestCase {
        }
 
        public function testGetWithNotExistingFileAndUpToDateTimestampAndVersion() {
+               $this->config
+                       ->expects($this->at(0))
+                       ->method('getSystemValue')
+                       ->with('appstoreenabled', true)
+                       ->willReturn(true);
+               $this->config
+                       ->expects($this->at(1))
+                       ->method('getSystemValue')
+                       ->with('appstoreenabled', true)
+                       ->willReturn(true);
+               $this->config
+                       ->expects($this->at(2))
+                       ->method('getSystemValue')
+                       ->with(
+                               $this->equalTo('version'),
+                               $this->anything()
+                       )->willReturn('11.0.0.2');
+
                $folder = $this->createMock(ISimpleFolder::class);
                $file = $this->createMock(ISimpleFile::class);
                $this->appData
@@ -157,6 +181,24 @@ abstract class FetcherBase extends TestCase {
        }
 
        public function testGetWithAlreadyExistingFileAndOutdatedTimestamp() {
+               $this->config
+                       ->expects($this->at(0))
+                       ->method('getSystemValue')
+                       ->with('appstoreenabled', true)
+                       ->willReturn(true);
+               $this->config
+                       ->expects($this->at(1))
+                       ->method('getSystemValue')
+                       ->with('appstoreenabled', true)
+                       ->willReturn(true);
+               $this->config
+                       ->expects($this->at(2))
+                       ->method('getSystemValue')
+                       ->with(
+                               $this->equalTo('version'),
+                               $this->anything()
+                       )->willReturn('11.0.0.2');
+
                $folder = $this->createMock(ISimpleFolder::class);
                $file = $this->createMock(ISimpleFile::class);
                $this->appData
@@ -222,6 +264,24 @@ abstract class FetcherBase extends TestCase {
        }
 
        public function testGetWithAlreadyExistingFileAndNoVersion() {
+               $this->config
+                       ->expects($this->at(0))
+                       ->method('getSystemValue')
+                       ->with('appstoreenabled', true)
+                       ->willReturn(true);
+               $this->config
+                       ->expects($this->at(1))
+                       ->method('getSystemValue')
+                       ->with('appstoreenabled', true)
+                       ->willReturn(true);
+               $this->config
+                       ->expects($this->at(2))
+                       ->method('getSystemValue')
+                       ->with(
+                               $this->equalTo('version'),
+                               $this->anything()
+                       )->willReturn('11.0.0.2');
+
                $folder = $this->createMock(ISimpleFolder::class);
                $file = $this->createMock(ISimpleFile::class);
                $this->appData
@@ -283,6 +343,24 @@ abstract class FetcherBase extends TestCase {
        }
 
        public function testGetWithAlreadyExistingFileAndOutdatedVersion() {
+               $this->config
+                       ->expects($this->at(0))
+                       ->method('getSystemValue')
+                       ->with('appstoreenabled', true)
+                       ->willReturn(true);
+               $this->config
+                       ->expects($this->at(1))
+                       ->method('getSystemValue')
+                       ->with('appstoreenabled', true)
+                       ->willReturn(true);
+               $this->config
+                       ->expects($this->at(2))
+                       ->method('getSystemValue')
+                       ->with(
+                               $this->equalTo('version'),
+                               $this->anything()
+                       )->willReturn('11.0.0.2');
+
                $folder = $this->createMock(ISimpleFolder::class);
                $file = $this->createMock(ISimpleFile::class);
                $this->appData
@@ -343,6 +421,17 @@ abstract class FetcherBase extends TestCase {
        }
 
        public function testGetWithExceptionInClient() {
+               $this->config
+                       ->expects($this->at(0))
+                       ->method('getSystemValue')
+                       ->with('appstoreenabled', true)
+                       ->willReturn(true);
+               $this->config
+                       ->expects($this->at(1))
+                       ->method('getSystemValue')
+                       ->with('appstoreenabled', true)
+                       ->willReturn(true);
+
                $folder = $this->createMock(ISimpleFolder::class);
                $file = $this->createMock(ISimpleFile::class);
                $this->appData
@@ -378,6 +467,24 @@ abstract class FetcherBase extends TestCase {
        }
 
        public function testGetMatchingETag() {
+               $this->config
+                       ->expects($this->at(0))
+                       ->method('getSystemValue')
+                       ->with('appstoreenabled', true)
+                       ->willReturn(true);
+               $this->config
+                       ->expects($this->at(1))
+                       ->method('getSystemValue')
+                       ->with('appstoreenabled', true)
+                       ->willReturn(true);
+               $this->config
+                       ->expects($this->at(2))
+                       ->method('getSystemValue')
+                       ->with(
+                               $this->equalTo('version'),
+                               $this->anything()
+                       )->willReturn('11.0.0.2');
+
                $folder = $this->createMock(ISimpleFolder::class);
                $file = $this->createMock(ISimpleFile::class);
                $this->appData
@@ -447,6 +554,24 @@ abstract class FetcherBase extends TestCase {
        }
 
        public function testGetNoMatchingETag() {
+               $this->config
+                       ->expects($this->at(0))
+                       ->method('getSystemValue')
+                       ->with('appstoreenabled', true)
+                       ->willReturn(true);
+               $this->config
+                       ->expects($this->at(1))
+                       ->method('getSystemValue')
+                       ->with('appstoreenabled', true)
+                       ->willReturn(true);
+               $this->config
+                       ->expects($this->at(2))
+                       ->method('getSystemValue')
+                       ->with(
+                               $this->equalTo('version'),
+                               $this->anything()
+                       )->willReturn('11.0.0.2');
+
                $folder = $this->createMock(ISimpleFolder::class);
                $file = $this->createMock(ISimpleFile::class);
                $this->appData