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:
3
tests/fixtures/less/config.less
vendored
Normal file
3
tests/fixtures/less/config.less
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
body {
|
||||
--custom-config-setting: @custom-config-setting;
|
||||
}
|
@@ -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
|
||||
|
Reference in New Issue
Block a user