Skip to content

Commit

Permalink
Replaced the $helpers $components with the initialize method in all c…
Browse files Browse the repository at this point in the history
…ontrollers.
  • Loading branch information
Xety committed Nov 4, 2016
1 parent 696b961 commit 440365c
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 68 deletions.
55 changes: 16 additions & 39 deletions src/Controller/AppController.php
Expand Up @@ -19,28 +19,12 @@ public function initialize()
{
parent::initialize();

//$this->loadComponent('Flash');
}

/**
* Components.
*
* @var array
*/
public $components = [
'Flash',
'Cookie',
'Acl.Acl',
'SessionsActivity',
/**
* If you want enable CSRF uncomment this.
* I recommend to enable it. If i have disable it, it's because
* CloudFlare have some problem with the header X-CSRF-Token (AJAX Request).
*/
/*'Csrf' => [
'secure' => true
],*/
'Auth' => [
//Components.
$this->loadComponent('Flash');
$this->loadComponent('Cookie');
$this->loadComponent('Acl.Acl');
$this->loadComponent('SessionsActivity');
$this->loadComponent('Auth', [
'className' => 'AclAuth',
'allowedActionsForBanned' => [
'Pages' => [
Expand Down Expand Up @@ -82,23 +66,16 @@ public function initialize()
'action' => 'home'
],
'authError' => 'You are not authorized to access that location !'
]
];

/**
* Helpers.
*
* @var array
*/
public $helpers = [
'Form' => [
'templates' => 'form-templates'
],
'Paginator' => [
'templates' => 'paginator-templates'
],
'Acl'
];
]);

if (env('HTTPS')) {
$this->loadComponent('Csrf', [
'secure' => true
]);
} else {
$this->loadComponent('Csrf');
}
}

/**
* beforeFilter handle.
Expand Down
13 changes: 8 additions & 5 deletions src/Controller/BlogController.php
Expand Up @@ -11,13 +11,16 @@ class BlogController extends AppController
{

/**
* Components.
* Initialization hook method.
*
* @var array
* @return void
*/
public $components = [
'RequestHandler'
];
public function initialize()
{
parent::initialize();

$this->loadComponent('RequestHandler');
}

/**
* BeforeFilter handle.
Expand Down
13 changes: 8 additions & 5 deletions src/Controller/NotificationsController.php
Expand Up @@ -7,13 +7,16 @@ class NotificationsController extends AppController
{

/**
* Components.
* Initialization hook method.
*
* @var array
* @return void
*/
public $components = [
'RequestHandler'
];
public function initialize()
{
parent::initialize();

$this->loadComponent('RequestHandler');
}

/**
* Mark a notification as readed.
Expand Down
13 changes: 8 additions & 5 deletions src/Controller/PagesController.php
Expand Up @@ -9,13 +9,16 @@ class PagesController extends AppController
{

/**
* Components.
* Initialization hook method.
*
* @var array
* @return void
*/
public $components = [
'RequestHandler'
];
public function initialize()
{
parent::initialize();

$this->loadComponent('RequestHandler');
}

/**
* Beforefilter.
Expand Down
27 changes: 27 additions & 0 deletions src/View/AppView.php
@@ -0,0 +1,27 @@
<?php
namespace App\View;

use Cake\View\View;

class AppView extends View
{

/**
* Initialization hook method.
*
* Use this method to add common initialization code like loading helpers.
*
* @return void
*/
public function initialize()
{
parent::initialize();
$this->loadHelper('Form', [
'templates' => 'form-templates'
]);
$this->loadHelper('Paginator', [
'templates' => 'paginator-templates'
]);
$this->loadHelper('Acl');
}
}
18 changes: 15 additions & 3 deletions tests/TestCase/Controller/ContactControllerTest.php
Expand Up @@ -26,10 +26,16 @@ public function testIndex()
*/
public function testIndexWithInvalidData()
{
$this->_cookie = [
'csrfToken' => '123456789'
];

$data = [
'email' => '',
'name' => '',
'message' => ''
'email' => '',
'subject' => '',
'message' => '',
'_csrfToken' => '123456789'
];

$this->post(['controller' => 'contact', 'action' => 'index'], $data);
Expand All @@ -45,10 +51,16 @@ public function testIndexWithInvalidData()
*/
public function testIndexWithValidData()
{
$this->_cookie = [
'csrfToken' => '123456789'
];

$data = [
'email' => 'test@xeta.io',
'name' => 'My Name',
'message' => 'My message'
'subject' => '',
'message' => 'My message',
'_csrfToken' => '123456789'
];

$this->post(['controller' => 'contact', 'action' => 'index'], $data);
Expand Down

0 comments on commit 440365c

Please sign in to comment.