Свежайшие Пирожки от CakePHP по-русски

Полнейшее руководство CakePHP 1.2 на русском языке, горячие новости и полезные статьи

Testing plugins

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.'.

Простой текст
  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.