示例#1
0
文件: UserTest.php 项目: howq/yii2
 public function testLoginExpires()
 {
     if (getenv('TRAVIS') == 'true') {
         $this->markTestSkipped('Can not reliably test this on travis-ci.');
     }
     $appConfig = ['components' => ['user' => ['identityClass' => UserIdentity::className(), 'authTimeout' => 10], 'authManager' => ['class' => PhpManager::className(), 'itemFile' => '@runtime/user_test_rbac_items.php', 'assignmentFile' => '@runtime/user_test_rbac_assignments.php', 'ruleFile' => '@runtime/user_test_rbac_rules.php']]];
     $this->mockWebApplication($appConfig);
     $am = Yii::$app->authManager;
     $am->removeAll();
     $am->add($role = $am->createPermission('rUser'));
     $am->add($perm = $am->createPermission('doSomething'));
     $am->addChild($role, $perm);
     $am->assign($role, 'user1');
     Yii::$app->session->removeAll();
     static::$time = \time();
     Yii::$app->user->login(UserIdentity::findIdentity('user1'));
     //        print_r(Yii::$app->session);
     //        print_r($_SESSION);
     $this->mockWebApplication($appConfig);
     $this->assertFalse(Yii::$app->user->isGuest);
     $this->assertTrue(Yii::$app->user->can('doSomething'));
     static::$time += 5;
     $this->mockWebApplication($appConfig);
     $this->assertFalse(Yii::$app->user->isGuest);
     $this->assertTrue(Yii::$app->user->can('doSomething'));
     static::$time += 11;
     $this->mockWebApplication($appConfig);
     $this->assertTrue(Yii::$app->user->isGuest);
     $this->assertFalse(Yii::$app->user->can('doSomething'));
 }
示例#2
0
 protected function setUp()
 {
     parent::setUp();
     $_SERVER['SCRIPT_FILENAME'] = "/index.php";
     $_SERVER['SCRIPT_NAME'] = "/index.php";
     $appConfig = ['components' => ['user' => ['identityClass' => UserIdentity::className()]], 'controllerMap' => ['test' => TestController::className()]];
     $this->mockWebApplication($appConfig);
 }