Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ok actually the only solution that me and my team found is creating a stub WebUser class. Rewriting WebUser class in this way you can authenticate a user without having Yii relying on the session.</p> <pre><code>class WebUserMock extends WebUser { public function login($identity,$duration=0) { $id=$identity-&gt;getId(); $states=$identity-&gt;getPersistentStates(); if($this-&gt;beforeLogin($id,$states,false)) { $this-&gt;changeIdentity($id,$identity-&gt;getName(),$states); $duration = 0; if($duration&gt;0) { if($this-&gt;allowAutoLogin) $this-&gt;saveToCookie($duration); else throw new CException(Yii::t('yii','{class}.allowAutoLogin must be set true in order to use cookie-based authentication.', array('{class}'=&gt;get_class($this)))); } $this-&gt;afterLogin(false); } return !$this-&gt;getIsGuest(); } public function changeIdentity($id,$name,$states) { $this-&gt;setId($id); $this-&gt;setName($name); $this-&gt;loadIdentityStates($states); } // Load user model. protected function loadUser() { $id = Yii::app()-&gt;user-&gt;id; if ($id!==null) $this-&gt;_model=User::model()-&gt;findByPk($id); return $this-&gt;_model; } }; </code></pre> <p>In the setUp method of your test class you can login any user (in this case leveraging my fixtures)</p> <pre><code>//a piece of your setUp() method.... $identity = new UserIdentity($this-&gt;users('User_2')-&gt;email, md5('demo')); $identity-&gt;authenticate(); if($identity-&gt;errorCode===UserIdentity::ERROR_NONE) Yii::app()-&gt;user-&gt;login($identity); </code></pre> <p>As a final thing to do just override the user component in the test configuration file and tell him to use this one:</p> <p>protected/config/test.php</p> <pre><code>'user'=&gt;array( 'class' =&gt; 'application.tests.mock.WebUserMock', 'allowAutoLogin'=&gt;false, ), </code></pre> <p>Still not sure that this is the best way to handle it but seems to work fine</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload