在app test中包含Tags插件的fixture

时间:2014-03-21 15:24:59

标签: cakephp phpunit cakedc

我在我的解决方案模型上使用了优秀的CakeDC标签插件:

class Solution extends AppModel {
    public $actsAs = array(
        'Tags.Taggable',
        'Search.Searchable',
    );
}

我有一个SolutionsController :: search()方法:

App::uses('AppController', 'Controller');
class SolutionsController extends AppController {
    public $components = array(
        'Paginator',
        'Search.Prg',
    );
    public $presetVars = true; // using the model configuration ('Search' plugin)

    public function search() {
        $this->Prg->commonProcess();
        $this->Paginator->settings['conditions'] = $this->Solution->parseCriteria($this->Prg->parsedParams());
        $solutions = $this->Paginator->paginate();
        if (!empty($solutions)) {
            $this->Session->setFlash('Solutions found');
        } else {
            $this->Session->setFlash('No solutions found');
        }
        $this->set('solutions', $solutions);
        $this->render('index');
    }

我正在尝试为此方法编写测试:

App::uses('SolutionsController', 'Controller');
class SolutionsControllerTest extends ControllerTestCase {

    public $fixtures = array(
            'app.solution',
            'plugin.tags.tag'
    );

    public function testSearchForOneResultShouldOutputText() {
        $data = array('search' => 'fiery');
        $result = $this->Solution->search($data);
        debug($result);
        $expected = array(
            'id' => 3,
            'name' => 'fiery-colored horse',
            'shortdesc' => 'war',
            'body' => 'it was granted to the one seated on it..',
            'category_id' => 3,
            'created_by' => 1,
            'modified_by' => 1,
            'created' => '2014-02-14 21:28:46',
            'modified' => '2014-02-14 21:28:46'
        );
        $this->assertContains($expected);
    }
}

我在运行测试时遇到此错误: 缺少数据库表 错误:在数据源测试中找不到模型Tag的表标记。

我已经尝试将插件标签夹具复制到我的应用程序Test / fixtures文件夹中,并将其作为应用程序夹具包含在内。我无法让我的测试运行。如何让我的测试从app\Plugin\tags\Test\Fixture\TagFixture.php查看标签夹具并运行?

1 个答案:

答案 0 :(得分:0)

问题原来是我的SolutionsFixture,它导入了表模式和记录,然后包含了$ records数组(oops)。重新烘焙此灯具既不导入架构也不导入记录解决了错误。