SCSSCacherTest.php 19 KB

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