Hi,
I write a behavior for Table. This behavior will check variables in session. Since we can’t access to the request->session() object in behavior, i read session’s variables directly like this :
private function _getSessionId()
{
$session = new Session();
$organisation_id = $session->read($this->_defaultConfig['session']); // read Auth.User.organisations_id
return $organisation_id;
}
this behavior is register to some tables of my application. This session’s reading is call at every before find for model.
Now, i want to test controllers which use tables with this behavior. So i fix var in session like this before the test of the action :
public function testListeStocksMultiSearch()
{
Configure::write('debug', 1);
// placement de la session
$this->session([
'Droits' => ['ADMIN'],
'Auth' => [
'User' => [
'id' => 1,
'username' => 'bmarchand',
'prenom' => 'Benjamin',
'nom' => 'Marchand',
'organisations_id' => 1
]
]
]);
$url = Router::url(['controller' => 'Stocks',
'action' => 'recherche',
'?' => ['_table' => 'Stocks',
'Produits' => ['couleur' => 'blanc']]]);
$this->get($url);
$this->_writeFile($this->_getBodyAsString());
$this->assertResponseOk();
$this->viewVariable('produits');
}
But i always have a null value in the behavior when i try to read the variable Auth.User.organisations_id (it works well when i request the data by the browser).
please someone have an idea about this bug (?).
Many thanks
regards
cyb