Ejemplo n.º 1
0
 /**
  * This method is called before each test method.
  *
  * @param \Codeception\Event\TestEvent $event
  */
 public function _before($event)
 {
     // delete this signed up user
     User::deleteAll(['email' => '*****@*****.**', 'username' => 'demo']);
     // delete roles
     Role::deleteAll();
 }
Ejemplo n.º 2
0
 /**
  * Assigns the appropriate role to the registered user.
  * If this is the first registered user in our system, he will get the
  * theCreator role (this should be you), if not, he will get the member role.
  *
  * @param  integer $id The id of the registered user.
  * @return string      Role name.
  */
 public static function assignRole($id)
 {
     // make sure there are no leftovers
     Role::deleteAll(['user_id' => $id]);
     $usersCount = User::find()->count();
     $auth = Yii::$app->authManager;
     // this is the first user in our system, give him theCreator role
     if ($usersCount == 1) {
         $role = $auth->getRole('theCreator');
         $auth->assign($role, $id);
     } else {
         $role = $auth->getRole('member');
         $auth->assign($role, $id);
     }
     // return assigned role name in case you want to use this method in tests
     return $role->name;
 }
Ejemplo n.º 3
0
 public static function assignRole($id)
 {
     Role::deleteAll(['user_id' => $id]);
     $usersCount = User::find()->count();
     $auth = Yii::$app->authManager;
     // FIRST USER
     if ($usersCount === 1) {
         $array = (array) AuthItem::getDevRole();
         foreach ($array as $key) {
             $role = $key->name;
         }
         $auth->assign($role, $id);
         return $role;
     } else {
         $array = (array) AuthItem::getParentRole();
         foreach ($array as $key) {
             $role = $key->name;
         }
         $auth->assign($role, $id);
         return $role;
     }
 }
Ejemplo n.º 4
0
 /**
  * Clean up the objects against which you tested.
  */
 protected function tearDown()
 {
     // delete roles
     Role::deleteAll();
 }