SCSSCacherTest.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 Julius Härtl <jus@bitgrid.net>
  4. *
  5. * @author Julius Härtl <jus@bitgrid.net>
  6. *
  7. * @license GNU AGPL version 3 or any later version
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as
  11. * published by the Free Software Foundation, either version 3 of the
  12. * License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. namespace Test\Template;
  24. use OC\AppConfig;
  25. use OC\Files\AppData\AppData;
  26. use OC\Files\AppData\Factory;
  27. use OC\Template\IconsCacher;
  28. use OC\Template\SCSSCacher;
  29. use OCA\Theming\ThemingDefaults;
  30. use OCP\AppFramework\Utility\ITimeFactory;
  31. use OCP\Files\IAppData;
  32. use OCP\Files\NotFoundException;
  33. use OCP\Files\SimpleFS\ISimpleFile;
  34. use OCP\Files\SimpleFS\ISimpleFolder;
  35. use OCP\ICache;
  36. use OCP\ICacheFactory;
  37. use OCP\IConfig;
  38. use OCP\ILogger;
  39. use OCP\IURLGenerator;
  40. class SCSSCacherTest extends \Test\TestCase {
  41. /** @var ILogger|\PHPUnit\Framework\MockObject\MockObject */
  42. protected $logger;
  43. /** @var IAppData|\PHPUnit\Framework\MockObject\MockObject */
  44. protected $appData;
  45. /** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */
  46. protected $urlGenerator;
  47. /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
  48. protected $config;
  49. /** @var ThemingDefaults|\PHPUnit\Framework\MockObject\MockObject */
  50. protected $themingDefaults;
  51. /** @var SCSSCacher */
  52. protected $scssCacher;
  53. /** @var ICache|\PHPUnit\Framework\MockObject\MockObject */
  54. protected $depsCache;
  55. /** @var ICacheFactory|\PHPUnit\Framework\MockObject\MockObject */
  56. protected $cacheFactory;
  57. /** @var IconsCacher|\PHPUnit\Framework\MockObject\MockObject */
  58. protected $iconsCacher;
  59. /** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */
  60. protected $timeFactory;
  61. /** @var AppConfig|\PHPUnit\Framework\MockObject\MockObject */
  62. protected $appConfig;
  63. protected function setUp(): void {
  64. parent::setUp();
  65. $this->logger = $this->createMock(ILogger::class);
  66. $this->appData = $this->createMock(AppData::class);
  67. $this->iconsCacher = $this->createMock(IconsCacher::class);
  68. $this->timeFactory = $this->createMock(ITimeFactory::class);
  69. /** @var Factory|\PHPUnit\Framework\MockObject\MockObject $factory */
  70. $factory = $this->createMock(Factory::class);
  71. $factory->method('get')->with('css')->willReturn($this->appData);
  72. $this->urlGenerator = $this->createMock(IURLGenerator::class);
  73. $this->urlGenerator->expects($this->any())
  74. ->method('getBaseUrl')
  75. ->willReturn('http://localhost/nextcloud');
  76. $this->config = $this->createMock(IConfig::class);
  77. $this->config->expects($this->any())
  78. ->method('getAppValue')
  79. ->will($this->returnCallback(function ($appId, $configKey, $defaultValue) {
  80. return $defaultValue;
  81. }));
  82. $this->cacheFactory = $this->createMock(ICacheFactory::class);
  83. $this->depsCache = $this->createMock(ICache::class);
  84. $this->cacheFactory->expects($this->at(0))
  85. ->method('createDistributed')
  86. ->willReturn($this->depsCache);
  87. $this->themingDefaults = $this->createMock(ThemingDefaults::class);
  88. $this->themingDefaults->expects($this->any())->method('getScssVariables')->willReturn([]);
  89. $iconsFile = $this->createMock(ISimpleFile::class);
  90. $this->iconsCacher->expects($this->any())
  91. ->method('getCachedCSS')
  92. ->willReturn($iconsFile);
  93. $this->appConfig = $this->createMock(AppConfig::class);
  94. $this->scssCacher = new SCSSCacher(
  95. $this->logger,
  96. $factory,
  97. $this->urlGenerator,
  98. $this->config,
  99. $this->themingDefaults,
  100. \OC::$SERVERROOT,
  101. $this->cacheFactory,
  102. $this->iconsCacher,
  103. $this->timeFactory,
  104. $this->appConfig
  105. );
  106. }
  107. public function testProcessUncachedFileNoAppDataFolder() {
  108. $folder = $this->createMock(ISimpleFolder::class);
  109. $file = $this->createMock(ISimpleFile::class);
  110. $file->expects($this->any())->method('getSize')->willReturn(1);
  111. $this->appData->expects($this->once())->method('getFolder')->with('core')->willThrowException(new NotFoundException());
  112. $this->appData->expects($this->once())->method('newFolder')->with('core')->willReturn($folder);
  113. $this->appData->method('getDirectoryListing')->willReturn([]);
  114. $fileDeps = $this->createMock(ISimpleFile::class);
  115. $gzfile = $this->createMock(ISimpleFile::class);
  116. $filePrefix = substr(md5(\OC_Util::getVersionString('core')), 0, 4) . '-' .
  117. substr(md5('http://localhost/nextcloud/index.php'), 0, 4) . '-';
  118. $folder->method('getFile')
  119. ->willReturnCallback(function ($path) use ($file, $gzfile, $filePrefix) {
  120. if ($path === $filePrefix.'styles.css') {
  121. return $file;
  122. } elseif ($path === $filePrefix.'styles.css.deps') {
  123. throw new NotFoundException();
  124. } elseif ($path === $filePrefix.'styles.css.gzip') {
  125. return $gzfile;
  126. } else {
  127. $this->fail();
  128. }
  129. });
  130. $folder->expects($this->once())
  131. ->method('newFile')
  132. ->with($filePrefix.'styles.css.deps')
  133. ->willReturn($fileDeps);
  134. $this->urlGenerator->expects($this->once())
  135. ->method('getBaseUrl')
  136. ->willReturn('http://localhost/nextcloud');
  137. $this->iconsCacher->expects($this->any())
  138. ->method('setIconsCss')
  139. ->willReturn('scss {}');
  140. $actual = $this->scssCacher->process(\OC::$SERVERROOT, '/core/css/styles.scss', 'core');
  141. $this->assertTrue($actual);
  142. }
  143. public function testProcessUncachedFile() {
  144. $folder = $this->createMock(ISimpleFolder::class);
  145. $this->appData->expects($this->once())->method('getFolder')->with('core')->willReturn($folder);
  146. $this->appData->method('getDirectoryListing')->willReturn([]);
  147. $file = $this->createMock(ISimpleFile::class);
  148. $file->expects($this->any())->method('getSize')->willReturn(1);
  149. $fileDeps = $this->createMock(ISimpleFile::class);
  150. $gzfile = $this->createMock(ISimpleFile::class);
  151. $filePrefix = substr(md5(\OC_Util::getVersionString('core')), 0, 4) . '-' .
  152. substr(md5('http://localhost/nextcloud/index.php'), 0, 4) . '-';
  153. $folder->method('getFile')
  154. ->willReturnCallback(function ($path) use ($file, $gzfile, $filePrefix) {
  155. if ($path === $filePrefix.'styles.css') {
  156. return $file;
  157. } elseif ($path === $filePrefix.'styles.css.deps') {
  158. throw new NotFoundException();
  159. } elseif ($path === $filePrefix.'styles.css.gzip') {
  160. return $gzfile;
  161. } else {
  162. $this->fail();
  163. }
  164. });
  165. $folder->expects($this->once())
  166. ->method('newFile')
  167. ->with($filePrefix.'styles.css.deps')
  168. ->willReturn($fileDeps);
  169. $this->iconsCacher->expects($this->any())
  170. ->method('setIconsCss')
  171. ->willReturn('scss {}');
  172. $actual = $this->scssCacher->process(\OC::$SERVERROOT, '/core/css/styles.scss', 'core');
  173. $this->assertTrue($actual);
  174. }
  175. public function testProcessCachedFile() {
  176. $folder = $this->createMock(ISimpleFolder::class);
  177. $this->appData->expects($this->once())->method('getFolder')->with('core')->willReturn($folder);
  178. $this->appData->method('getDirectoryListing')->willReturn([]);
  179. $file = $this->createMock(ISimpleFile::class);
  180. $fileDeps = $this->createMock(ISimpleFile::class);
  181. $fileDeps->expects($this->any())->method('getSize')->willReturn(1);
  182. $gzFile = $this->createMock(ISimpleFile::class);
  183. $filePrefix = substr(md5(\OC_Util::getVersionString('core')), 0, 4) . '-' .
  184. substr(md5('http://localhost/nextcloud/index.php'), 0, 4) . '-';
  185. $folder->method('getFile')
  186. ->willReturnCallback(function ($name) use ($file, $fileDeps, $gzFile, $filePrefix) {
  187. if ($name === $filePrefix.'styles.css') {
  188. return $file;
  189. } elseif ($name === $filePrefix.'styles.css.deps') {
  190. return $fileDeps;
  191. } elseif ($name === $filePrefix.'styles.css.gzip') {
  192. return $gzFile;
  193. }
  194. $this->fail();
  195. });
  196. $this->iconsCacher->expects($this->any())
  197. ->method('setIconsCss')
  198. ->willReturn('scss {}');
  199. $actual = $this->scssCacher->process(\OC::$SERVERROOT, '/core/css/styles.scss', 'core');
  200. $this->assertTrue($actual);
  201. }
  202. public function testProcessCachedFileMemcache() {
  203. $folder = $this->createMock(ISimpleFolder::class);
  204. $this->appData->expects($this->once())
  205. ->method('getFolder')
  206. ->with('core')
  207. ->willReturn($folder);
  208. $folder->method('getName')
  209. ->willReturn('core');
  210. $this->appData->method('getDirectoryListing')->willReturn([]);
  211. $file = $this->createMock(ISimpleFile::class);
  212. $fileDeps = $this->createMock(ISimpleFile::class);
  213. $fileDeps->expects($this->any())->method('getSize')->willReturn(1);
  214. $gzFile = $this->createMock(ISimpleFile::class);
  215. $filePrefix = substr(md5(\OC_Util::getVersionString('core')), 0, 4) . '-' .
  216. substr(md5('http://localhost/nextcloud/index.php'), 0, 4) . '-';
  217. $folder->method('getFile')
  218. ->willReturnCallback(function ($name) use ($file, $fileDeps, $gzFile, $filePrefix) {
  219. if ($name === $filePrefix.'styles.css') {
  220. return $file;
  221. } elseif ($name === $filePrefix.'styles.css.deps') {
  222. return $fileDeps;
  223. } elseif ($name === $filePrefix.'styles.css.gzip') {
  224. return $gzFile;
  225. }
  226. $this->fail();
  227. });
  228. $this->iconsCacher->expects($this->any())
  229. ->method('setIconsCss')
  230. ->willReturn('scss {}');
  231. $actual = $this->scssCacher->process(\OC::$SERVERROOT, '/core/css/styles.scss', 'core');
  232. $this->assertTrue($actual);
  233. }
  234. public function testIsCachedNoFile() {
  235. $fileNameCSS = "styles.css";
  236. $folder = $this->createMock(ISimpleFolder::class);
  237. $folder->expects($this->at(0))->method('getFile')->with($fileNameCSS)->willThrowException(new NotFoundException());
  238. $this->appData->expects($this->any())
  239. ->method('getFolder')
  240. ->willReturn($folder);
  241. $actual = self::invokePrivate($this->scssCacher, 'isCached', [$fileNameCSS, 'core']);
  242. $this->assertFalse($actual);
  243. }
  244. public function testIsCachedNoDepsFile() {
  245. $fileNameCSS = "styles.css";
  246. $folder = $this->createMock(ISimpleFolder::class);
  247. $file = $this->createMock(ISimpleFile::class);
  248. $file->expects($this->once())->method('getSize')->willReturn(1);
  249. $folder->method('getFile')
  250. ->willReturnCallback(function ($path) use ($file) {
  251. if ($path === 'styles.css') {
  252. return $file;
  253. } elseif ($path === 'styles.css.deps') {
  254. throw new NotFoundException();
  255. } else {
  256. $this->fail();
  257. }
  258. });
  259. $this->appData->expects($this->any())
  260. ->method('getFolder')
  261. ->willReturn($folder);
  262. $actual = self::invokePrivate($this->scssCacher, 'isCached', [$fileNameCSS, 'core']);
  263. $this->assertFalse($actual);
  264. }
  265. public function testCacheNoFile() {
  266. $fileNameCSS = "styles.css";
  267. $fileNameSCSS = "styles.scss";
  268. $folder = $this->createMock(ISimpleFolder::class);
  269. $file = $this->createMock(ISimpleFile::class);
  270. $depsFile = $this->createMock(ISimpleFile::class);
  271. $gzipFile = $this->createMock(ISimpleFile::class);
  272. $webDir = "core/css";
  273. $path = \OC::$SERVERROOT . '/core/css/';
  274. $folder->method('getFile')->willThrowException(new NotFoundException());
  275. $folder->method('newFile')->willReturnCallback(function ($fileName) use ($file, $depsFile, $gzipFile) {
  276. if ($fileName === 'styles.css') {
  277. return $file;
  278. } elseif ($fileName === 'styles.css.deps') {
  279. return $depsFile;
  280. } elseif ($fileName === 'styles.css.gzip') {
  281. return $gzipFile;
  282. }
  283. throw new \Exception();
  284. });
  285. $this->iconsCacher->expects($this->any())
  286. ->method('setIconsCss')
  287. ->willReturn('scss {}');
  288. $file->expects($this->once())->method('putContent');
  289. $depsFile->expects($this->once())->method('putContent');
  290. $gzipFile->expects($this->once())->method('putContent');
  291. $actual = self::invokePrivate($this->scssCacher, 'cache', [$path, $fileNameCSS, $fileNameSCSS, $folder, $webDir]);
  292. $this->assertTrue($actual);
  293. }
  294. public function testCache() {
  295. $fileNameCSS = "styles.css";
  296. $fileNameSCSS = "styles.scss";
  297. $folder = $this->createMock(ISimpleFolder::class);
  298. $file = $this->createMock(ISimpleFile::class);
  299. $depsFile = $this->createMock(ISimpleFile::class);
  300. $gzipFile = $this->createMock(ISimpleFile::class);
  301. $webDir = "core/css";
  302. $path = \OC::$SERVERROOT;
  303. $folder->method('getFile')->willReturnCallback(function ($fileName) use ($file, $depsFile, $gzipFile) {
  304. if ($fileName === 'styles.css') {
  305. return $file;
  306. } elseif ($fileName === 'styles.css.deps') {
  307. return $depsFile;
  308. } elseif ($fileName === 'styles.css.gzip') {
  309. return $gzipFile;
  310. }
  311. throw new \Exception();
  312. });
  313. $file->expects($this->once())->method('putContent');
  314. $depsFile->expects($this->once())->method('putContent');
  315. $gzipFile->expects($this->once())->method('putContent');
  316. $this->iconsCacher->expects($this->any())
  317. ->method('setIconsCss')
  318. ->willReturn('scss {}');
  319. $actual = self::invokePrivate($this->scssCacher, 'cache', [$path, $fileNameCSS, $fileNameSCSS, $folder, $webDir]);
  320. $this->assertTrue($actual);
  321. }
  322. public function testCacheSuccess() {
  323. $fileNameCSS = "styles-success.css";
  324. $fileNameSCSS = "../../tests/data/scss/styles-success.scss";
  325. $folder = $this->createMock(ISimpleFolder::class);
  326. $file = $this->createMock(ISimpleFile::class);
  327. $depsFile = $this->createMock(ISimpleFile::class);
  328. $gzipFile = $this->createMock(ISimpleFile::class);
  329. $webDir = "tests/data/scss";
  330. $path = \OC::$SERVERROOT . $webDir;
  331. $folder->method('getFile')->willReturnCallback(function ($fileName) use ($file, $depsFile, $gzipFile) {
  332. if ($fileName === 'styles-success.css') {
  333. return $file;
  334. } elseif ($fileName === 'styles-success.css.deps') {
  335. return $depsFile;
  336. } elseif ($fileName === 'styles-success.css.gzip') {
  337. return $gzipFile;
  338. }
  339. throw new \Exception();
  340. });
  341. $this->iconsCacher->expects($this->at(0))
  342. ->method('setIconsCss')
  343. ->willReturn('body{background-color:#0082c9}');
  344. $file->expects($this->at(0))->method('putContent')->with($this->callback(
  345. function ($content) {
  346. return 'body{background-color:#0082c9}' === $content;
  347. }));
  348. $depsFile->expects($this->at(0))->method('putContent')->with($this->callback(
  349. function ($content) {
  350. $deps = json_decode($content, true);
  351. return array_key_exists(\OC::$SERVERROOT . '/core/css/variables.scss', $deps)
  352. && array_key_exists(\OC::$SERVERROOT . '/tests/data/scss/styles-success.scss', $deps);
  353. }));
  354. $gzipFile->expects($this->at(0))->method('putContent')->with($this->callback(
  355. function ($content) {
  356. return gzdecode($content) === 'body{background-color:#0082c9}';
  357. }
  358. ));
  359. $actual = self::invokePrivate($this->scssCacher, 'cache', [$path, $fileNameCSS, $fileNameSCSS, $folder, $webDir]);
  360. $this->assertTrue($actual);
  361. }
  362. public function testCacheFailure() {
  363. $fileNameCSS = "styles-error.css";
  364. $fileNameSCSS = "../../tests/data/scss/styles-error.scss";
  365. $folder = $this->createMock(ISimpleFolder::class);
  366. $file = $this->createMock(ISimpleFile::class);
  367. $depsFile = $this->createMock(ISimpleFile::class);
  368. $webDir = "/tests/data/scss";
  369. $path = \OC::$SERVERROOT . $webDir;
  370. $folder->expects($this->at(0))->method('getFile')->with($fileNameCSS)->willReturn($file);
  371. $folder->expects($this->at(1))->method('getFile')->with($fileNameCSS . '.deps')->willReturn($depsFile);
  372. $actual = self::invokePrivate($this->scssCacher, 'cache', [$path, $fileNameCSS, $fileNameSCSS, $folder, $webDir]);
  373. $this->assertFalse($actual);
  374. }
  375. public function dataRebaseUrls() {
  376. return [
  377. ['#id { background-image: url(\'../img/image.jpg\'); }','#id { background-image: url(\'/apps/files/css/../img/image.jpg\'); }'],
  378. ['#id { background-image: url("../img/image.jpg"); }','#id { background-image: url(\'/apps/files/css/../img/image.jpg\'); }'],
  379. ['#id { background-image: url(\'/img/image.jpg\'); }','#id { background-image: url(\'/img/image.jpg\'); }'],
  380. ['#id { background-image: url("http://example.com/test.jpg"); }','#id { background-image: url("http://example.com/test.jpg"); }'],
  381. ];
  382. }
  383. /**
  384. * @dataProvider dataRebaseUrls
  385. */
  386. public function testRebaseUrls($scss, $expected) {
  387. $webDir = '/apps/files/css';
  388. $actual = self::invokePrivate($this->scssCacher, 'rebaseUrls', [$scss, $webDir]);
  389. $this->assertEquals($expected, $actual);
  390. }
  391. public function dataGetCachedSCSS() {
  392. return [
  393. ['core', 'core/css/styles.scss', '/css/core/styles.css', \OC_Util::getVersionString()],
  394. ['files', 'apps/files/css/styles.scss', '/css/files/styles.css', \OC_App::getAppVersion('files')]
  395. ];
  396. }
  397. /**
  398. * @param $appName
  399. * @param $fileName
  400. * @param $result
  401. * @dataProvider dataGetCachedSCSS
  402. */
  403. public function testGetCachedSCSS($appName, $fileName, $result, $version) {
  404. $this->urlGenerator->expects($this->once())
  405. ->method('linkToRoute')
  406. ->with('core.Css.getCss', [
  407. 'fileName' => substr(md5($version), 0, 4) . '-' .
  408. substr(md5('http://localhost/nextcloud/index.php'), 0, 4) . '-styles.css',
  409. 'appName' => $appName,
  410. 'v' => 0,
  411. ])
  412. ->willReturn(\OC::$WEBROOT . $result);
  413. $actual = $this->scssCacher->getCachedSCSS($appName, $fileName);
  414. $this->assertEquals(substr($result, 1), $actual);
  415. }
  416. private function randomString() {
  417. return sha1(uniqid(mt_rand(), true));
  418. }
  419. private function rrmdir($directory) {
  420. $files = array_diff(scandir($directory), ['.','..']);
  421. foreach ($files as $file) {
  422. if (is_dir($directory . '/' . $file)) {
  423. $this->rrmdir($directory . '/' . $file);
  424. } else {
  425. unlink($directory . '/' . $file);
  426. }
  427. }
  428. return rmdir($directory);
  429. }
  430. public function dataGetWebDir() {
  431. return [
  432. // Root installation
  433. ['/http/core/css', 'core', '', '/http', '/core/css'],
  434. ['/http/apps/scss/css', 'scss', '', '/http', '/apps/scss/css'],
  435. ['/srv/apps2/scss/css', 'scss', '', '/http', '/apps2/scss/css'],
  436. // Sub directory install
  437. ['/http/nextcloud/core/css', 'core', '/nextcloud', '/http/nextcloud', '/nextcloud/core/css'],
  438. ['/http/nextcloud/apps/scss/css', 'scss', '/nextcloud', '/http/nextcloud', '/nextcloud/apps/scss/css'],
  439. ['/srv/apps2/scss/css', 'scss', '/nextcloud', '/http/nextcloud', '/apps2/scss/css']
  440. ];
  441. }
  442. /**
  443. * @param $path
  444. * @param $appName
  445. * @param $webRoot
  446. * @param $serverRoot
  447. * @dataProvider dataGetWebDir
  448. */
  449. public function testgetWebDir($path, $appName, $webRoot, $serverRoot, $correctWebDir) {
  450. $tmpDir = sys_get_temp_dir().'/'.$this->randomString();
  451. // Adding fake apps folder and create fake app install
  452. \OC::$APPSROOTS[] = [
  453. 'path' => $tmpDir.'/srv/apps2',
  454. 'url' => '/apps2',
  455. 'writable' => false
  456. ];
  457. mkdir($tmpDir.$path, 0777, true);
  458. $actual = self::invokePrivate($this->scssCacher, 'getWebDir', [$tmpDir.$path, $appName, $tmpDir.$serverRoot, $webRoot]);
  459. $this->assertEquals($correctWebDir, $actual);
  460. array_pop(\OC::$APPSROOTS);
  461. $this->rrmdir($tmpDir.$path);
  462. }
  463. public function testResetCache() {
  464. $file = $this->createMock(ISimpleFile::class);
  465. $file->expects($this->once())
  466. ->method('delete');
  467. $folder = $this->createMock(ISimpleFolder::class);
  468. $folder->expects($this->once())
  469. ->method('getDirectoryListing')
  470. ->willReturn([$file]);
  471. $cache = $this->createMock(ICache::class);
  472. $this->cacheFactory->expects($this->exactly(2))
  473. ->method('createDistributed')
  474. ->willReturn($cache);
  475. $cache->expects($this->exactly(2))
  476. ->method('clear')
  477. ->with('');
  478. $this->appData->expects($this->once())
  479. ->method('getDirectoryListing')
  480. ->willReturn([$folder]);
  481. $this->scssCacher->resetCache();
  482. }
  483. }