Example #1
2
 /**
  * test that component components are not enabled in the collection.
  *
  * @return void
  */
 public function testInnerComponentsAreNotEnabled()
 {
     $mock = $this->getMock('Cake\\Event\\EventManager');
     $controller = new Controller();
     $controller->eventManager($mock);
     $mock->expects($this->once())->method('on')->with($this->isInstanceOf('TestApp\\Controller\\Component\\AppleComponent'));
     $Collection = new ComponentRegistry($controller);
     $Apple = $Collection->load('Apple');
     $this->assertInstanceOf('TestApp\\Controller\\Component\\OrangeComponent', $Apple->Orange, 'class is wrong');
 }
 /**
  * Constructor.
  *
  * @param \Cake\Controller\Controller $Controller Controller instance.
  */
 public function __construct(Controller $Controller = null)
 {
     if ($Controller) {
         $this->_Controller = $Controller;
         $this->eventManager($Controller->eventManager());
     }
 }
Example #3
0
 /**
  * Constructor
  *
  * @param \Cake\Controller\ComponentRegistry $collection Component Registry
  * @param array $config Array of configuration settings.
  */
 public function __construct(ComponentRegistry $collection, $config = [])
 {
     $this->_controller = $collection->getController();
     $this->_eventManager = $this->_controller->eventManager();
     parent::__construct($collection, $config);
     $this->_createCrudComponentInstance();
 }
Example #4
0
 /**
  * Constructor
  *
  * @param \Cake\Controller\ComponentRegistry $collection A ComponentCollection this component
  *   can use to lazy load its components.
  * @param array $config Array of configuration settings.
  */
 public function __construct(ComponentRegistry $collection, $config = [])
 {
     $config += ['actions' => [], 'listeners' => []];
     $config['actions'] = $this->normalizeArray($config['actions']);
     $config['listeners'] = $this->normalizeArray($config['listeners']);
     $this->_controller = $collection->getController();
     $this->_eventManager = $this->_controller->eventManager();
     parent::__construct($collection, $config);
 }
 /**
  * Add additional event spies to the controller/view event manager.
  *
  * @param \Cake\Event\Event $event A dispatcher event.
  * @return void
  */
 public function controllerSpy($event)
 {
     if (empty($event->data['controller'])) {
         return;
     }
     $this->_controller = $event->data['controller'];
     $events = $this->_controller->eventManager();
     $events->attach(function ($event, $viewFile) {
         $this->_viewName = $viewFile;
     }, 'View.beforeRender');
     $events->attach(function ($event, $viewFile) {
         $this->_layoutName = $viewFile;
     }, 'View.beforeLayout');
 }
Example #6
0
 /**
  * test that beforeRedirect callback returning false in controller
  *
  * @return void
  */
 public function testRedirectBeforeRedirectListenerReturnFalse()
 {
     $Response = $this->getMock('Cake\\Network\\Response', ['stop', 'header']);
     $Controller = new Controller(null, $Response);
     $Controller->eventManager()->attach(function ($event, $url, $response) {
         return false;
     }, 'Controller.beforeRedirect');
     $Controller->response->expects($this->never())->method('stop');
     $Controller->response->expects($this->never())->method('header');
     $Controller->response->expects($this->never())->method('statusCode');
     $result = $Controller->redirect('http://cakephp.org');
     $this->assertNull($result);
 }
Example #7
0
 /**
  * Set the controller associated with the collection.
  *
  * @param \Cake\Controller\Controller $controller Controller instance.
  * @return void
  */
 public function setController(Controller $controller)
 {
     $this->_Controller = $controller;
     $this->eventManager($controller->eventManager());
 }
Example #8
-1
 public function testRedirectBeforeRedirectListenerReturnResponse()
 {
     $Response = $this->getMockBuilder('Cake\\Network\\Response')->setMethods(['stop', 'header', 'statusCode'])->getMock();
     $Controller = new Controller(null, $Response);
     $newResponse = new Response();
     $Controller->eventManager()->on('Controller.beforeRedirect', function ($event, $url, $response) use($newResponse) {
         return $newResponse;
     });
     $result = $Controller->redirect('http://cakephp.org');
     $this->assertSame($newResponse, $result);
 }