summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2018-07-19 23:54:29 +0200
committerGitHub <noreply@github.com>2018-07-19 23:54:29 +0200
commit4751f1e7f766419fd013e5d6ddac4988e9158f5c (patch)
treeaece73c6e050c5adfd8a68f29f3c2eb02d51d961 /tests
parent8032e362ec27111f5813f70b9604e7d07c6bf2ab (diff)
parent9d94cc16976970c84d5a88e090ea55be273be712 (diff)
downloadnextcloud-server-4751f1e7f766419fd013e5d6ddac4988e9158f5c.tar.gz
nextcloud-server-4751f1e7f766419fd013e5d6ddac4988e9158f5c.zip
Merge pull request #9984 from nextcloud/inverted-svg-api
Svg color api
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/Settings/ManagerTest.php4
-rw-r--r--tests/lib/Template/CSSResourceLocatorTest.php7
-rw-r--r--tests/lib/Template/IconsCacherTest.php127
-rw-r--r--tests/lib/Template/SCSSCacherTest.php51
4 files changed, 179 insertions, 10 deletions
diff --git a/tests/lib/Settings/ManagerTest.php b/tests/lib/Settings/ManagerTest.php
index 30a5b7bd103..76f6d867d3a 100644
--- a/tests/lib/Settings/ManagerTest.php
+++ b/tests/lib/Settings/ManagerTest.php
@@ -122,7 +122,7 @@ class ManagerTest extends TestCase {
['core', 'actions/settings-dark.svg', '1'],
['core', 'actions/share.svg', '2'],
['core', 'actions/password.svg', '3'],
- ['core', 'places/contacts-dark.svg', '5'],
+ ['core', 'places/contacts.svg', '5'],
['settings', 'help.svg', '4'],
]);
@@ -175,7 +175,7 @@ class ManagerTest extends TestCase {
['core', 'actions/settings-dark.svg', '1'],
['core', 'actions/share.svg', '2'],
['core', 'actions/password.svg', '3'],
- ['core', 'places/contacts-dark.svg', '5'],
+ ['core', 'places/contacts.svg', '5'],
['settings', 'help.svg', '4'],
]);
diff --git a/tests/lib/Template/CSSResourceLocatorTest.php b/tests/lib/Template/CSSResourceLocatorTest.php
index a8b123b8d5b..3fb7972b211 100644
--- a/tests/lib/Template/CSSResourceLocatorTest.php
+++ b/tests/lib/Template/CSSResourceLocatorTest.php
@@ -31,6 +31,7 @@ use OCP\ILogger;
use OCP\IURLGenerator;
use OCP\IConfig;
use OCA\Theming\ThemingDefaults;
+use OC\Template\IconsCacher;
use OC\Template\SCSSCacher;
use OC\Template\CSSResourceLocator;
@@ -47,6 +48,8 @@ class CSSResourceLocatorTest extends \Test\TestCase {
protected $cacheFactory;
/** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */
protected $logger;
+ /** @var IconsCacher|\PHPUnit_Framework_MockObject_MockObject */
+ protected $iconsCacher;
protected function setUp() {
parent::setUp();
@@ -57,6 +60,7 @@ class CSSResourceLocatorTest extends \Test\TestCase {
$this->config = $this->createMock(IConfig::class);
$this->cacheFactory = $this->createMock(ICacheFactory::class);
$this->themingDefaults = $this->createMock(ThemingDefaults::class);
+ $this->iconsCacher = $this->createMock(IconsCacher::class);
}
private function cssResourceLocator() {
@@ -70,7 +74,8 @@ class CSSResourceLocatorTest extends \Test\TestCase {
$this->config,
$this->themingDefaults,
\OC::$SERVERROOT,
- $this->cacheFactory
+ $this->cacheFactory,
+ $this->iconsCacher
);
return new CSSResourceLocator(
$this->logger,
diff --git a/tests/lib/Template/IconsCacherTest.php b/tests/lib/Template/IconsCacherTest.php
new file mode 100644
index 00000000000..106f08d5fa8
--- /dev/null
+++ b/tests/lib/Template/IconsCacherTest.php
@@ -0,0 +1,127 @@
+<?php
+declare (strict_types = 1);
+/**
+ * @copyright Copyright (c) 2018, John Molakvoæ (skjnldsv@protonmail.com)
+ *
+ * @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
+ *
+ * @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\Template;
+
+use OC\Files\AppData\AppData;
+use OC\Files\AppData\Factory;
+use OC\Template\IconsCacher;
+use OCA\Theming\ThemingDefaults;
+use OCP\Files\IAppData;
+use OCP\Files\NotFoundException;
+use OCP\Files\SimpleFS\ISimpleFile;
+use OCP\Files\SimpleFS\ISimpleFolder;
+use OCP\ICache;
+use OCP\ICacheFactory;
+use OCP\IConfig;
+use OCP\ILogger;
+use OCP\IURLGenerator;
+use OC_App;
+
+class IconsCacherTest extends \Test\TestCase {
+ /** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */
+ protected $logger;
+ /** @var IAppData|\PHPUnit_Framework_MockObject_MockObject */
+ protected $appData;
+ /** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
+ protected $urlGenerator;
+
+ protected function setUp() {
+ $this->logger = $this->createMock(ILogger::class);
+ $this->appData = $this->createMock(AppData::class);
+
+ /** @var Factory|\PHPUnit_Framework_MockObject_MockObject $factory */
+ $factory = $this->createMock(Factory::class);
+ $factory->method('get')->with('css')->willReturn($this->appData);
+
+ $this->folder = $this->createMock(ISimpleFolder::class);
+ $this->appData->method('getFolder')->willReturn($this->folder);
+
+ $this->urlGenerator = $this->createMock(IURLGenerator::class);
+
+ $this->iconsCacher = new IconsCacher(
+ $this->logger,
+ $factory,
+ $this->urlGenerator
+ );
+ }
+
+ public function testGetIconsFromEmptyCss() {
+ $css = "
+ icon.test {
+ color: #aaa;
+ }
+ ";
+ $icons = self::invokePrivate($this->iconsCacher, 'getIconsFromCss', [$css]);
+ $this->assertTrue(empty($icons));
+ }
+
+ public function testGetIconsFromValidCss() {
+ $css = "
+ icon.test {
+ --icon-test: url('/svg/core/actions/add/000');
+ background-image: var(--icon-test);
+ }
+ ";
+ $actual = self::invokePrivate($this->iconsCacher, 'getIconsFromCss', [$css]);
+ $expected = array(
+ 'icon-test' => '/svg/core/actions/add/000'
+ );
+ $this->assertEquals($expected, $actual);
+ }
+
+ public function testSetIconsFromEmptyCss() {
+ $expected = "
+ icon.test {
+ color: #aaa;
+ }
+ ";
+ $actual = $this->iconsCacher->setIconsCss($expected);
+ $this->assertEquals($expected, $actual);
+ }
+
+ public function testSetIconsFromValidCss() {
+ $css = "
+ icon.test {
+ --icon-test: url('/svg/core/actions/add/000');
+ background-image: var(--icon-test);
+ }
+ ";
+ $expected = "
+ icon.test {
+
+ background-image: var(--icon-test);
+ }
+ ";
+
+ $iconsFile = $this->createMock(ISimpleFile::class);
+ $this->folder->expects($this->once())
+ ->method('getFile')
+ ->willReturn($iconsFile);
+
+ $actual = $this->iconsCacher->setIconsCss($css);
+ $this->assertEquals($expected, $actual);
+ }
+
+} \ No newline at end of file
diff --git a/tests/lib/Template/SCSSCacherTest.php b/tests/lib/Template/SCSSCacherTest.php
index 5e3700477ff..f32b87edcbb 100644
--- a/tests/lib/Template/SCSSCacherTest.php
+++ b/tests/lib/Template/SCSSCacherTest.php
@@ -26,6 +26,7 @@ namespace Test\Template;
use OC\Files\AppData\AppData;
use OC\Files\AppData\Factory;
use OC\Template\SCSSCacher;
+use OC\Template\IconsCacher;
use OCA\Theming\ThemingDefaults;
use OCP\Files\IAppData;
use OCP\Files\NotFoundException;
@@ -55,11 +56,14 @@ class SCSSCacherTest extends \Test\TestCase {
protected $depsCache;
/** @var ICacheFactory|\PHPUnit_Framework_MockObject_MockObject */
protected $cacheFactory;
+ /** @var IconsCacher|\PHPUnit_Framework_MockObject_MockObject */
+ protected $iconsCacher;
protected function setUp() {
parent::setUp();
$this->logger = $this->createMock(ILogger::class);
$this->appData = $this->createMock(AppData::class);
+ $this->iconsCacher = $this->createMock(IconsCacher::class);
/** @var Factory|\PHPUnit_Framework_MockObject_MockObject $factory */
$factory = $this->createMock(Factory::class);
@@ -80,6 +84,11 @@ class SCSSCacherTest extends \Test\TestCase {
$this->themingDefaults = $this->createMock(ThemingDefaults::class);
$this->themingDefaults->expects($this->any())->method('getScssVariables')->willReturn([]);
+ $iconsFile = $this->createMock(ISimpleFile::class);
+ $this->iconsCacher->expects($this->any())
+ ->method('getCachedCSS')
+ ->willReturn($iconsFile);
+
$this->scssCacher = new SCSSCacher(
$this->logger,
$factory,
@@ -87,7 +96,8 @@ class SCSSCacherTest extends \Test\TestCase {
$this->config,
$this->themingDefaults,
\OC::$SERVERROOT,
- $this->cacheFactory
+ $this->cacheFactory,
+ $this->iconsCacher
);
}
@@ -103,7 +113,7 @@ class SCSSCacherTest extends \Test\TestCase {
$fileDeps = $this->createMock(ISimpleFile::class);
$gzfile = $this->createMock(ISimpleFile::class);
$filePrefix = substr(md5(\OC_Util::getVersionString('core')), 0, 4) . '-' .
- substr(md5('http://localhost/nextcloud'), 0, 4) . '-';
+ substr(md5('http://localhost/nextcloud/index.php'), 0, 4) . '-';
$folder->method('getFile')
->will($this->returnCallback(function($path) use ($file, $gzfile, $filePrefix) {
@@ -126,6 +136,10 @@ class SCSSCacherTest extends \Test\TestCase {
->method('getBaseUrl')
->willReturn('http://localhost/nextcloud');
+ $this->iconsCacher->expects($this->any())
+ ->method('setIconsCss')
+ ->willReturn('scss {}');
+
$actual = $this->scssCacher->process(\OC::$SERVERROOT, '/core/css/styles.scss', 'core');
$this->assertTrue($actual);
}
@@ -139,7 +153,7 @@ class SCSSCacherTest extends \Test\TestCase {
$fileDeps = $this->createMock(ISimpleFile::class);
$gzfile = $this->createMock(ISimpleFile::class);
$filePrefix = substr(md5(\OC_Util::getVersionString('core')), 0, 4) . '-' .
- substr(md5('http://localhost/nextcloud'), 0, 4) . '-';
+ substr(md5('http://localhost/nextcloud/index.php'), 0, 4) . '-';
$folder->method('getFile')
->will($this->returnCallback(function($path) use ($file, $gzfile, $filePrefix) {
@@ -158,6 +172,10 @@ class SCSSCacherTest extends \Test\TestCase {
->with($filePrefix.'styles.css.deps')
->willReturn($fileDeps);
+ $this->iconsCacher->expects($this->any())
+ ->method('setIconsCss')
+ ->willReturn('scss {}');
+
$actual = $this->scssCacher->process(\OC::$SERVERROOT, '/core/css/styles.scss', 'core');
$this->assertTrue($actual);
}
@@ -171,7 +189,7 @@ class SCSSCacherTest extends \Test\TestCase {
$fileDeps->expects($this->any())->method('getSize')->willReturn(1);
$gzFile = $this->createMock(ISimpleFile::class);
$filePrefix = substr(md5(\OC_Util::getVersionString('core')), 0, 4) . '-' .
- substr(md5('http://localhost/nextcloud'), 0, 4) . '-';
+ substr(md5('http://localhost/nextcloud/index.php'), 0, 4) . '-';
$folder->method('getFile')
->will($this->returnCallback(function($name) use ($file, $fileDeps, $gzFile, $filePrefix) {
@@ -185,6 +203,10 @@ class SCSSCacherTest extends \Test\TestCase {
$this->fail();
}));
+ $this->iconsCacher->expects($this->any())
+ ->method('setIconsCss')
+ ->willReturn('scss {}');
+
$actual = $this->scssCacher->process(\OC::$SERVERROOT, '/core/css/styles.scss', 'core');
$this->assertTrue($actual);
}
@@ -205,9 +227,8 @@ class SCSSCacherTest extends \Test\TestCase {
$fileDeps->expects($this->any())->method('getSize')->willReturn(1);
$gzFile = $this->createMock(ISimpleFile::class);
- $filePrefix = substr(md5('http://localhost/nextcloud'), 0, 8) . '-';
$filePrefix = substr(md5(\OC_Util::getVersionString('core')), 0, 4) . '-' .
- substr(md5('http://localhost/nextcloud'), 0, 4) . '-';
+ substr(md5('http://localhost/nextcloud/index.php'), 0, 4) . '-';
$folder->method('getFile')
->will($this->returnCallback(function($name) use ($file, $fileDeps, $gzFile, $filePrefix) {
if ($name === $filePrefix.'styles.css') {
@@ -220,6 +241,10 @@ class SCSSCacherTest extends \Test\TestCase {
$this->fail();
}));
+ $this->iconsCacher->expects($this->any())
+ ->method('setIconsCss')
+ ->willReturn('scss {}');
+
$actual = $this->scssCacher->process(\OC::$SERVERROOT, '/core/css/styles.scss', 'core');
$this->assertTrue($actual);
}
@@ -276,6 +301,10 @@ class SCSSCacherTest extends \Test\TestCase {
throw new \Exception();
}));
+ $this->iconsCacher->expects($this->any())
+ ->method('setIconsCss')
+ ->willReturn('scss {}');
+
$file->expects($this->once())->method('putContent');
$depsFile->expects($this->once())->method('putContent');
$gzipFile->expects($this->once())->method('putContent');
@@ -310,6 +339,10 @@ class SCSSCacherTest extends \Test\TestCase {
$depsFile->expects($this->once())->method('putContent');
$gzipFile->expects($this->once())->method('putContent');
+ $this->iconsCacher->expects($this->any())
+ ->method('setIconsCss')
+ ->willReturn('scss {}');
+
$actual = self::invokePrivate($this->scssCacher, 'cache', [$path, $fileNameCSS, $fileNameSCSS, $folder, $webDir]);
$this->assertTrue($actual);
}
@@ -336,6 +369,10 @@ class SCSSCacherTest extends \Test\TestCase {
throw new \Exception();
}));
+ $this->iconsCacher->expects($this->at(0))
+ ->method('setIconsCss')
+ ->willReturn('body{background-color:#0082c9}');
+
$file->expects($this->at(0))->method('putContent')->with($this->callback(
function ($content){
return 'body{background-color:#0082c9}' === $content;
@@ -409,7 +446,7 @@ class SCSSCacherTest extends \Test\TestCase {
->method('linkToRoute')
->with('core.Css.getCss', [
'fileName' => substr(md5($version), 0, 4) . '-' .
- substr(md5('http://localhost/nextcloud'), 0, 4) . '-styles.css',
+ substr(md5('http://localhost/nextcloud/index.php'), 0, 4) . '-styles.css',
'appName' => $appName
])
->willReturn(\OC::$WEBROOT . $result);