Skip to content

Commit

Permalink
Provide "server.css" URL in ThemingController response
Browse files Browse the repository at this point in the history
Pull request #5429 made cached SCSS files depend on a hash of the base
URL, so the "/css/core/server.css" file does no longer exist. The
"server.css" URL must be known by the Theming app in order to update the
stylesheets when previewing the changes to the theme, so the
DataResponse from the controller now provides the full URL to the
"server.css" file that has to be reloaded (if any).

The "server.css" URL provided by the response will be taken into account
by the JavaScript front-end in a following commit.

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
  • Loading branch information
danxuliu committed Aug 10, 2017
1 parent 986dffd commit db52e86
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
13 changes: 10 additions & 3 deletions apps/theming/lib/Controller/ThemingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class ThemingController extends Controller {
private $appData;
/** @var SCSSCacher */
private $scssCacher;
/** @var IURLGenerator */
private $urlGenerator;

/**
* ThemingController constructor.
Expand All @@ -87,6 +89,7 @@ class ThemingController extends Controller {
* @param ITempManager $tempManager
* @param IAppData $appData
* @param SCSSCacher $scssCacher
* @param IURLGenerator $urlGenerator
*/
public function __construct(
$appName,
Expand All @@ -98,7 +101,8 @@ public function __construct(
IL10N $l,
ITempManager $tempManager,
IAppData $appData,
SCSSCacher $scssCacher
SCSSCacher $scssCacher,
IURLGenerator $urlGenerator
) {
parent::__construct($appName, $request);

Expand All @@ -110,6 +114,7 @@ public function __construct(
$this->tempManager = $tempManager;
$this->appData = $appData;
$this->scssCacher = $scssCacher;
$this->urlGenerator = $urlGenerator;
}

/**
Expand Down Expand Up @@ -172,7 +177,8 @@ public function updateStylesheet($setting, $value) {
[
'data' =>
[
'message' => $this->l10n->t('Saved')
'message' => $this->l10n->t('Saved'),
'serverCssUrl' => $this->urlGenerator->linkTo('', $this->scssCacher->getCachedSCSS('core', '/core/css/server.scss'))
],
'status' => 'success'
]
Expand Down Expand Up @@ -303,7 +309,8 @@ public function undo($setting) {
'data' =>
[
'value' => $value,
'message' => $this->l10n->t('Saved')
'message' => $this->l10n->t('Saved'),
'serverCssUrl' => $this->urlGenerator->linkTo('', $this->scssCacher->getCachedSCSS('core', '/core/css/server.scss'))
],
'status' => 'success'
]
Expand Down
39 changes: 38 additions & 1 deletion apps/theming/tests/Controller/ThemingControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class ThemingControllerTest extends TestCase {
private $appData;
/** @var SCSSCacher */
private $scssCacher;
/** @var IURLGenerator */
private $urlGenerator;

public function setUp() {
$this->request = $this->createMock(IRequest::class);
Expand All @@ -85,6 +87,7 @@ public function setUp() {
->willReturn(123);
$this->tempManager = \OC::$server->getTempManager();
$this->scssCacher = $this->createMock(SCSSCacher::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);

$this->themingController = new ThemingController(
'theming',
Expand All @@ -96,7 +99,8 @@ public function setUp() {
$this->l10n,
$this->tempManager,
$this->appData,
$this->scssCacher
$this->scssCacher,
$this->urlGenerator
);

return parent::setUp();
Expand Down Expand Up @@ -129,12 +133,23 @@ public function testUpdateStylesheetSuccess($setting, $value, $message) {
->method('t')
->with($message)
->willReturn($message);
$this->scssCacher
->expects($this->once())
->method('getCachedSCSS')
->with('core', '/core/css/server.scss')
->willReturn('/core/css/someHash-server.scss');
$this->urlGenerator
->expects($this->once())
->method('linkTo')
->with('', '/core/css/someHash-server.scss')
->willReturn('/nextcloudWebroot/core/css/someHash-server.scss');

$expected = new DataResponse(
[
'data' =>
[
'message' => $message,
'serverCssUrl' => '/nextcloudWebroot/core/css/someHash-server.scss',
],
'status' => 'success',
]
Expand Down Expand Up @@ -448,13 +463,24 @@ public function testUndo() {
->method('undo')
->with('MySetting')
->willReturn('MyValue');
$this->scssCacher
->expects($this->once())
->method('getCachedSCSS')
->with('core', '/core/css/server.scss')
->willReturn('/core/css/someHash-server.scss');
$this->urlGenerator
->expects($this->once())
->method('linkTo')
->with('', '/core/css/someHash-server.scss')
->willReturn('/nextcloudWebroot/core/css/someHash-server.scss');

$expected = new DataResponse(
[
'data' =>
[
'value' => 'MyValue',
'message' => 'Saved',
'serverCssUrl' => '/nextcloudWebroot/core/css/someHash-server.scss',
],
'status' => 'success'
]
Expand All @@ -481,6 +507,16 @@ public function testUndoDelete($value, $filename) {
->method('undo')
->with($value)
->willReturn($value);
$this->scssCacher
->expects($this->once())
->method('getCachedSCSS')
->with('core', '/core/css/server.scss')
->willReturn('/core/css/someHash-server.scss');
$this->urlGenerator
->expects($this->once())
->method('linkTo')
->with('', '/core/css/someHash-server.scss')
->willReturn('/nextcloudWebroot/core/css/someHash-server.scss');
$folder = $this->createMock(ISimpleFolder::class);
$file = $this->createMock(ISimpleFile::class);
$this->appData
Expand All @@ -503,6 +539,7 @@ public function testUndoDelete($value, $filename) {
[
'value' => $value,
'message' => 'Saved',
'serverCssUrl' => '/nextcloudWebroot/core/css/someHash-server.scss',
],
'status' => 'success'
]
Expand Down

0 comments on commit db52e86

Please sign in to comment.