SignupCest.php 2.28 KB
Newer Older
1 2
<?php

3
namespace tests\codeception\frontend\acceptance;
4

5
use tests\codeception\frontend\_pages\SignupPage;
6 7 8 9 10
use common\models\User;

class SignupCest
{

11 12
    /**
     * This method is called before each cest class test method
13
     * @param \Codeception\Event\TestEvent $event
14 15 16 17
     */
    public function _before($event)
    {
    }
18

19 20
    /**
     * This method is called after each cest class test method, even if test failed.
21
     * @param \Codeception\Event\TestEvent $event
22 23 24 25 26 27 28 29
     */
    public function _after($event)
    {
        User::deleteAll([
            'email' => 'tester.email@example.com',
            'username' => 'tester',
        ]);
    }
30

31 32
    /**
     * This method is called when test fails.
33
     * @param \Codeception\Event\FailEvent $event
34 35 36 37
     */
    public function _fail($event)
    {
    }
38

39
    /**
40
     * @param \codeception_frontend\AcceptanceTester $I
41 42 43 44 45
     * @param \Codeception\Scenario $scenario
     */
    public function testUserSignup($I, $scenario)
    {
        $I->wantTo('ensure that signup works');
46

47 48 49
        $signupPage = SignupPage::openBy($I);
        $I->see('Signup', 'h1');
        $I->see('Please fill out the following fields to signup:');
50

51
        $I->amGoingTo('submit signup form with no data');
52

53
        $signupPage->submit([]);
54

55 56 57 58
        $I->expectTo('see validation errors');
        $I->see('Username cannot be blank.', '.help-block');
        $I->see('Email cannot be blank.', '.help-block');
        $I->see('Password cannot be blank.', '.help-block');
59

60 61
        $I->amGoingTo('submit signup form with not correct email');
        $signupPage->submit([
62 63 64
            'username' => 'tester',
            'email' => 'tester.email',
            'password' => 'tester_password',
65
        ]);
66

67 68 69 70
        $I->expectTo('see that email address is wrong');
        $I->dontSee('Username cannot be blank.', '.help-block');
        $I->dontSee('Password cannot be blank.', '.help-block');
        $I->see('Email is not a valid email address.', '.help-block');
71

72 73
        $I->amGoingTo('submit signup form with correct email');
        $signupPage->submit([
74 75 76
            'username' => 'tester',
            'email' => 'tester.email@example.com',
            'password' => 'tester_password',
77
        ]);
78

79 80 81
        $I->expectTo('see that user logged in');
        $I->seeLink('Logout (tester)');
    }
82
}