diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2018-02-07 09:02:37 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-07 09:02:37 +0100 |
commit | 7486d021b106de0660866f18317fc4d5ed7f17fc (patch) | |
tree | 61b12e230f6acc7c2e2f4937a2b95495580b33f9 /tests | |
parent | 1ec43c8265a03c34bd2fe85fc0ae20cf192500b7 (diff) | |
parent | b837d3f33277880923a169a984c460ea970e031b (diff) | |
download | nextcloud-server-7486d021b106de0660866f18317fc4d5ed7f17fc.tar.gz nextcloud-server-7486d021b106de0660866f18317fc4d5ed7f17fc.zip |
Merge pull request #8197 from nextcloud/stable13-8144
[stable13] Repair step to clear frontend related caches
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/Repair/ClearFrontendCachesTest.php | 78 | ||||
-rw-r--r-- | tests/lib/Template/JSCombinerTest.php | 21 | ||||
-rw-r--r-- | tests/lib/Template/SCSSCacherTest.php | 25 |
3 files changed, 124 insertions, 0 deletions
diff --git a/tests/lib/Repair/ClearFrontendCachesTest.php b/tests/lib/Repair/ClearFrontendCachesTest.php new file mode 100644 index 00000000000..7c3a54cf1db --- /dev/null +++ b/tests/lib/Repair/ClearFrontendCachesTest.php @@ -0,0 +1,78 @@ +<?php +/** + * @copyright Copyright (c) 2018 Julius Härtl <jus@bitgrid.net> + * + * @author Julius Härtl <jus@bitgrid.net> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace Test\Repair; +use OC\Template\JSCombiner; +use OC\Template\SCSSCacher; +use OCP\ICache; +use OCP\ICacheFactory; +use OCP\Migration\IOutput; + +class ClearFrontendCachesTest extends \Test\TestCase { + + /** @var ICacheFactory */ + private $cacheFactory; + + /** @var SCSSCacher */ + private $scssCacher; + + /** @var JSCombiner */ + private $jsCombiner; + + /** @var \OC\Repair\ClearFrontendCaches */ + protected $repair; + + /** @var IOutput */ + private $outputMock; + + protected function setUp() { + parent::setUp(); + + $this->outputMock = $this->createMock(IOutput::class); + + $this->cacheFactory = $this->createMock(ICacheFactory::class); + $this->scssCacher = $this->createMock(SCSSCacher::class); + $this->jsCombiner = $this->createMock(JSCombiner::class); + + $this->repair = new \OC\Repair\ClearFrontendCaches($this->cacheFactory, $this->scssCacher, $this->jsCombiner); + } + + + public function testRun() { + $imagePathCache = $this->createMock(ICache::class); + $imagePathCache->expects($this->once()) + ->method('clear') + ->with(''); + $this->jsCombiner->expects($this->once()) + ->method('resetCache'); + $this->scssCacher->expects($this->once()) + ->method('resetCache'); + $this->cacheFactory->expects($this->at(0)) + ->method('createDistributed') + ->with('imagePath') + ->willReturn($imagePathCache); + + $this->repair->run($this->outputMock); + $this->assertTrue(true); + } +} diff --git a/tests/lib/Template/JSCombinerTest.php b/tests/lib/Template/JSCombinerTest.php index d6583d4a450..d5f7000e0a5 100644 --- a/tests/lib/Template/JSCombinerTest.php +++ b/tests/lib/Template/JSCombinerTest.php @@ -511,4 +511,25 @@ var b = \'world\'; $expected = []; $this->assertEquals($expected, $this->jsCombiner->getContent($pathInfo['dirname'], $pathInfo['basename'])); } + + public function testResetCache() { + $file = $this->createMock(ISimpleFile::class); + $file->expects($this->once()) + ->method('delete'); + + $folder = $this->createMock(ISimpleFolder::class); + $folder->expects($this->once()) + ->method('getDirectoryListing') + ->willReturn([$file]); + + $this->depsCache->expects($this->once()) + ->method('clear') + ->with(''); + $this->appData->expects($this->once()) + ->method('getDirectoryListing') + ->willReturn([$folder]); + + $this->jsCombiner->resetCache(); + } + } diff --git a/tests/lib/Template/SCSSCacherTest.php b/tests/lib/Template/SCSSCacherTest.php index 7b5300b99a9..dfaeb803578 100644 --- a/tests/lib/Template/SCSSCacherTest.php +++ b/tests/lib/Template/SCSSCacherTest.php @@ -85,6 +85,7 @@ class SCSSCacherTest extends \Test\TestCase { $this->appData->expects($this->once())->method('getFolder')->with('core')->willThrowException(new NotFoundException()); $this->appData->expects($this->once())->method('newFolder')->with('core')->willReturn($folder); + $this->appData->method('getDirectoryListing')->willReturn([]); $fileDeps = $this->createMock(ISimpleFile::class); $gzfile = $this->createMock(ISimpleFile::class); @@ -118,6 +119,7 @@ class SCSSCacherTest extends \Test\TestCase { public function testProcessUncachedFile() { $folder = $this->createMock(ISimpleFolder::class); $this->appData->expects($this->once())->method('getFolder')->with('core')->willReturn($folder); + $this->appData->method('getDirectoryListing')->willReturn([]); $file = $this->createMock(ISimpleFile::class); $file->expects($this->any())->method('getSize')->willReturn(1); $fileDeps = $this->createMock(ISimpleFile::class); @@ -148,6 +150,7 @@ class SCSSCacherTest extends \Test\TestCase { public function testProcessCachedFile() { $folder = $this->createMock(ISimpleFolder::class); $this->appData->expects($this->once())->method('getFolder')->with('core')->willReturn($folder); + $this->appData->method('getDirectoryListing')->willReturn([]); $file = $this->createMock(ISimpleFile::class); $fileDeps = $this->createMock(ISimpleFile::class); $fileDeps->expects($this->any())->method('getSize')->willReturn(1); @@ -178,6 +181,7 @@ class SCSSCacherTest extends \Test\TestCase { ->willReturn($folder); $folder->method('getName') ->willReturn('core'); + $this->appData->method('getDirectoryListing')->willReturn([]); $file = $this->createMock(ISimpleFile::class); @@ -445,4 +449,25 @@ class SCSSCacherTest extends \Test\TestCase { $this->rrmdir($tmpDir.$path); } + public function testResetCache() { + $file = $this->createMock(ISimpleFile::class); + $file->expects($this->once()) + ->method('delete'); + + $folder = $this->createMock(ISimpleFolder::class); + $folder->expects($this->once()) + ->method('getDirectoryListing') + ->willReturn([$file]); + + $this->depsCache->expects($this->once()) + ->method('clear') + ->with(''); + $this->appData->expects($this->once()) + ->method('getDirectoryListing') + ->willReturn([$folder]); + + $this->scssCacher->resetCache(); + } + + } |