1
0
mirror of https://github.com/flarum/core.git synced 2025-07-31 21:50:50 +02:00

feat: Allow registering settings as Less config vars through Settings Extender (#3011)

Co-authored-by: Alexander Skvortsov <38059171+askvortsov1@users.noreply.github.com>
This commit is contained in:
Sami Mazouz
2021-11-01 15:41:19 +01:00
committed by GitHub
parent 2b163025d6
commit d8e7aa54b4
8 changed files with 163 additions and 17 deletions

3
tests/fixtures/less/config.less vendored Normal file
View File

@@ -0,0 +1,3 @@
body {
--custom-config-setting: @custom-config-setting;
}

View File

@@ -220,6 +220,61 @@ class SettingsTest extends TestCase
$this->assertEquals(null, $value);
}
/**
* @test
*/
public function custom_less_var_does_not_work_by_default()
{
$this->extend(
(new Extend\Frontend('forum'))
->css(__DIR__.'/../../fixtures/less/config.less'),
);
$response = $this->send($this->request('GET', '/'));
$this->assertEquals(500, $response->getStatusCode());
}
/**
* @test
*/
public function custom_less_var_works_if_registered()
{
$this->extend(
(new Extend\Frontend('forum'))
->css(__DIR__.'/../../fixtures/less/config.less'),
(new Extend\Settings())
->registerLessConfigVar('custom-config-setting', 'custom-prefix.custom_setting')
);
$response = $this->send($this->request('GET', '/'));
$cssFilePath = $this->app()->getContainer()->make('filesystem')->disk('flarum-assets')->path('forum.css');
$this->assertStringContainsString('--custom-config-setting:customValue', file_get_contents($cssFilePath));
$this->assertEquals(200, $response->getStatusCode());
}
/**
* @test
*/
public function cant_save_setting_if_invalid_less_var()
{
$this->extend(
(new Extend\Settings())
->registerLessConfigVar('custom-config-setting2', 'custom-prefix.custom_setting2')
);
$response = $this->send($this->request('POST', '/api/settings', [
'authenticatedAs' => 1,
'json' => [
'custom-prefix.custom_setting2' => '@muralf'
],
]));
$this->assertEquals(422, $response->getStatusCode());
}
}
class CustomInvokableClass