V
V
Vocler2019-07-23 03:11:13
Yii
Vocler, 2019-07-23 03:11:13

How to send a POST request to codeception using a button?

There is a page with the following button

<a href="/user/delete?id=1" data-method="post" id="mybutton"></a>

When you click on it, the browser sends a request /user/delete?id=1using the POST method. Then some action is performed on the server, and in response it returns a redirect back to the page with the button ( /user)
I'm trying to write a functional test for the above button. Now he looks like this
public function deleteUser(\FunctionalTester $I)
    {
        $I->amOnRoute('user');
        $I->see('myuser_stay');
        $I->see('myuser_delete');

        $I->click('#mybutton');

        $I->see('myuser_stay');
        $I->dontSee('myuser_delete');
    }

The deletion of the user should happen here myuser_delete, but not the user myuser_stay.
I'm trying to run the test, it crashes with an error on the line :$I->see('myuser_stay');
Fail  Failed asserting that  on page /user/delete?id=1
--> Method Not Allowed: Method Not Allowed. This URL can only handle the following request methods: POST.
--> contains "myuser_stay".

Apparently, for some reason, Codeception tries to send a GET request to , ignoring the buttons. Questions: 1) Why is data-method ignored? 2) How to fix it? Of course, you can use , and send a request directly, bypassing the button, but as for me, this is a crutch. /user/delete?id=1data-method
$I->sendAjaxPostRequest()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Bratenkov, 2019-07-23
@Vocler

Perhaps the problem is that the attribute data-methodis processed by JS, which does not work in functional tests, respectively, and is data-methodignored .
Acceptance tests pass this moment normally?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question