Ver Mensaje Individual
  #1 (permalink)  
Antiguo 29/05/2011, 09:10
Avatar de jerkan
jerkan
 
Fecha de Ingreso: septiembre-2005
Mensajes: 1.607
Antigüedad: 18 años, 7 meses
Puntos: 19
Test + Redirector

Hola,

estoy intentando testear el siguiente action helper
Código PHP:
Ver original
  1. class My_Helper_Message extends Zend_Controller_Action_Helper_Abstract
  2. {
  3.     /**
  4.      * sets message and redirect to message view
  5.      *
  6.      * @param   string $type        Message type
  7.      * @param   string $description Message description
  8.      * @param   string $autorefresh OPTIONAL Autorefresh URL
  9.      * @param   array  $links       OPTIONAL Links array. Each link should have label and href
  10.      * @param   string $title       OPTIONAL Title
  11.      * @return  void
  12.      */
  13.     public function setMessageAndRedirect($type,
  14.                                           $description,
  15.                                           $autorefresh = null,
  16.                                           $links = array(),
  17.                                           $title = null)
  18.     {
  19.         $translate = Zend_Registry::get('translate');
  20.         $session = new Zend_Session_Namespace('message');
  21.        
  22.         $session->type = $type;
  23.         $session->description = $description;
  24.         $session->autorefresh = $autorefresh;
  25.         $session->links = $links;
  26.         $session->title = $title;
  27.  
  28.         $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('Redirector');        
  29.         $redirector->gotoSimple('message', 'index');
  30.     }
  31.    
  32.     /**
  33.      * Strategy pattern: call helper as broker method
  34.      *
  35.      * @param   string $type        Message type
  36.      * @param   string $description Message description
  37.      * @param   string $autorefresh OPTIONAL Autorefresh URL
  38.      * @param   array  $links       OPTIONAL Links array.
  39.      *                              Each link should have label and href
  40.      * @param   string $title       OPTIONAL Title
  41.      * @return  void
  42.      */
  43.     public function direct($type, $description, $autorefresh = null,
  44.                            $links = array(), $title = null)
  45.     {
  46.         $this->setMessageAndRedirect($type, $description, $autorefresh,
  47.                                      $links, $title);
  48.     }  
  49. }
lo que haces es simplemente instanciar unas variables de sesión y redirigir al usuario.

El test luce así:
Código PHP:
Ver original
  1. class My_Helper_Message_Test
  2.     extends ControllerTestCase
  3. {    
  4.     public function testSetMessageOk()
  5.     {
  6.         $helper = new My_Helper_Message();
  7.        
  8.         $helper->setMessageAndRedirect(
  9.                   'warning',
  10.                   'message',
  11.                   null,
  12.                   array(
  13.                       array('label' => 'Link - Return to home',
  14.                             'href' => '/index/index')
  15.                       )
  16.                   );
  17.            
  18.         $this->assertRedirectTo('/index/message');
  19.     }
  20. }
Al ejecutarlo, me da el siguiente error:
Código:
1) My_Helper_Message_Test::testSetMessageOk
Zend_Controller_Router_Exception: Route default is not defined
Añadir que si comento el assertRedirectTo sigue saliendo el mismo error. Juraría que viene del redirector->gotoSimple.

¿Cómo puedo solucionarlo?

Gracias de antemano