Example #1
0
 /**
  * Test that view variables are being set after the beforeRender event gets dispatched
  *
  * @return void
  */
 public function testBeforeRenderViewVariables()
 {
     $controller = new PostsController();
     $controller->eventManager()->on('Controller.beforeRender', function (Event $event) {
         /* @var Controller $controller */
         $controller = $event->subject();
         $controller->set('testVariable', 'test');
     });
     $controller->render('index');
     $this->assertArrayHasKey('testVariable', $controller->View->viewVars);
 }
Example #2
0
 /**
  * test that a classes namespace is used in the viewPath.
  *
  * @return void
  */
 public function testViewPathConventions()
 {
     $request = new Request('admin/posts');
     $request->addParams(['prefix' => 'admin']);
     $response = $this->getMockBuilder('Cake\\Network\\Response')->getMock();
     $Controller = new \TestApp\Controller\Admin\PostsController($request, $response);
     $Controller->eventManager()->on('Controller.beforeRender', function (Event $e) {
         return $e->subject()->response;
     });
     $Controller->render();
     $this->assertEquals('Admin' . DS . 'Posts', $Controller->viewBuilder()->templatePath());
     $request->addParams(['prefix' => 'admin/super']);
     $response = $this->getMockBuilder('Cake\\Network\\Response')->getMock();
     $Controller = new \TestApp\Controller\Admin\PostsController($request, $response);
     $Controller->eventManager()->on('Controller.beforeRender', function (Event $e) {
         return $e->subject()->response;
     });
     $Controller->render();
     $this->assertEquals('Admin' . DS . 'Super' . DS . 'Posts', $Controller->viewBuilder()->templatePath());
     $request = new Request('pages/home');
     $request->addParams(['prefix' => false]);
     $Controller = new \TestApp\Controller\PagesController($request, $response);
     $Controller->eventManager()->on('Controller.beforeRender', function (Event $e) {
         return $e->subject()->response;
     });
     $Controller->render();
     $this->assertEquals('Pages', $Controller->viewBuilder()->templatePath());
 }