Welcome to the Cookbook

loading...

4.7.10 Testing plugins

ada perubahan yang masih ditangguhkan untuk bagian ini. More information about translations

Tests for plugins are created in their own directory inside the plugins folder.

/app
     /plugins
         /pizza
             /tests
                  /cases
                  /fixtures
                  /groups

They work just like normal tests but you have to remember to use the naming conventions for plugins when importing classes. This is an example of a testcase for the PizzaOrder model from the plugins chapter of this manual. A difference from other tests is in the first line where 'Pizza.PizzaOrder' is imported. You also need to prefix your plugin fixtures with 'plugin.plugin_name.'.

<?php 
App::import('Model', 'Pizza.PizzaOrder');

class PizzaOrderCase extends CakeTestCase {

    // Plugin fixtures located in /app/plugins/pizza/tests/fixtures/
    var $fixtures = array('plugin.pizza.pizza_order');
    var $PizzaOrderTest;
    
    function testSomething() {
        // ClassRegistry makes the model use the test database connection
        $this->PizzaOrderTest =& ClassRegistry::init('PizzaOrder');

        // do some useful test here
        $this->assertTrue(is_object($this->PizzaOrderTest));
    }
}
?>
  1. <?php
  2. App::import('Model', 'Pizza.PizzaOrder');
  3. class PizzaOrderCase extends CakeTestCase {
  4. // Plugin fixtures located in /app/plugins/pizza/tests/fixtures/
  5. var $fixtures = array('plugin.pizza.pizza_order');
  6. var $PizzaOrderTest;
  7. function testSomething() {
  8. // ClassRegistry makes the model use the test database connection
  9. $this->PizzaOrderTest =& ClassRegistry::init('PizzaOrder');
  10. // do some useful test here
  11. $this->assertTrue(is_object($this->PizzaOrderTest));
  12. }
  13. }
  14. ?>

If you want to use plugin fixtures in the app tests you can reference them using 'plugin.pluginName.fixtureName' syntax in the $fixtures array.

That is all there is to it.