如何在10月Cms中为插件测试设置活动主题

问题描述 投票:0回答:1

我正在尝试为树枝过滤器编写测试。为此,我需要从fixture文件夹加载一个主题 plugins/matchish/myplugin/tests/fixtures/themes/test

这是我如何设置测试

class TwigTest extends PluginTestCase {

    public function setUp()
    {
        parent::setUp();

        Config::set('cms.themesPath', __DIR__ . '/../fixtures/themes');
        Config::set('cms.activeTheme', 'test');
        Event::flush('cms.theme.getActiveTheme');
        Theme::resetCache();
    }
...

现在我收到错误active theme not found

unit-testing phpunit octobercms octobercms-plugins
1个回答
0
投票

你可以使用getActiveThemesetActiveTheme

// store old code once your testing done it should return to default theme
$oldTheme = Theme::getActiveTheme();
Theme::resetCache();
Theme::setActiveTheme('<theme.code>');

// at last 
Theme::setActiveTheme($oldTheme);

可能这应该有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.