LogoutActionTest::runAction()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
1
<?php
2
3
namespace yii2mod\user\tests\actions;
4
5
use Yii;
6
use yii2mod\user\actions\LoginAction;
7
use yii2mod\user\actions\LogoutAction;
8
use yii2mod\user\tests\TestCase;
9
10
/**
11
 * Class LogoutActionTest
12
 *
13
 * @package yii2mod\user\tests\actions
14
 */
15
class LogoutActionTest extends TestCase
16
{
17
    /**
18
     * Runs the action.
19
     *
20
     * @param $actionClass
21
     * @param $id
22
     * @param array $config
23
     *
24
     * @return array|\yii\web\Response response
25
     */
26
    protected function runAction($actionClass, $id, array $config = [])
27
    {
28
        $action = new $actionClass($id, $this->createController(), $config);
29
30
        return $action->run();
31
    }
32
33
    // Tests:
34
35
    public function testLogout()
36
    {
37
        // login as the demo user
38
        Yii::$app->request->bodyParams = [
39
            'LoginForm' => [
40
                'email' => '[email protected]',
41
                'password' => 'password',
42
            ],
43
        ];
44
        $this->runAction(LoginAction::class, 'login');
45
        $this->assertFalse(Yii::$app->user->isGuest);
46
47
        // logout
48
        $this->runAction(LogoutAction::class, 'logout');
49
        $this->assertTrue(Yii::$app->user->isGuest);
50
    }
51
}
52