mirror of
https://github.com/flarum/framework.git
synced 2024-12-03 07:33:36 +08:00
f56fc11af9
This PR introduces the ability to just override a LESS file's contents through an extender.
This is mainly useful for theme development, as there are times in extensively customized themes where overriding the actual file makes a huge difference vs overriding CSS styles which can turn into a maintenance hell real fast.
Overriding styles is more tedious than overriding files. When you're designing an element, you would normally rather start from a blank canvas, than a styled element. With an already styled element you have to first override and undo the styles you do not wish to have, only then can you start shaping it, but even then you'd always end up constantly undoing default styles. This mostly applies for more advanced themes. (example: 851c55516d/less/forum/DiscussionList.less
)
108 lines
3.4 KiB
PHP
108 lines
3.4 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of Flarum.
|
|
*
|
|
* For detailed copyright and license information, please view the
|
|
* LICENSE file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Flarum\Tests\integration\extenders;
|
|
|
|
use Flarum\Extend;
|
|
use Flarum\Testing\integration\TestCase;
|
|
|
|
class ThemeTest extends TestCase
|
|
{
|
|
/**
|
|
* @test
|
|
*/
|
|
public function theme_extender_override_import_doesnt_work_by_default()
|
|
{
|
|
$response = $this->send($this->request('GET', '/'));
|
|
|
|
$this->assertEquals(200, $response->getStatusCode());
|
|
|
|
$cssFilePath = $this->app()->getContainer()->make('filesystem')->disk('flarum-assets')->path('forum.css');
|
|
$this->assertStringNotContainsString('.dummy_test_case{color:red}', file_get_contents($cssFilePath));
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
public function theme_extender_override_import_works()
|
|
{
|
|
$this->extend(
|
|
(new Extend\Theme)
|
|
->overrideLessImport('forum/Hero.less', __DIR__.'/../../fixtures/less/dummy.less')
|
|
);
|
|
|
|
$response = $this->send($this->request('GET', '/'));
|
|
|
|
$this->assertEquals(200, $response->getStatusCode());
|
|
|
|
$cssFilePath = $this->app()->getContainer()->make('filesystem')->disk('flarum-assets')->path('forum.css');
|
|
|
|
$this->assertStringContainsString('.dummy_test_case{color:red}', file_get_contents($cssFilePath));
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
public function theme_extender_override_import_works_with_external_sources()
|
|
{
|
|
$this->extend(
|
|
(new Extend\Frontend('forum'))
|
|
->css(__DIR__.'/../../fixtures/less/forum.less'),
|
|
(new Extend\Theme)
|
|
->overrideLessImport('Imported.less', __DIR__.'/../../fixtures/less/dummy.less', 'site-custom')
|
|
);
|
|
|
|
$response = $this->send($this->request('GET', '/'));
|
|
|
|
$this->assertEquals(200, $response->getStatusCode());
|
|
|
|
$cssFilePath = $this->app()->getContainer()->make('filesystem')->disk('flarum-assets')->path('forum.css');
|
|
$contents = file_get_contents($cssFilePath);
|
|
|
|
$this->assertStringNotContainsString('.Imported', $contents);
|
|
$this->assertStringContainsString('.dummy_test_case{color:red}', $contents);
|
|
$this->assertStringContainsString('.dummy{color:yellow}', $contents);
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
public function theme_extender_override_file_source_works()
|
|
{
|
|
$this->extend(
|
|
(new Extend\Theme)
|
|
->overrideFileSource('forum.less', __DIR__.'/../../fixtures/less/override_filesource.less')
|
|
);
|
|
|
|
$response = $this->send($this->request('GET', '/'));
|
|
|
|
$this->assertEquals(200, $response->getStatusCode());
|
|
|
|
$cssFilePath = $this->app()->getContainer()->make('filesystem')->disk('flarum-assets')->path('forum.css');
|
|
|
|
$this->assertEquals('body{color:orange}', file_get_contents($cssFilePath));
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
public function theme_extender_override_file_source_works_by_failing_when_necessary()
|
|
{
|
|
$this->extend(
|
|
(new Extend\Theme)
|
|
->overrideFileSource('mixins.less', __DIR__.'/../../fixtures/less/dummy.less')
|
|
);
|
|
|
|
$response = $this->send($this->request('GET', '/'));
|
|
|
|
$this->assertStringContainsString('Less_Exception_Compiler', $response->getBody()->getContents());
|
|
$this->assertEquals(500, $response->getStatusCode());
|
|
}
|
|
}
|