Search code examples
cakephpphpunitcakedc

Include fixture from Tags plugin in app test


I'm using the excellent CakeDC Tags plugin on my Solutions model:

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

I have a SolutionsController::search() method:

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

I'm trying to write a test for this method:

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

I'm getting this error when running the test: Missing Database Table Error: Table tags for model Tag was not found in datasource test.

I've tried copying the plugin Tag fixture to my app Test/fixtures folder and including it as an app fixture. I can't get my test to run. How do I get my test to see the tags fixture from app\Plugin\tags\Test\Fixture\TagFixture.php and run?


Solution

  • Problem turned out to be my SolutionsFixture, which imported the table schema and the records, then also included a $records array (oops). Re-baking this fixture to import neither schema nor records resolved the error.