All Crud.* events passes this object as subject Copyright 2010-2012, Nodes ApS. (http://www.nodesagency.com/) Licensed under The MIT License Redistributions of files must retain the above copyright notice.
Inheritance: extends stdClass
 /**
  * Helper method to generate and mock all the required
  * classes
  *
  * `$hasField` is a field => bool array with what
  * fields should exist according to 'hasField' model check
  *
  * @param array $hasField
  * @return array
  */
 protected function _mockClasses($hasField = array())
 {
     $CrudSubject = new CrudSubject();
     $Crud = $this->CrudMock->disableOriginalConstructor()->setMethods(array('action'))->getMock();
     $Model = $this->ModelMock->setConstructorArgs(array(array('table' => 'models', 'name' => 'Model', 'ds' => 'test')))->setMethods(array('hasField', 'getAssociated'))->getMock();
     $Model->expects($this->any())->method('getAssociated')->will($this->returnValue(array('Sample' => array(), 'Demo' => array(), 'User' => array())));
     $Model->alias = 'Model';
     $Controller = $this->ControllerMock->disableOriginalConstructor()->setMethods(null)->getMock();
     $Controller->Components = new StdClass();
     $Request = new CakeRequest();
     $Request->addDetector('api', array('callback' => function () {
         return true;
     }));
     $Paginator = $this->PaginatorMock->disableOriginalConstructor()->setMethods(null)->getMock();
     $Controller->Paginator = $Paginator;
     $CrudSubject->set(array('crud' => $Crud, 'request' => $Request, 'controller' => $Controller, 'action' => 'add', 'model' => $Model, 'modelClass' => $Model->name, 'args' => array(), 'query' => array('fields' => null, 'contain' => null)));
     $Action = $this->ActionMock->setConstructorArgs(array($CrudSubject))->setMethods(null)->getMock();
     $Listener = new ApiFieldFilterListener($CrudSubject);
     $Event = new CakeEvent('Test', $CrudSubject);
     $Crud->expects($this->any())->method('action')->will($this->returnValue($Action));
     $i = 0;
     foreach ($hasField as $field => $has) {
         $Model->expects($this->at($i))->method('hasField')->with($field)->will($this->returnValue($has));
         $i++;
     }
     return compact('Crud', 'Model', 'Controller', 'Paginator', 'Request', 'CrudSubject', 'Listener', 'Action', 'Event');
 }
Exemple #2
0
 /**
  * Create a CakeEvent subject with the required properties.
  *
  * @param array $additional Additional properties for the subject.
  * @return CrudSubject
  */
 public function getSubject($additional = array())
 {
     if (empty($this->_model) || empty($this->_modelName)) {
         $this->_setModelProperties();
     }
     $subject = new CrudSubject();
     $subject->crud = $this;
     $subject->controller = $this->_controller;
     $subject->model = $this->_model;
     $subject->modelClass = $this->_modelName;
     $subject->action = $this->_action;
     $subject->request = $this->_request;
     $subject->response = $this->_controller->response;
     $subject->set($additional);
     return $subject;
 }