1

I try to test my code with Codeception and my tests (both functional and acceptance) fails when I test logout option. They fails with "Method is not allowed (405)" because they are sent by GET method. I have this code out of the box within the Nav widget:

$menuItems[] = ['label' => 'Logout (' . Yii::$app->user->identity['username'] . ')',
                                'url' => ['/site/logout'],
                                'linkOptions' => ['data-method' => 'post']

This code works fine when I click the link by hand. In this case they are sent by POST method. But it doesn't work while testing. Why does it happens?

1 Answer 1

1

for logout you can add the form as follows, which will send the request using POST

$menuItems[] = '<li>'
        . Html::beginForm(['/site/logout'], 'post')
        . Html::submitButton(
                'Logout ('.Yii::$app->user->identity['username'].')', ['class' => 'btn btn-link btnlogout']
        )
        . Html::endForm()
        . '</li>';
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! It works! So in this case we should include this link in form tag.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.