<?php

use tests\codeception\rest\FunctionalTester;
/** @var \Codeception\Scenario $scenario */
$I = new FunctionalTester($scenario);
$token = '?access-token=tUu1qHcde0diwUol3xeI-18MuHkkprQI';
$I->wantTo('ensure that posts access only for auth users');
$I->sendGET('/v1/posts');
$I->seeResponseCodeIs(401);
$I->seeResponseIsJson();
$I->wantTo('create post via API');
$I->haveHttpHeader('Content-Type', 'application/json');
$I->sendPOST('/v1/posts' . $token, ['title' => 'My first post', 'content' => 'There are many words....', 'status' => 2]);
$I->seeResponseCodeIs(201);
$I->seeResponseIsJson();
$I->seeResponseContainsJson(['title' => 'My first post']);
$I->wantTo('get my post');
$I->sendGET('/v1/posts' . $token . '&title=My first post');
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->seeResponseContainsJson(['title' => 'My first post', 'id' => 1, 'author' => ['username' => 'erau']]);
$I->wantTo('update my post to draft');
$I->haveHttpHeader('Content-Type', 'application/json');
$I->sendPUT('/v1/posts/1' . $token, ['title' => 'My second post']);
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->seeResponseContainsJson(['title' => 'My second post']);
Exemplo n.º 2
0
<?php

use tests\codeception\rest\FunctionalTester;
/** @var \Codeception\Scenario $scenario */
$I = new FunctionalTester($scenario);
$I->wantTo('test to obtain a token');
$I->sendPOST('/v1/user/login', ['username' => 'erau', 'password' => 'password_0']);
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->seeResponseContains('tUu1qHcde0diwUol3xeI-18MuHkkprQI');
$I->wantTo('test invalid query');
$I->sendPOST('/v1/user/login', ['username' => 'user', 'password' => 'password']);
$I->seeResponseCodeIs(422);
$I->seeResponseIsJson();
$I->seeResponseContainsJson(['message' => 'Incorrect username or password.']);
Exemplo n.º 3
0
<?php

use tests\codeception\rest\FunctionalTester;
use tests\codeception\common\_pages\LoginPage;
/* @var $scenario Codeception\Scenario */
$I = new FunctionalTester($scenario);
$I->wantTo('ensure login page works');
$loginPage = LoginPage::openBy($I);
$I->amGoingTo('submit login form with no data');
$loginPage->login('', '');
$I->expectTo('see validations errors');
$I->see('Username cannot be blank.', '.help-block');
$I->see('Password cannot be blank.', '.help-block');
$I->amGoingTo('try to login with wrong credentials');
$I->expectTo('see validations errors');
$loginPage->login('admin', 'wrong');
$I->expectTo('see validations errors');
$I->see('Incorrect username or password.', '.help-block');
$I->amGoingTo('try to login with correct credentials');
$loginPage->login('erau', 'password_0');
$I->expectTo('see that user is logged');
$I->seeLink('Logout (erau)');
$I->dontSeeLink('Login');
$I->dontSeeLink('Signup');