使用CKEditor测试表单

时间:2017-07-14 16:42:52

标签: symfony ckeditor

我想测试包含ArticleForm字段的CKEditor

$builder->add('content', CKEditorType::class, array(
    'config' => array('uiColor' => '#ffffff'),
    'required' => true));

然而,当我运行PHPUnit时,我收到以下错误:

Argument 1 passed to Ivory\CKEditorBundle\Form\Type\CKEditorType::__construct() 
must be an instance of Ivory\CKEditorBundle\Model\ConfigManagerInterface, none given

我的测试配置与 dev prod 相同,其中CKEditor正常工作:

ivory_ck_editor:
    default_config: default
    configs:
        default:
            filebrowserBrowseRoute: elfinder
            filebrowserBrowseRouteParameters: []

测试用例扩展了Symfonys的TypeTestCase,它创建了自己的工厂。这可能是原因。但是,我不知道如何强制此工厂提供正确的CKEditor实例。有人知道怎么做吗?

1 个答案:

答案 0 :(得分:1)

问题已解决PreloadedExtension

class ArticleTypeTest {

    protected function getExtensions() {
        return array(new PreloadedExtension(array($this->getCKEditor()), array()));
    }

    ...

    protected function getCKEditor() {
        $configManager = $this->getMockBuilder ( ConfigManagerInterface::class )->disableOriginalConstructor ()->getMock ();
        $pluginManager = $this->getMockBuilder ( PluginManagerInterface::class )->disableOriginalConstructor ()->getMock ();
        $stylesSetManager = $this->getMockBuilder ( StylesSetManagerInterface::class )->disableOriginalConstructor ()->getMock ();
        $templateManager = $this->getMockBuilder ( TemplateManagerInterface::class )->disableOriginalConstructor ()->getMock ();

        $type = new CKEditorType($configManager, $pluginManager, $stylesSetManager, $templateManager);

        return $type;
    }
}