Example #1
0
 /**
  * test _defaultSaveCallback() method
  *
  * @test
  */
 public function _defaultSaveCallback()
 {
     $this->generateComponent(['mocks' => ['Api' => ['_getDefaultModel']]]);
     $mock = $this->getMockBuilder('stdclass')->setMethods(['saveAll'])->getMock();
     $mock->expects($this->once())->method('saveAll')->with('testData', ['testOptions'])->will($this->returnValue(true));
     $this->Api->expects($this->once())->method('_getDefaultModel')->will($this->returnValue($mock));
     $result = $this->Api->dispatchMethod('_defaultSaveCallback', ['testData', ['testOptions']]);
 }
 public function startup(Controller $Controller)
 {
     $this->Controller = $Controller;
     $this->Model = ClassRegistry::init($this->modelClass);
     $this->constructLimits();
     $action = strtolower($Controller->request->params['action']);
     $types = array_map('strtolower', array_keys($this->settings));
     foreach ($types as $type) {
         if (!$Controller->request->is($type) || empty($this->{$type}[$action])) {
             continue;
         }
         extract($this->{$type}[$action]);
         if (!$this->limit(compact('limit'))) {
             list($method, $params) = (array) $callback;
             $Controller->dispatchMethod($method, $params);
             return false;
         }
         if ('get' == $type) {
             $this->fail(compact('duration'));
         }
     }
     return true;
 }
 function dispatchMethod($method, $params = array())
 {
     if ($this->_cancelAction === true) {
         return false;
     }
     return parent::dispatchMethod($method, $params);
 }