0

我在我的 Solutions 模型上使用了优秀的 CakeDC Tags 插件:

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中查看标签夹具并运行?

4

1 回答 1

0

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

于 2014-04-13T16:15:16.257 回答