/**
  * setUp method
  *
  * @access public
  * @return void
  */
 public function setUp()
 {
     $this->Controller = new ArticlesTestController();
     $this->Controller->constructClasses();
     $this->Controller->params = array('named' => array(), 'pass' => array(), 'url' => array());
     $this->Controller->modelClass = 'Article';
     $this->Controller->Archive = new ArchiveComponent($this->Controller->Components);
     $this->Controller->Archive->startup($this->Controller);
 }
Beispiel #2
0
 /**
  * Initialize
  *
  * @param type $stdout
  * @param type $stderr
  * @param type $stdin
  */
 public function __construct($stdout = null, $stderr = null, $stdin = null)
 {
     parent::__construct($stdout, $stderr, $stdin);
     $this->_CroogoPlugin = new CroogoPlugin();
     $this->_CroogoTheme = new CroogoTheme();
     $CakeRequest = new CakeRequest();
     $CakeResponse = new CakeResponse();
     $this->_Controller = new AppController($CakeRequest, $CakeResponse);
     $this->_Controller->constructClasses();
     $this->_Controller->startupProcess();
     $this->_CroogoPlugin->setController($this->_Controller);
     $this->initialize();
 }
 /**
  * Override this method to ensure that some components get loaded
  * conditionally.
  *
  * @access  public
  */
 public function constructClasses()
 {
     if (Configure::read('debug') > 0) {
         $this->components[] = 'DebugKit.Toolbar';
     }
     parent::constructClasses();
 }
 protected function _createController($data)
 {
     $request = new CakeRequest();
     $request->data = $data;
     $controller = new Controller($request);
     $controller->components = array('Croogo.BulkProcess');
     $controller->constructClasses();
     $controller->startupProcess();
     return $controller;
 }
 public function constructClasses()
 {
     if (Configure::read('debug')) {
         $className = get_class($this);
         if (substr($className, 0, 5) != 'Mock_') {
             //inside PHPUnit mocks, do not use DebugKit Toolbar
             $this->components[] = 'DebugKit.Toolbar';
         }
     }
     parent::constructClasses();
 }
Beispiel #6
0
 /**
  * When methods are now present in a controller
  * scaffoldView is used to call default Scaffold methods if:
  * <code>
  * var $scaffold;
  * </code>
  * is placed in the controller's class definition.
  *
  * @param string $url
  * @param string $controller_class
  * @param array $params
  * @since Cake v 0.10.0.172
  * @access private
  */
 function __scaffold($params)
 {
     if (!in_array('Form', $this->controllerClass->helpers)) {
         $this->controllerClass->helpers[] = 'Form';
     }
     if ($this->controllerClass->constructClasses()) {
         $db =& ConnectionManager::getDataSource($this->controllerClass->{$this->modelKey}->useDbConfig);
         if (isset($db)) {
             if ($params['action'] === 'index' || $params['action'] === 'list' || $params['action'] === 'view' || $params['action'] === 'add' || $params['action'] === 'create' || $params['action'] === 'edit' || $params['action'] === 'update' || $params['action'] === 'delete') {
                 switch ($params['action']) {
                     case 'index':
                         $this->__scaffoldIndex($params);
                         break;
                     case 'view':
                         $this->__scaffoldView($params);
                         break;
                     case 'list':
                         $this->__scaffoldIndex($params);
                         break;
                     case 'add':
                         $this->__scaffoldForm($params, 'add');
                         break;
                     case 'edit':
                         $this->__scaffoldForm($params, 'edit');
                         break;
                     case 'create':
                         $this->__scaffoldSave($params, 'create');
                         break;
                     case 'update':
                         $this->__scaffoldSave($params, 'update');
                         break;
                     case 'delete':
                         $this->__scaffoldDelete($params);
                         break;
                 }
             } else {
                 return $this->cakeError('missingAction', array(array('className' => Inflector::camelize($params['controller'] . "Controller"), 'base' => $this->controllerClass->base, 'action' => $params['action'], 'webroot' => $this->controllerClass->webroot)));
             }
         } else {
             return $this->cakeError('missingDatabase', array(array('webroot' => $this->controllerClass->webroot)));
         }
     } else {
         return $this->cakeError('missingModel', array(array('className' => $this->modelKey, 'webroot' => '', 'base' => $this->base)));
     }
 }
 public function testPagination()
 {
     $this->markTestSkipped('Needs revision');
     $objController = new Controller(new CakeRequest('/'), new CakeResponse());
     $objController->layout = 'ajax';
     $objController->uses = array('User');
     $objController->constructClasses();
     $objController->request->url = '/';
     $objController->paginate = array('fields' => array('username'), 'contain' => false, 'link' => array('Profile' => array('fields' => array('biography'))), 'limit' => 2);
     $arrayResult = $objController->paginate('User');
     $this->assertEquals($objController->params['paging']['User']['count'], 4, 'Paging: total records count: %s');
     // Pagination with order on a row from table joined with Linkable
     $objController->paginate = array('fields' => array('id'), 'contain' => false, 'link' => array('Profile' => array('fields' => array('user_id'))), 'limit' => 2, 'order' => 'Profile.user_id DESC');
     $arrayResult = $objController->paginate('User');
     $arrayExpected = array(0 => array('User' => array('id' => 4), 'Profile' => array('user_id' => 4)), 1 => array('User' => array('id' => 3), 'Profile' => array('user_id' => 3)));
     $this->assertEquals($arrayResult, $arrayExpected, 'Paging with order on join table row: %s');
     // Pagination without specifying any fields
     $objController->paginate = array('contain' => false, 'link' => array('Profile'), 'limit' => 2, 'order' => 'Profile.user_id DESC');
     $arrayResult = $objController->paginate('User');
     $this->assertEquals($objController->params['paging']['User']['count'], 4, 'Paging without any field lists: total records count: %s');
 }
 /**
 * Initializes the components and models a controller will be using.
 * Triggers the controller action, and invokes the rendering if Controller::$autoRender is true and echo's the output.
 * Otherwise the return value of the controller action are returned.
 *
 * Works like {@see Dispatcher::_invoke()} but returns the full response instead the body only.
 *
 * Bancha needs to overwrite this method because we need the full response object not only the body of the response
 * object on return.
 *
 * @param Controller $controller Controller to invoke
 * @param CakeRequest $request The request object to invoke the controller for.
 * @param CakeResponse $response The response object to receive the output
 * @return CakeResponse te resulting response object
 */
 protected function _invoke(Controller $controller, CakeRequest $request, CakeResponse $response)
 {
     $controller->constructClasses();
     $controller->startupProcess();
     $render = true;
     $result = $controller->invokeAction($request);
     if ($result instanceof CakeResponse) {
         $render = false;
         $response = $result;
     }
     if ($render && $controller->autoRender) {
         $response = $controller->render();
     } elseif ($response->body() === null) {
         $response->body($result);
     }
     $controller->shutdownProcess();
     if (isset($request->params['return'])) {
         return $response;
         // <-------------- only this line is changed, original: return $response->body();
     }
     $response->send();
 }
 /**
  * testPaginateMaxLimit
  *
  * @return void
  */
 public function testPaginateMaxLimit()
 {
     $Controller = new Controller($this->request);
     $Controller->uses = array('PaginatorControllerPost', 'ControllerComment');
     $Controller->passedArgs[] = '1';
     $Controller->constructClasses();
     $Controller->request->params['named'] = array('contain' => array('ControllerComment'), 'limit' => '1000');
     $result = $Controller->paginate('PaginatorControllerPost');
     $this->assertEquals($Controller->params['paging']['PaginatorControllerPost']['options']['limit'], 100);
     $Controller->request->params['named'] = array('contain' => array('ControllerComment'), 'limit' => '1000', 'maxLimit' => 1000);
     $result = $Controller->paginate('PaginatorControllerPost');
     $this->assertEquals($Controller->params['paging']['PaginatorControllerPost']['options']['limit'], 100);
     $Controller->request->params['named'] = array('contain' => array('ControllerComment'), 'limit' => '10');
     $result = $Controller->paginate('PaginatorControllerPost');
     $this->assertEquals($Controller->params['paging']['PaginatorControllerPost']['options']['limit'], 10);
     $Controller->request->params['named'] = array('contain' => array('ControllerComment'), 'limit' => '1000');
     $Controller->paginate = array('maxLimit' => 2000, 'paramType' => 'named');
     $result = $Controller->paginate('PaginatorControllerPost');
     $this->assertEquals($Controller->params['paging']['PaginatorControllerPost']['options']['limit'], 1000);
     $Controller->request->params['named'] = array('contain' => array('ControllerComment'), 'limit' => '5000');
     $result = $Controller->paginate('PaginatorControllerPost');
     $this->assertEquals($Controller->params['paging']['PaginatorControllerPost']['options']['limit'], 2000);
 }
Beispiel #10
0
 /**
  * test that using Controller::paginate() falls back to PaginatorComponent
  *
  * @return void
  */
 function testPaginateBackwardsCompatibility()
 {
     $request = new CakeRequest('controller_posts/index');
     $request->params['pass'] = $request->params['named'] = array();
     $Controller = new Controller($request);
     $Controller->uses = array('ControllerPost', 'ControllerComment');
     $Controller->passedArgs[] = '1';
     $Controller->params['url'] = array();
     $Controller->constructClasses();
     $expected = array('page' => 1, 'limit' => 20, 'maxLimit' => 100, 'paramType' => 'named');
     $this->assertEqual($Controller->paginate, $expected);
     $results = Set::extract($Controller->paginate('ControllerPost'), '{n}.ControllerPost.id');
     $this->assertEqual($results, array(1, 2, 3));
     $Controller->passedArgs = array();
     $Controller->paginate = array('limit' => '-1');
     $this->assertEqual($Controller->paginate, array('limit' => '-1'));
     $Controller->paginate('ControllerPost');
     $this->assertIdentical($Controller->params['paging']['ControllerPost']['page'], 1);
     $this->assertIdentical($Controller->params['paging']['ControllerPost']['pageCount'], 3);
     $this->assertIdentical($Controller->params['paging']['ControllerPost']['prevPage'], false);
     $this->assertIdentical($Controller->params['paging']['ControllerPost']['nextPage'], true);
 }
 public function constructClasses()
 {
     parent::constructClasses();
     $this->Auth = $this->CustomAuth;
 }
Beispiel #12
0
 /**
  * testPaginate method
  *
  * @access public
  * @return void
  */
 function testPaginate()
 {
     $Controller = new Controller();
     $Controller->uses = array('Article');
     $Controller->passedArgs[] = '1';
     $Controller->params['url'] = array();
     $Controller->constructClasses();
     $Controller->paginate = array('Article' => array('fields' => array('title'), 'contain' => array('User(user)')));
     $result = $Controller->paginate('Article');
     $expected = array(array('Article' => array('title' => 'First Article'), 'User' => array('user' => 'mariano', 'id' => 1)), array('Article' => array('title' => 'Second Article'), 'User' => array('user' => 'larry', 'id' => 3)), array('Article' => array('title' => 'Third Article'), 'User' => array('user' => 'mariano', 'id' => 1)));
     $this->assertEqual($result, $expected);
     $r = $Controller->Article->find('all');
     $this->assertTrue(Set::matches('/Article[id=1]', $r));
     $this->assertTrue(Set::matches('/User[id=1]', $r));
     $this->assertTrue(Set::matches('/Tag[id=1]', $r));
     $Controller->paginate = array('Article' => array('contain' => array('Comment(comment)' => 'User(user)'), 'fields' => array('title')));
     $result = $Controller->paginate('Article');
     $expected = array(array('Article' => array('title' => 'First Article', 'id' => 1), 'Comment' => array(array('comment' => 'First Comment for First Article', 'user_id' => 2, 'article_id' => 1, 'User' => array('user' => 'nate')), array('comment' => 'Second Comment for First Article', 'user_id' => 4, 'article_id' => 1, 'User' => array('user' => 'garrett')), array('comment' => 'Third Comment for First Article', 'user_id' => 1, 'article_id' => 1, 'User' => array('user' => 'mariano')), array('comment' => 'Fourth Comment for First Article', 'user_id' => 1, 'article_id' => 1, 'User' => array('user' => 'mariano')))), array('Article' => array('title' => 'Second Article', 'id' => 2), 'Comment' => array(array('comment' => 'First Comment for Second Article', 'user_id' => 1, 'article_id' => 2, 'User' => array('user' => 'mariano')), array('comment' => 'Second Comment for Second Article', 'user_id' => 2, 'article_id' => 2, 'User' => array('user' => 'nate')))), array('Article' => array('title' => 'Third Article', 'id' => 3), 'Comment' => array()));
     $this->assertEqual($result, $expected);
     $r = $Controller->Article->find('all');
     $this->assertTrue(Set::matches('/Article[id=1]', $r));
     $this->assertTrue(Set::matches('/User[id=1]', $r));
     $this->assertTrue(Set::matches('/Tag[id=1]', $r));
     $Controller->Article->unbindModel(array('hasMany' => array('Comment'), 'belongsTo' => array('User'), 'hasAndBelongsToMany' => array('Tag')), false);
     $Controller->Article->bindModel(array('hasMany' => array('Comment'), 'belongsTo' => array('User')), false);
     $Controller->paginate = array('Article' => array('contain' => array('Comment(comment)', 'User(user)'), 'fields' => array('title')));
     $r = $Controller->paginate('Article');
     $this->assertTrue(Set::matches('/Article[id=1]', $r));
     $this->assertTrue(Set::matches('/User[id=1]', $r));
     $this->assertTrue(Set::matches('/Comment[article_id=1]', $r));
     $this->assertFalse(Set::matches('/Comment[id=1]', $r));
     $r = $this->Article->find('all');
     $this->assertTrue(Set::matches('/Article[id=1]', $r));
     $this->assertTrue(Set::matches('/User[id=1]', $r));
     $this->assertTrue(Set::matches('/Comment[article_id=1]', $r));
     $this->assertTrue(Set::matches('/Comment[id=1]', $r));
 }
Beispiel #13
0
 /**
  * test paginate() and virtualField overlapping with real fields.
  *
  * @return void
  */
 public function testPaginateOrderVirtualFieldSharedWithRealField()
 {
     $Controller = new Controller($this->request);
     $Controller->uses = array('PaginatorControllerPost', 'PaginatorControllerComment');
     $Controller->constructClasses();
     $Controller->PaginatorControllerComment->virtualFields = array('title' => 'PaginatorControllerComment.comment');
     $Controller->PaginatorControllerComment->bindModel(array('belongsTo' => array('PaginatorControllerPost' => array('className' => 'PaginatorControllerPost', 'foreignKey' => 'article_id'))), false);
     $Controller->paginate = array('fields' => array('PaginatorControllerComment.id', 'title', 'PaginatorControllerPost.title'));
     $Controller->passedArgs = array('sort' => 'PaginatorControllerPost.title', 'dir' => 'asc');
     $result = $Controller->paginate('PaginatorControllerComment');
     $this->assertEquals(Set::extract($result, '{n}.PaginatorControllerComment.id'), array(1, 2, 3, 4, 5, 6));
 }
Beispiel #14
0
 /**
  * testRequestHandlerPrefers method
  *
  * @access public
  * @return void
  */
 function testRequestHandlerPrefers()
 {
     Configure::write('debug', 2);
     $Controller = new Controller();
     $Controller->components = array("RequestHandler");
     $Controller->modelClass = 'ControllerPost';
     $Controller->params['url']['ext'] = 'rss';
     $Controller->constructClasses();
     $Controller->Component->initialize($Controller);
     $Controller->beforeFilter();
     $Controller->Component->startup($Controller);
     $this->assertEqual($Controller->RequestHandler->prefers(), 'rss');
     unset($Controller);
 }
 /**
  * Initializes the components and models a controller will be using.
  * Triggers the controller action, and invokes the rendering if Controller::$autoRender is true and echo's the output.
  * Otherwise the return value of the controller action are returned.
  *
  * @param Controller $controller Controller to invoke
  * @param CakeRequest $request The request object to invoke the controller for.
  * @param CakeResponse $response The response object to receive the output
  * @return CakeResponse the resulting response object
  */
 protected function _invoke(Controller $controller, CakeRequest $request, CakeResponse $response)
 {
     $controller->constructClasses();
     $controller->startupProcess();
     $render = true;
     $result = $controller->invokeAction($request);
     if ($result instanceof CakeResponse) {
         $render = false;
         $response = $result;
     }
     if ($render && $controller->autoRender) {
         $response = $controller->render();
     } elseif (!$result instanceof CakeResponse && $response->body() === null) {
         $response->body($result);
     }
     $controller->shutdownProcess();
     return $response;
 }
 public function testPagination()
 {
     $objController = new Controller(new CakeRequest(), new CakeResponse());
     $objController->layout = 'ajax';
     $objController->uses = ['LinkableUser'];
     $objController->constructClasses();
     $objController->request->url = '/';
     $objController->paginate = ['fields' => ['username'], 'contain' => false, 'link' => ['LinkableProfile' => ['fields' => ['biography']]], 'limit' => 2];
     $arrayResult = $objController->paginate('LinkableUser');
     $this->assertEquals(4, $objController->params['paging']['LinkableUser']['count'], 'Paging: total records count: %s');
     // Pagination with order on a row from table joined with Linkable
     $objController->paginate = ['fields' => ['id'], 'contain' => false, 'link' => ['LinkableProfile' => ['fields' => ['user_id']]], 'limit' => 2, 'order' => 'LinkableProfile.user_id DESC'];
     $arrayResult = $objController->paginate('LinkableUser');
     $arrayExpected = [0 => ['LinkableUser' => ['id' => 4], 'LinkableProfile' => ['user_id' => 4]], 1 => ['LinkableUser' => ['id' => 3], 'LinkableProfile' => ['user_id' => 3]]];
     $this->assertEquals($arrayExpected, $arrayResult, 'Paging with order on join table row: %s');
     // Pagination without specifying any fields
     $objController->paginate = ['contain' => false, 'link' => ['LinkableProfile'], 'limit' => 2, 'order' => 'LinkableProfile.user_id DESC'];
     $arrayResult = $objController->paginate('LinkableUser');
     $this->assertEquals(4, $objController->params['paging']['LinkableUser']['count'], 'Paging without any field lists: total records count: %s');
 }
/**
 * Initialize the CakePHP controllers, disable the autoRender, add Cpamf.AmfAuth
 * component to a controller. This component handles the redirect attempts, and
 * thows and exception when Auth component, or controller attempts to redirect.
 * Initializes all components for the controller, and calls beforeFilter.
 * 
 * @param Controller $controller
 */
function initCakeController($controller)
{
    $controller->autoRender = false;
    $controller->components = array_merge($controller->components, array('Cpamf.AmfAuth'));
    $controller->constructClasses();
    $controller->Component->initialize($controller);
    $controller->beforeFilter();
    $controller->Component->startup($controller);
}
Beispiel #18
0
 /**
  * Process all the models attached to a controller
  * and generate a fixture list.
  *
  * @param Controller $subject A controller to pull model names off of.
  * @return void
  * @access protected
  */
 function _processController(&$subject)
 {
     $subject->constructClasses();
     $models = array(Inflector::classify($subject->name));
     if (!empty($subject->uses)) {
         $models = $subject->uses;
     }
     foreach ($models as $model) {
         $this->_processModel($subject->{$model});
     }
 }
Beispiel #19
0
 /**
  * test File upload input on a model not used in create();
  *
  * @return void
  */
 function testFileUploadOnOtherModel()
 {
     ClassRegistry::removeObject('view');
     $controller = new Controller();
     $controller->name = 'ValidateUsers';
     $controller->uses = array('ValidateUser');
     $controller->constructClasses();
     $view = new View($controller, true);
     $this->Form->create('ValidateUser', array('type' => 'file'));
     $result = $this->Form->file('ValidateProfile.city');
     $expected = array('input' => array('type' => 'file', 'name' => 'data[ValidateProfile][city]', 'value' => '', 'id' => 'ValidateProfileCity'));
     $this->assertTags($result, $expected);
 }
    /**
     * testGenerateFileFileExists
     *
     * Running the shell should only add missing translations,
     * Without removing or corrupting existing translations.
     *
     * @return void
     */
    public function testGenerateFileFileExists()
    {
        $expected = <<<END
<?php

/**
 * Example CRUD Component translations
 */
__d('crud', 'Some other translation');
__d('crud', 'Invalid id');
__d('crud', 'Not found');
__d('crud', 'Method not allowed. This action permits only {methods}');
__d('crud', 'Successfully created example');
__d('crud', 'Could not create example');
__d('crud', 'Successfully updated example');
__d('crud', 'Could not update example');
__d('crud', 'Successfully deleted example');
END;
        $path = TMP . 'crud_translations_shell_test.php';
        file_put_contents($path, $expected);
        $controller = new Controller(new CakeRequest());
        $controller->Example = new StdClass();
        // dummy
        $controller->Example->name = 'Example';
        $controller->modelClass = 'Example';
        $controller->components = array('Crud.Crud' => array('actions' => array('index', 'add', 'edit', 'view', 'delete')));
        $controller->constructClasses();
        $controller->startupProcess();
        $this->Shell->expects($this->once())->method('_loadController')->will($this->returnValue($controller));
        $this->Shell->expects($this->once())->method('_getControllers')->will($this->returnValue(array('Example')));
        $this->Shell->path($path);
        $this->Shell->generate();
        $this->assertFileExists($path);
        $onlyNewTranslation = "\n__d('crud', 'Could not delete example');";
        $expected .= $onlyNewTranslation;
        $contents = file_get_contents($path);
        $this->assertTextEquals(trim($expected), trim($contents), "Only expected one translation to be added");
        unlink($path);
    }
Beispiel #21
0
 /**
  * Initializes the components and models a controller will be using.
  * Triggers the controller action, and invokes the rendering if Controller::$autoRender is true and echo's the output.
  * Otherwise the return value of the controller action are returned.
  *
  * @param Controller $controller Controller to invoke
  * @param CakeRequest $request The request object to invoke the controller for.
  * @return string Output as sent by controller
  * @throws MissingActionException when the action being called is missing.
  */
 protected function _invoke(Controller $controller, CakeRequest $request)
 {
     $controller->constructClasses();
     $controller->startupProcess();
     $methods = array_flip($controller->methods);
     if (!isset($methods[$request->params['action']])) {
         if ($controller->scaffold !== false) {
             App::import('Controller', 'Scaffold', false);
             return new Scaffold($controller, $request);
         }
         throw new MissingActionException(array('controller' => Inflector::camelize($request->params['controller']) . "Controller", 'action' => $request->params['action']));
     }
     $result = call_user_func_array(array(&$controller, $request->params['action']), $request->params['pass']);
     $response = $controller->getResponse();
     if ($controller->autoRender) {
         $controller->render();
     } elseif ($response->body() === null) {
         $response->body($result);
     }
     $controller->shutdownProcess();
     if (isset($request->params['return'])) {
         return $response->body();
     }
     $response->send();
 }
 /**
  * test that using Controller::paginate() falls back to PaginatorComponent
  *
  * @return void
  */
 public function testPaginateBackwardsCompatibility()
 {
     $request = new CakeRequest('controller_posts/index');
     $request->params['pass'] = $request->params['named'] = array();
     $response = $this->getMock('CakeResponse', array('httpCodes'));
     $Controller = new Controller($request, $response);
     $Controller->uses = array('ControllerPost', 'ControllerComment');
     $Controller->passedArgs[] = '1';
     $Controller->params['url'] = array();
     $Controller->constructClasses();
     $expected = array('page' => 1, 'limit' => 20, 'maxLimit' => 100, 'paramType' => 'named');
     $this->assertEquals($expected, $Controller->paginate);
     $results = Hash::extract($Controller->paginate('ControllerPost'), '{n}.ControllerPost.id');
     $this->assertEquals(array(1, 2, 3), $results);
     $Controller->passedArgs = array();
     $Controller->paginate = array('limit' => '-1');
     $this->assertEquals(array('limit' => '-1'), $Controller->paginate);
     $Controller->paginate('ControllerPost');
     $this->assertSame($Controller->params['paging']['ControllerPost']['page'], 1);
     $this->assertSame($Controller->params['paging']['ControllerPost']['pageCount'], 3);
     $this->assertSame($Controller->params['paging']['ControllerPost']['prevPage'], false);
     $this->assertSame($Controller->params['paging']['ControllerPost']['nextPage'], true);
 }
Beispiel #23
0
 /**
  * Overrides `Controller::constructClasses()` to apply the 'Controller.constructClasses'
  * event's results.
  *
  * @return  void
  */
 public function constructClasses()
 {
     $timer = 'controllerConstructClasses';
     Common::startTimer($timer, __d('common', "Event: Controller.constructClasses"));
     $properties = array('components', 'helpers');
     $result = $this->triggerEvent('Controller.constructClasses', $this);
     $this->_mergeControllerVars();
     foreach ($properties as $property) {
         if (!isset($result[$property])) {
             continue;
         }
         $this->{$property} = Hash::merge(Hash::normalize($result[$property]), Hash::normalize((array) $this->{$property}));
         unset($result[$property]);
     }
     $this->_set($result);
     Common::stopTimer($timer);
     parent::constructClasses();
 }
 /**
  * Ensure that _mergeControllerVars is not being greedy and merging with
  * AppController when you make an instance of Controller
  *
  * @return void
  */
 public function testMergeVarsNotGreedy()
 {
     $Controller = new Controller();
     $Controller->components = array();
     $Controller->uses = array();
     $Controller->constructClasses();
     $this->assertFalse(isset($Controller->Session));
 }
Beispiel #25
0
 public function testPaginate()
 {
     $Controller = new Controller();
     $Controller->uses = array('TestAddress');
     $Controller->params['url'] = array();
     $Controller->constructClasses();
     $Controller->paginate = array('TestAddress' => array('near', 'fields' => array('address'), 'limit' => 2, 'address' => '1209 La Brad Lane, Tampa, FL'));
     $result = $Controller->paginate('TestAddress');
     $this->assertTrue(!empty($result));
     if (!empty($result)) {
         $result = Set::combine($result, '/' . $this->Address->alias . '/address', '/' . $this->Address->alias . '/distance');
         foreach ($result as $key => $distance) {
             $result[$key] = round($distance, 3);
         }
         $expected = array('14348 N Rome Ave, Tampa, 33613 FL' => 0.257, '1180 Magdalene Hill, Florida, US' => 0.499);
         $this->assertEqual($result, $expected);
     }
     $Controller->paginate = array('TestAddress' => array('near', 'fields' => array('address'), 'limit' => 2, 'address' => '1209 La Brad Lane, Tampa, FL', 'page' => 2));
     $result = $Controller->paginate('TestAddress');
     $this->assertTrue(!empty($result));
     if (!empty($result)) {
         $result = Set::combine($result, '/' . $this->Address->alias . '/address', '/' . $this->Address->alias . '/distance');
         foreach ($result as $key => $distance) {
             $result[$key] = round($distance, 3);
         }
         $expected = array('9106 El Portal Dr, Tampa, FL' => 5.331);
         $this->assertEqual($result, $expected);
     }
     $Controller->paginate = array('TestAddress' => array('near', 'fields' => array('address'), 'limit' => 2, 'address' => '1209 La Brad Lane, Tampa, FL', 'unit' => 'm'));
     $result = $Controller->paginate('TestAddress');
     $this->assertTrue(!empty($result));
     if (!empty($result)) {
         $result = Set::combine($result, '/' . $this->Address->alias . '/address', '/' . $this->Address->alias . '/distance');
         foreach ($result as $key => $distance) {
             $result[$key] = round($distance, 3);
         }
         $expected = array('14348 N Rome Ave, Tampa, 33613 FL' => 0.16, '1180 Magdalene Hill, Florida, US' => 0.31);
         $this->assertEqual($result, $expected);
     }
     $Controller->paginate = array('TestAddress' => array('near', 'fields' => array('address'), 'limit' => 2, 'address' => '1209 La Brad Lane, Tampa, FL', 'unit' => 'm', 'distance' => 0.25));
     $result = $Controller->paginate('TestAddress');
     $this->assertTrue(!empty($result));
     if (!empty($result)) {
         $result = Set::combine($result, '/' . $this->Address->alias . '/address', '/' . $this->Address->alias . '/distance');
         foreach ($result as $key => $distance) {
             $result[$key] = round($distance, 3);
         }
         $expected = array('14348 N Rome Ave, Tampa, 33613 FL' => 0.16);
         $this->assertEqual($result, $expected);
     }
 }
 /**
  * test paginate() and custom find with returning other query on count operation,
  * to make sure the correct count is returned.
  *
  * @return void
  */
 public function testPaginateCustomFindCount()
 {
     $Controller = new Controller($this->request);
     $Controller->uses = array('PaginatorCustomPost');
     $Controller->constructClasses();
     $data = array('author_id' => 2, 'title' => 'Fourth Article', 'body' => 'Article Body, unpublished', 'published' => 'N');
     $Controller->PaginatorCustomPost->create($data);
     $result = $Controller->PaginatorCustomPost->save();
     $this->assertTrue(!empty($result));
     $Controller->paginate = array('totalsOperation', 'limit' => 2);
     $result = $Controller->paginate();
     $expected = array(array('PaginatorCustomPost' => array('author_id' => '1', 'total_posts' => '2'), 'Author' => array('user' => 'mariano')), array('PaginatorCustomPost' => array('author_id' => '2', 'total_posts' => '1'), 'Author' => array('user' => 'nate')));
     $this->assertEquals($expected, $result);
     $result = $Controller->params['paging']['PaginatorCustomPost'];
     $this->assertEquals(2, $result['current']);
     $this->assertEquals(3, $result['count']);
     $this->assertEquals(2, $result['pageCount']);
     $this->assertTrue($result['nextPage']);
     $this->assertFalse($result['prevPage']);
 }
Beispiel #27
0
 /**
  * Loads Components and prepares them for initialization.
  * Models will be lazy loaded by default
  *
  * @return mixed true if models found and instance created, or cakeError if models not found.
  * @access public
  * @see Controller::loadModel()
  * @link http://book.cakephp.org/view/977/Controller-Methods#constructClasses-986
  */
 function constructClasses()
 {
     if (SlExtensions::getInstance()->dependencyError) {
         $params = SlExtensions::getInstance()->dependencyError;
         SlExtensions::getInstance()->dependencyError = false;
         $this->cakeError('missingDependence', $params);
     }
     SlExtensions::trigger('constructClasses', $this);
     $this->__mergeVars();
     // Component class sets components by reference, hence triggering an uneeded read operation
     // Avoid magic __get() method calls by setting null values
     $this->components = Set::normalize($this->components);
     foreach ($this->components as $component => $settings) {
         if (strpos($component, '.') !== false) {
             list($plugin, $component) = explode('.', $component);
         }
         $this->{$component} = null;
     }
     if (!SlConfigure::read('Sl.options.lazyLoadModels')) {
         return parent::constructClasses();
     }
     $this->Component->init($this);
     if ($this->uses !== null || $this->uses !== array()) {
         if ($this->uses) {
             $uses = is_array($this->uses) ? $this->uses : array($this->uses);
             $modelClassName = $uses[0];
             if (strpos($uses[0], '.') !== false) {
                 list($plugin, $modelClassName) = explode('.', $uses[0]);
             }
             $this->modelClass = $modelClassName;
         }
     }
     return true;
 }