3535use OCP \IConfig ;
3636use OCP \ILogger ;
3737use OCP \IURLGenerator ;
38+ use OC_App ;
3839
3940class SCSSCacherTest extends \Test \TestCase {
4041 /** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */
@@ -58,17 +59,26 @@ protected function setUp() {
5859 parent ::setUp ();
5960 $ this ->logger = $ this ->createMock (ILogger::class);
6061 $ this ->appData = $ this ->createMock (IAppData::class);
62+
6163 /** @var Factory|\PHPUnit_Framework_MockObject_MockObject $factory */
6264 $ factory = $ this ->createMock (Factory::class);
6365 $ factory ->method ('get ' )->with ('css ' )->willReturn ($ this ->appData );
66+
6467 $ this ->urlGenerator = $ this ->createMock (IURLGenerator::class);
68+ $ this ->urlGenerator ->expects ($ this ->any ())
69+ ->method ('getBaseUrl ' )
70+ ->willReturn ('http://localhost/nextcloud ' );
71+
6572 $ this ->config = $ this ->createMock (IConfig::class);
6673 $ this ->cacheFactory = $ this ->createMock (ICacheFactory::class);
6774 $ this ->depsCache = $ this ->createMock (ICache::class);
6875 $ this ->cacheFactory ->expects ($ this ->at (0 ))
6976 ->method ('createDistributed ' )
7077 ->willReturn ($ this ->depsCache );
78+
7179 $ this ->themingDefaults = $ this ->createMock (ThemingDefaults::class);
80+ $ this ->themingDefaults ->expects ($ this ->any ())->method ('getScssVariables ' )->willReturn ([]);
81+
7282 $ this ->scssCacher = new SCSSCacher (
7383 $ this ->logger ,
7484 $ factory ,
@@ -78,11 +88,6 @@ protected function setUp() {
7888 \OC ::$ SERVERROOT ,
7989 $ this ->cacheFactory
8090 );
81- $ this ->themingDefaults ->expects ($ this ->any ())->method ('getScssVariables ' )->willReturn ([]);
82-
83- $ this ->urlGenerator ->expects ($ this ->any ())
84- ->method ('getBaseUrl ' )
85- ->willReturn ('http://localhost/nextcloud ' );
8691 }
8792
8893 public function testProcessUncachedFileNoAppDataFolder () {
@@ -96,7 +101,8 @@ public function testProcessUncachedFileNoAppDataFolder() {
96101
97102 $ fileDeps = $ this ->createMock (ISimpleFile::class);
98103 $ gzfile = $ this ->createMock (ISimpleFile::class);
99- $ filePrefix = substr (md5 ('http://localhost/nextcloud ' ), 0 , 8 ) . '- ' ;
104+ $ filePrefix = substr (md5 (\OC_Util::getVersionString ('core ' )), 0 , 4 ) . '- ' .
105+ substr (md5 ('http://localhost/nextcloud ' ), 0 , 4 ) . '- ' ;
100106
101107 $ folder ->method ('getFile ' )
102108 ->will ($ this ->returnCallback (function ($ path ) use ($ file , $ gzfile , $ filePrefix ) {
@@ -131,7 +137,8 @@ public function testProcessUncachedFile() {
131137 $ file ->expects ($ this ->any ())->method ('getSize ' )->willReturn (1 );
132138 $ fileDeps = $ this ->createMock (ISimpleFile::class);
133139 $ gzfile = $ this ->createMock (ISimpleFile::class);
134- $ filePrefix = substr (md5 ('http://localhost/nextcloud ' ), 0 , 8 ) . '- ' ;
140+ $ filePrefix = substr (md5 (\OC_Util::getVersionString ('core ' )), 0 , 4 ) . '- ' .
141+ substr (md5 ('http://localhost/nextcloud ' ), 0 , 4 ) . '- ' ;
135142
136143 $ folder ->method ('getFile ' )
137144 ->will ($ this ->returnCallback (function ($ path ) use ($ file , $ gzfile , $ filePrefix ) {
@@ -162,7 +169,8 @@ public function testProcessCachedFile() {
162169 $ fileDeps = $ this ->createMock (ISimpleFile::class);
163170 $ fileDeps ->expects ($ this ->any ())->method ('getSize ' )->willReturn (1 );
164171 $ gzFile = $ this ->createMock (ISimpleFile::class);
165- $ filePrefix = substr (md5 ('http://localhost/nextcloud ' ), 0 , 8 ) . '- ' ;
172+ $ filePrefix = substr (md5 (\OC_Util::getVersionString ('core ' )), 0 , 4 ) . '- ' .
173+ substr (md5 ('http://localhost/nextcloud ' ), 0 , 4 ) . '- ' ;
166174
167175 $ folder ->method ('getFile ' )
168176 ->will ($ this ->returnCallback (function ($ name ) use ($ file , $ fileDeps , $ gzFile , $ filePrefix ) {
@@ -197,6 +205,8 @@ public function testProcessCachedFileMemcache() {
197205
198206 $ gzFile = $ this ->createMock (ISimpleFile::class);
199207 $ filePrefix = substr (md5 ('http://localhost/nextcloud ' ), 0 , 8 ) . '- ' ;
208+ $ filePrefix = substr (md5 (\OC_Util::getVersionString ('core ' )), 0 , 4 ) . '- ' .
209+ substr (md5 ('http://localhost/nextcloud ' ), 0 , 4 ) . '- ' ;
200210 $ folder ->method ('getFile ' )
201211 ->will ($ this ->returnCallback (function ($ name ) use ($ file , $ fileDeps , $ gzFile , $ filePrefix ) {
202212 if ($ name === $ filePrefix .'styles.css ' ) {
@@ -382,8 +392,8 @@ public function testRebaseUrls($scss, $expected) {
382392
383393 public function dataGetCachedSCSS () {
384394 return [
385- ['core ' , 'core/css/styles.scss ' , '/css/core/styles.css ' ],
386- ['files ' , 'apps/files/css/styles.scss ' , '/css/files/styles.css ' ]
395+ ['core ' , 'core/css/styles.scss ' , '/css/core/styles.css ' , \OC_Util:: getVersionString () ],
396+ ['files ' , 'apps/files/css/styles.scss ' , '/css/files/styles.css ' , \OC_App:: getAppVersion ( ' files ' ) ]
387397 ];
388398 }
389399
@@ -393,11 +403,12 @@ public function dataGetCachedSCSS() {
393403 * @param $result
394404 * @dataProvider dataGetCachedSCSS
395405 */
396- public function testGetCachedSCSS ($ appName , $ fileName , $ result ) {
406+ public function testGetCachedSCSS ($ appName , $ fileName , $ result, $ version ) {
397407 $ this ->urlGenerator ->expects ($ this ->once ())
398408 ->method ('linkToRoute ' )
399409 ->with ('core.Css.getCss ' , [
400- 'fileName ' => substr (md5 ('http://localhost/nextcloud ' ), 0 , 8 ) . '-styles.css ' ,
410+ 'fileName ' => substr (md5 ($ version ), 0 , 4 ) . '- ' .
411+ substr (md5 ('http://localhost/nextcloud ' ), 0 , 4 ) . '-styles.css ' ,
401412 'appName ' => $ appName
402413 ])
403414 ->willReturn (\OC ::$ WEBROOT . $ result );
0 commit comments