Cakephp如何加载I18nModel夹具进行测试?

标签 cakephp internationalization testcase

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

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

在测试用例中,我将“plugin.languages.i18n”(固定装置位于插件内部)添加到 $fixtures 中,我的固定装置如下所示:

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();}

还有许多其他变体,但没有一个起作用。

我是不是漏掉了什么?

最佳答案

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

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

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

关于Cakephp如何加载I18nModel夹具进行测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18741086/

相关文章:

testing - 发现测试用例的方法有哪些

java - JTestcase 使用 JUnit 处理 xml 文件中的数据?

php - 如何从 cakephp 的 url 中删除操作名称?

CakePHP 如何在自定义验证函数中使用内置验证规则?

Django:在多种语言上运行网站

spring-mvc - Spring MVC/Freemarker : using a message from a bundle in a Freemarker expression

testing - 当我们在现有测试用例中间添加一个新测试用例时,测试框架如何表现?

php - 在 cakephp 中使用 maxlength 选项 - 但它在 html 中输出两个 maxlength 值

html - cakephp 2.x 如何包含来自外部模板 css 的文件

C#、本地化、资源和 MonoDevelop