/** * Generates the component for test * Options: * - mocks: specify mock methods for each objects * - componentOptopns: could be used for component options. * * @param $options * @return void */ public function generateComponent($options = []) { $options = Hash::merge(['mocks' => ['controller' => ['_stop', 'redirect']], 'componentOptions' => ['setDebuggerTypeAs' => false, 'setExceptionHandler' => false, 'setAuthenticate' => false], 'initialize' => true], $options); extract($options); $this->request = $this->getMockBuilder('CakeRequest')->setConstructorArgs(['/', false])->setMethods(Hash::get($mocks, 'request'))->getMock(); $this->response = $this->getMockBuilder('CakeResponse')->setMethods(Hash::get($mocks, 'response'))->getMock(); $this->controller = $this->getMockBuilder('Controller')->setConstructorArgs([$this->request, $this->response])->setMethods(Hash::get($mocks, 'controller'))->getMock(); $this->collection = $this->getMockBuilder('ComponentCollection')->setMethods(Hash::get($mocks, 'collection'))->getMock(); $this->collection->init($this->controller); $this->Api = $this->getMockBuilder('ApiComponent')->setConstructorArgs([$this->collection, $componentOptions])->setMethods(Hash::get($mocks, 'Api'))->getMock(); if ($initialize) { $this->Api->initialize($this->controller); } return $this->Api; }
public function setUp() { parent::setUp(); $this->Controller = new EnummPostsController(); $collection = new ComponentCollection(); $collection->init($this->Controller); }
public function setUp() { $this->Controller = $this->getMock('AccessLimitTestController', array('dispatchMethod'), array($this->getMock('CakeRequest', array('is'), array(null, false)), $this->getMock('CakeResponse'))); $this->Model = $this->getMockForModel('Security.AccessLimit'); ClassRegistry::addObject('AccessLimit', $this->Model); $collection = new ComponentCollection(); $collection->init($this->Controller); $this->Controller->Components->init($this->Controller); $this->AccessLimit = $this->Controller->AccessLimit; }
public function setUp() { parent::setUp(); $request = new CakeRequest(null, false); $request->params['ext'] = 'json'; $this->Controller = new TestRestController($request, $this->getMock('CakeResponse')); $collection = new ComponentCollection(); $collection->init($this->Controller); $this->Rest = new MockRestComponent($collection, $this->settings); $this->Rest->request = $request; $this->Rest->response = $this->getMock('CakeResponse'); $this->Controller->Components->init($this->Controller); }
/** * setUp method * * @return void */ public function setUp() { parent::setUp(); $request = new CakeRequest(null, false); $this->Controller = new UploaderTestController($request, $this->getMock('CakeResponse')); $collection = new ComponentCollection(); $collection->init($this->Controller); $this->Uploader = new TestUploaderComponent($collection); $this->Controller->Components->init($this->Controller); $this->Controller->startupProcess(); $this->upload1 = array('name' => 'Upload.jpg', 'type' => 'image/jpg', 'tmp_name' => $this->tmpDir . 'upload.jpg', 'error' => (int) 0, 'size' => filesize($this->tmpDir . 'upload.jpg')); $this->upload2 = array('name' => 'Upload File 2.txt', 'type' => 'text/plain', 'tmp_name' => $this->tmpDir . 'upload2.txt', 'error' => (int) 0, 'size' => filesize($this->tmpDir . 'upload2.txt')); $this->MediaUpload = ClassRegistry::init('MediaUpload'); $this->Controller->Uploader->setModel($this->MediaUpload); $this->uploadResult = null; }
/** * setUp method * * @return void */ public function setUp() { parent::setUp(); // Ensure all requests start with a valid token attached. $token = 'cc0a91cfa4f3b703531c1dc4f5f64b89'; $request = $this->getMock('CakeRequest', array('header'), array(null, false)); $request->staticExpects($this->any())->method('header')->with('Authorization')->will($this->returnValue('Bearer ' . $token)); $this->Controller = new StatelessAuthController($request, $this->getMock('CakeResponse')); $this->Controller->request = $request; $collection = new ComponentCollection(); $collection->init($this->Controller); $this->Component = new TestStatelessAuthComponent($collection); $this->Component->request = $request; $this->Component->response = $this->getMock('CakeResponse'); $this->Controller->Components->init($this->Controller); }
public function setUp() { parent::setUp(); // コンポーネントと偽のテストコントローラをセットアップする $request = new CakeRequest(); $response = $this->getMock('CakeResponse'); $this->Controller = new BcReplacePrefixTestController($request, $response); $collection = new ComponentCollection(); $collection->init($this->Controller); $this->BcReplacePrefix = new BcReplacePrefixComponent($collection); $this->BcReplacePrefix->request = $request; $this->BcReplacePrefix->response = $response; $this->Controller->Components->init($this->Controller); Router::reload(); Router::connect('/:controller/:action/*'); }
public function setUp() { @session_start(); parent::setUp(); // コンポーネントと偽のコントローラをセットアップする $request = new CakeRequest(); $response = $this->getMock('CakeResponse'); $this->Controller = new BcAuthConfigureTestController($request, $response); $collection = new ComponentCollection(); $collection->init($this->Controller); $this->BcAuthConfigure = new BcAuthConfigureComponent($collection); $this->BcAuthConfigure->request = $request; $this->BcAuthConfigure->response = $response; $this->Controller->Components->init($this->Controller); Router::reload(); Router::connect('/:controller/:action/*'); }
public function testConstructionMissing() { $collection = new ComponentCollection(); $collection->init($this->Controller); $this->setExpectedException('PermitException'); $testPermit = new TestPermitComponent($collection, array('path' => 'MockAuthTest', 'check' => 'id', 'isTest' => false, 'permit_include_path' => dirname(__FILE__) . DS . 'Config' . DS . 'permit.php')); }
/** * Test that the constructor sets the settings. * * @return void */ public function testConstructorSettings() { $settings = array('ajaxLayout' => 'test_ajax', 'viewClassMap' => array('json' => 'MyPlugin.MyJson')); $Collection = new ComponentCollection(); $Collection->init($this->Controller); $RequestHandler = new RequestHandlerComponent($Collection, $settings); $this->assertEquals('test_ajax', $RequestHandler->ajaxLayout); $this->assertEquals(array('json' => 'MyPlugin.MyJson'), $RequestHandler->settings['viewClassMap']); }
/** * Test that the constructor sets the settings. * * @return void */ public function testConstructorSettings() { $settings = array('ajaxLayout' => 'test_ajax'); $Collection = new ComponentCollection(); $Collection->init($this->Controller); $RequestHandler = new RequestHandlerComponent($Collection, $settings); $this->assertEquals('test_ajax', $RequestHandler->ajaxLayout); }
/** * setUp method * * @return void */ public function setUp() { parent::setUp(); $CakeRequest = new CakeRequest(null, false); $CakeResponse = $this->getMock('CakeResponse', array('send')); $this->Controller = new WizardTestController($CakeRequest, $CakeResponse); $ComponentCollection = new ComponentCollection(); $ComponentCollection->init($this->Controller); $this->Controller->Components->init($this->Controller); $this->Wizard = $this->Controller->Wizard; $this->Wizard->initialize($this->Controller); }
/** * setUp method * * @access public * @return void */ function setUp() { parent::setUp(); $this->_server = $_SERVER; $this->_env = $_ENV; Configure::write('Security.salt', 'YJfIxfs2guVoUubWDYhG93b0qyJfIxfs2guwvniR2G0FgaC9mi'); Configure::write('Security.cipherSeed', 770011223369876.0); $request = new CakeRequest(null, false); $this->Controller = new AuthTestController($request); $collection = new ComponentCollection(); $collection->init($this->Controller); $this->Auth = new TestAuthComponent($collection); $this->Auth->request = $request; $this->Auth->response = $this->getMock('CakeResponse'); $this->Controller->Components->init($this->Controller); $this->initialized = true; Router::reload(); ClassRegistry::init('AuthUser')->updateAll(array('password' => '"' . Security::hash('cake', null, true) . '"')); }
/** * setUp method * * @return void */ public function setUp() { parent::setUp(); Configure::write('Security.salt', 'YJfIxfs2guVoUubWDYhG93b0qyJfIxfs2guwvniR2G0FgaC9mi'); Configure::write('Security.cipherSeed', 770011223369876); $request = new CakeRequest(null, false); $this->Controller = new AuthTestController($request, $this->getMock('CakeResponse')); $collection = new ComponentCollection(); $collection->init($this->Controller); $this->Auth = new TestAuthComponent($collection); $this->Auth->request = $request; $this->Auth->response = $this->getMock('CakeResponse'); $this->Controller->Components->init($this->Controller); $this->initialized = true; Router::reload(); Router::connect('/:controller/:action/*'); $User = ClassRegistry::init('AuthUser'); $User->updateAll(array('password' => $User->getDataSource()->value(Security::hash('cake', null, true)))); }
/** * Test initialize with AppError controller * * @author Everton Yoshitani <*****@*****.**> * @since 1.0 * @return void */ public function testInitializeWithAppErrorController() { $Controller = new Controller(); $Controller->name = 'AppError'; $Collection = new ComponentCollection(); $Collection->init($Controller); $Component = $this->getMock('Component', array('getController'), array($Collection)); $ApiPhpAcl = new ApiPhpAcl($Component); $this->assertTrue($ApiPhpAcl->initialize($Component)); }
/** * setUp * * Setup the classes the crud component needs to be testable */ public function setUp() { require_once 'models.php'; parent::setUp(); CakeEventManager::instance(new TestCrudEventManager()); ConnectionManager::getDataSource('test')->getLog(); $this->model = new CrudExample(); $this->controller = $this->getMock('CrudController', array('header', 'redirect', 'render', '_stop'), array(), '', false); $this->controller->name = 'CrudExamples'; $this->request = new CakeRequest(); $response = new CakeResponse(); $this->controller->__construct($this->request, $response); $this->controller->methods = array(); $Collection = new ComponentCollection(); $Collection->init($this->controller); $settings = array('actions' => array('index', 'add', 'edit', 'view', 'delete')); $this->controller->Components = $Collection; $this->Crud = $this->getMock('TestCrudComponent', null, array($Collection, $settings)); $this->Crud->initialize($this->controller); }
/** * Given the name of a controller, return an instance of said controller * in the fastest method possible. * @param string $name The name of the controller. * @return Controller|null A controller instance if we can find or create one, null otherwise. */ private function __getController($name) { // First check to see if we have a cached copy of this controller if (array_key_exists($name, $this->__controllers)) { return $this->__controllers[$name]; } else { // Are we lucky enough to be checking isAuthorized on the // controller we're currently attached to? $controllerToUse = null; $controllerName = ''; if ($this->__currentController != null && $this->__currentController->name == $name) { // Awesome, this is not too slow $controllerToUse = $this->__currentController; $controllerName = $name; } if ($controllerToUse == null) { // Nope, we are left to construct the controller and everything $__controllers = App::objects('controller'); foreach ($__controllers as $controllerClassName) { $controllerName = str_replace('Controller', '', $controllerClassName); if (strtolower($controllerName) == strtolower($name)) { App::import('Controller', $controllerName); $controllerToUse = new $controllerClassName(); $collection = new ComponentCollection(); $collection->init($controllerToUse); $controllerToUse->Auth = new AuthComponent($collection); break; } } } if ($controllerToUse != null) { $this->__controllers[$controllerName] = $controllerToUse; return $controllerToUse; } } return null; }
/** * 指定ブログで公開状態の記事を取得 * * ページ編集画面等で利用する事ができる。 * ビュー: lib/Baser/Plugin/Blog/View/blog/{コンテンツテンプレート名}/posts.php * * 《利用例》 * $this->BcBaser->allBlogPosts('news', 3) * * @param int $contentsName 管理システムで指定したコンテンツ名 * @param int $num 記事件数(初期値 : 5) * @param array $options オプション(初期値 : array()) * - `tag` : タグで絞り込む場合にタグ名を指定(初期値 : null) * - `content` : content.id(ブログのID) で絞り込む場合に id を指定(初期値 : null) * - `post` : post.id(ブログ記事のID) で絞り込む場合に id を指定(初期値 : null) * - `category` : カテゴリで絞り込む場合にアルファベットのカテゴリ名指定(初期値 : null) * - `year` : 年で絞り込む場合に年を指定(初期値 : null) * - `month` : 月で絞り込む場合に月を指定(初期値 : null) * - `day` : 日で絞り込む場合に日を指定(初期値 : null) * - `keyword` : キーワードで絞り込む場合にキーワードを指定(初期値 : null) * - `template` : 読み込むテンプレート名を指定する場合にテンプレート名を指定(初期値 : null) * - `direction` : 並び順の方向を指定 [昇順:ASC or 降順:DESC](初期値 : null) * - `sort` : 並び替えの基準となるフィールドを指定(初期値 : null) * - `page` : ページ数を指定(初期値 : null) * @return void */ public function allBlogPosts($options = array()) { $options = array_merge(array('category' => null, 'tag' => null, 'year' => null, 'month' => null, 'day' => null, 'content' => null, 'post' => null, 'keyword' => null, 'template' => null, 'direction' => null, 'page' => null, 'sort' => null), $options); $BlogPost = ClassRegistry::init('Blog.BlogPost'); $conditions = $BlogPost->getConditionAllowPublish(); if ($options['content'] !== null) { $conditions['BlogContent.id'] = $options['content']; } if ($options['post'] !== null) { $conditions['BlogPost.id'] = $options['post']; } if ($options['tag'] !== null) { //SELECT blog_post_id FROM mysite_pg_blog_posts_blog_tags WHERE blog_tag_id IN (1,2,3) GROUP BY blog_post_id; $BlogPostsBlogTag = ClassRegistry::init('ExHelper.BlogPostsBlogTag'); $tags = $BlogPostsBlogTag->find('all', array('fields' => array('BlogPostsBlogTag.blog_post_id'), 'conditions' => array('BlogPostsBlogTag.blog_tag_id' => $options['tag']), 'group' => 'BlogPostsBlogTag.blog_post_id', 'cache' => false)); if (is_array($tags)) { $tagId = null; foreach ($tags as $val) { $tagId[] = $val['BlogPostsBlogTag']['blog_post_id']; } } if (!empty($conditions['BlogPost.id'])) { $postId = null; if (is_numeric($conditions['BlogPost.id'])) { foreach ($tagId as $val) { if ($val == $conditions['BlogPost.id']) { $postId = $val; break; } } } else { if (is_array($conditions['BlogPost.id'])) { foreach ($tagId as $val) { if (in_array($val, $conditions['BlogPost.id'])) { $postId[] = $val; } } } } $conditions['BlogPost.id'] = $postId; } else { $conditions['BlogPost.id'] = $tagId; } } //PetitCustomField に対応。。。 alter table形式のヤツがいいなやっぱり。 $posts = $BlogPost->find('all', array('fields' => array('BlogPost.id', 'BlogPost.name'), 'conditions' => $conditions, 'order' => array('BlogPost.posts_date DESC'), 'limit' => 100, 'cache' => false)); //pagination用セッティング $settings = array('page' => 1, 'limit' => 2, 'maxLimit' => 100, 'paramType' => 'querystring'); $ExHelperController = new ExHelperController(); // var_dump($this->request);exit; $ExHelperController->request = $this->request; //pagination componentで使っているため $ExHelperController->request->params['controller'] = substr($this->BcBaser->getUrl(), 1); $ExHelperController->request->params['action'] = null; $ComponentCollection = new ComponentCollection(); $ComponentCollection->init($ExHelperController); //利用するControllerをセットしてあげる。 $this->Paginator = new PaginatorComponent($ComponentCollection, $settings); $posts = $this->Paginator->paginate('BlogPost', $conditions); // 出力関数しかないので一回制御 ob_start(); $this->BcBaser->pagination(); // @todo 第2引数のdataの中身を解析する必要有 $this->allBlogPagination = ob_get_contents(); ob_end_clean(); return $posts; }
/** * Loads Model classes based on the uses property * see Controller::loadModel(); for more info. * Loads Components and prepares them for initialization. * * @return mixed true if models found and instance created. * @see Controller::loadModel() * @link http://book.cakephp.org/2.0/en/controllers.html#Controller::constructClasses * @throws MissingModelException */ public function constructClasses() { $this->_mergeControllerVars(); if ($this->uses) { $this->uses = (array) $this->uses; list(, $this->modelClass) = pluginSplit(reset($this->uses)); } $this->Components->init($this); return true; }
/** * @covers AnnotationParserTrait::getController */ public function testGetController() { $this->assertEquals($this->Controller, $this->traitObject->getController()); $traitObject = new TestAnnotationParserImpl($this->Controller); $collection = new ComponentCollection(); $collection->init($this->Controller); $traitObject->setCollection($collection); $this->assertEquals($this->Controller, $traitObject->getController()); }