【问题标题】:Cakephp how to load I18nModel fixture for testing?Cakephp 如何加载 I18nModel 夹具进行测试?
【发布时间】:2013-09-15 11:19:06
【问题描述】:

我想使用蛋糕测试功能来测试我的应用,但我的 AppTranslateBehavior(其自定义行为)中使用的 I18nModel 存在问题。我收到一个错误:

在数据源测试中未找到模型 I18nModel 的表 i18n。

在测试用例中,我在 $fixtures 中添加了“plugin.languages.i18n”(夹具在插件内),我的夹具如下所示:

class I18nFixture extends CakeTestFixture {

public $name = 'I18n';
public $table = 'i18n';
public $import = array(
    'table' => 'i18n',
);}

我也试过了

class I18nModelFixture extends CakeTestFixture {

public $import = 'I18nModel';
public $table = 'i18n';
public $fields = array(
    'id' => array('type' => 'integer', 'key' => 'primary'),
    'locale' => array('type' => 'string', 'length' => 6, 'null' => false),
    'model' => array('type' => 'string', 'null' => false),
    'foreign_key' => array('type' => 'integer', 'null' => false),
    'field' => array('type' => 'string', 'null' => false),
    'content' => array('type' => 'text')
);
public $records = array();}

还有许多其他变体,但都没有奏效。

我错过了什么?

【问题讨论】:

  • 你找到解决这个问题的方法了吗?如果您可以在 SO 上发布它,那就太好了。

标签: cakephp internationalization testcase


【解决方案1】:

你应该使用 cakephp 提供的核心翻译装置:

class MyModelTest extends CakeTestCase {
    public $fixtures = array(...,'core.translates');
    ...
}

编辑:灯具名称是 core.translates,而不是 core.translate

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-21
    • 1970-01-01
    • 2018-02-07
    • 2011-01-12
    • 2016-09-09
    • 1970-01-01
    • 1970-01-01
    • 2012-07-21
    相关资源
    最近更新 更多