Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixed tests
Signed-off-by: John Molakvoæ (skjnldsv) <[email protected]>
  • Loading branch information
skjnldsv authored and juliusknorr committed Jul 19, 2018
commit 14bc9ffda4cdf42b047725b581d6a1129eb70a5b
2 changes: 1 addition & 1 deletion apps/dav/lib/CalDAV/Activity/Filter/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function getPriority() {
* @since 11.0.0
*/
public function getIcon() {
return $this->url->getAbsoluteURL($this->url->imagePath('core', 'places/calendar-dark.svg'));
return $this->url->getAbsoluteURL($this->url->imagePath('core', 'places/calendar.svg'));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected function setUp() {
public function testGetIcon() {
$this->url->expects($this->once())
->method('imagePath')
->with('core', 'places/calendar-dark.svg')
->with('core', 'places/calendar.svg')
->willReturn('path-to-icon');

$this->url->expects($this->once())
Expand Down
2 changes: 1 addition & 1 deletion autotest-js.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ for SCSSFILE in core/css/*.scss
do
FILE=$(basename $SCSSFILE)
FILENAME="${FILE%.*}"
printf "@import 'variables.scss'; @import '${FILE}';" | ./build/bin/node-sass --include-path core/css/ > tests/css/${FILE}.css
printf "\$webroot:''; @import 'functions.scss'; @import 'variables.scss'; @import '${FILE}';" | ./build/bin/node-sass --include-path core/css/ > tests/css/${FILE}.css
done

KARMA="$PREFIX/node_modules/karma/bin/karma"
Expand Down
5 changes: 3 additions & 2 deletions core/css/functions.scss
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@
*/
@mixin icon-color($icon, $dir, $color, $core: false) {
// remove # from color
$index: str-index($color, '#');
// inspect cast int to string
$index: str-index(inspect($color), '#');
@if $index {
$color: str-slice($color, 2);
$color: str-slice(inspect($color), 2);
}
$varName: "--icon-#{$icon}-#{$color}";
@if $core {
Expand Down
4 changes: 3 additions & 1 deletion lib/private/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
use OC\Share20\ShareHelper;
use OC\SystemTag\ManagerFactory as SystemTagManagerFactory;
use OC\Tagging\TagMapper;
use OC\Template\IconsCacher;
use OC\Template\JSCombiner;
use OC\Template\SCSSCacher;
use OCA\Theming\ImageManager;
Expand Down Expand Up @@ -963,7 +964,8 @@ public function __construct($webRoot, \OC\Config $config) {
$c->getConfig(),
$c->getThemingDefaults(),
\OC::$SERVERROOT,
$this->getMemCacheFactory()
$this->getMemCacheFactory(),
$c->query(IconsCacher::class)
);
});
$this->registerService(JSCombiner::class, function (Server $c) {
Expand Down
16 changes: 8 additions & 8 deletions lib/private/Template/IconsCacher.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use OCP\Files\IAppData;
use OCP\Files\NotFoundException;
use OCP\Files\SimpleFS\ISimpleFolder;
use OCP\Files\SimpleFS\ISimpleFile;
use OCP\ILogger;
use OCP\IURLGenerator;
use OC\Files\AppData\Factory;
Expand Down Expand Up @@ -85,10 +86,11 @@ private function getIconsFromCss(string $css): array{
*/
public function setIconsCss(string $css) {

try {
$currentData = $this->folder->getFile($this->fileName)->getContent();
} catch (NotFoundException $e) {
$cachedFile = $this->getCachedCSS();
if (!$cachedFile) {
$currentData = '';
} else {
$currentData = $cachedFile->getContent();
}

// remove :root
Expand All @@ -102,16 +104,14 @@ public function setIconsCss(string $css) {
}

if (strlen($data) > 0) {
try {
$cachedfile = $this->folder->getFile($this->fileName);
} catch (NotFoundException $e) {
$cachedfile = $this->folder->newFile($this->fileName);
if (!$cachedFile) {
$cachedFile = $this->folder->newFile($this->fileName);
}

$data = ":root {
$data
}";
$cachedfile->putContent($data);
$cachedFile->putContent($data);
}

return preg_replace($this->iconVarRE, '', $css);
Expand Down
11 changes: 4 additions & 7 deletions lib/private/Template/SCSSCacher.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,16 @@ class SCSSCacher {
* @param \OC_Defaults $defaults
* @param string $serverRoot
* @param ICacheFactory $cacheFactory
* @param IconsCacher $iconsCacher
*/
public function __construct(ILogger $logger,
Factory $appDataFactory,
IURLGenerator $urlGenerator,
IConfig $config,
\OC_Defaults $defaults,
$serverRoot,
ICacheFactory $cacheFactory) {
ICacheFactory $cacheFactory,
IconsCacher $iconsCacher) {
$this->logger = $logger;
$this->appData = $appDataFactory->get('css');
$this->urlGenerator = $urlGenerator;
Expand All @@ -101,12 +103,7 @@ public function __construct(ILogger $logger,
$this->serverRoot = $serverRoot;
$this->cacheFactory = $cacheFactory;
$this->depsCache = $cacheFactory->createDistributed('SCSS-' . md5($this->urlGenerator->getBaseUrl()));

$this->iconsCacher = new IconsCacher(
$this->logger,
$appDataFactory,
$this->urlGenerator
);
$this->iconsCacher = $iconsCacher;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/Settings/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function testGetAdminSections() {
['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'],
]);

Expand Down Expand Up @@ -175,7 +175,7 @@ public function testGetAdminSectionsEmptySection() {
['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'],
]);

Expand Down
7 changes: 6 additions & 1 deletion tests/lib/Template/CSSResourceLocatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use OCP\IURLGenerator;
use OCP\IConfig;
use OCA\Theming\ThemingDefaults;
use OC\Template\IconsCacher;
use OC\Template\SCSSCacher;
use OC\Template\CSSResourceLocator;

Expand All @@ -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();
Expand All @@ -57,6 +60,7 @@ protected function setUp() {
$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() {
Expand All @@ -70,7 +74,8 @@ private function cssResourceLocator() {
$this->config,
$this->themingDefaults,
\OC::$SERVERROOT,
$this->cacheFactory
$this->cacheFactory,
$this->iconsCacher
);
return new CSSResourceLocator(
$this->logger,
Expand Down
126 changes: 126 additions & 0 deletions tests/lib/Template/IconsCacherTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?php
/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strict

* @copyright Copyright (c) 2018, John Molakvoæ ([email protected])
*
* @author John Molakvoæ (skjnldsv) <[email protected]>
*
* @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);
}

}
Loading