SignupCest.php 2.09 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
<?php

namespace frontend\tests\functional;

use frontend\tests\_pages\SignupPage;
use common\models\User;

class SignupCest
{

	/**
Johnny Theill committed
12
	 * This method is called before each cest class test method
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
	 * @param \Codeception\Event\Test $event
	 */
	public function _before($event)
	{
	}

	/**
	 * This method is called after each cest class test method, even if test failed.
	 * @param \Codeception\Event\Test $event
	 */
	public function _after($event)
	{
		User::deleteAll([
			'email' => 'tester.email@example.com',
			'username' => 'tester',
		]);
	}

	/**
	 * This method is called when test fails.
	 * @param \Codeception\Event\Fail $event
	 */
	public function _fail($event)
	{
Johnny Theill committed
37

38 39 40
	}

	/**
Johnny Theill committed
41
	 *
42 43 44 45 46 47 48 49
	 * @param \TestGuy $I
	 * @param \Codeception\Scenario $scenario
	 */
	public function testUserSignup($I, $scenario)
	{
		$I->wantTo('ensure that signup works');

		$signupPage = SignupPage::openBy($I);
Johnny Theill committed
50
		$I->see('Signup', 'h1');
51 52 53 54 55 56 57
		$I->see('Please fill out the following fields to signup:');

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

		$signupPage->submit([]);

		$I->expectTo('see validation errors');
Johnny Theill committed
58 59 60
		$I->see('Username cannot be blank.', '.help-block');
		$I->see('Email cannot be blank.', '.help-block');
		$I->see('Password cannot be blank.', '.help-block');
61 62 63 64 65 66 67 68

		$I->amGoingTo('submit signup form with not correct email');
		$signupPage->submit([
			'username'		=>	'tester',
			'email'			=>	'tester.email',
			'password'		=>	'tester_password',
		]);

Johnny Theill committed
69 70 71
		$I->expectTo('see that email address is wrong');
		$I->dontSee('Username cannot be blank.', '.help-block');
		$I->dontSee('Password cannot be blank.', '.help-block');
72 73 74 75 76 77 78 79 80
		$I->see('Email is not a valid email address.', '.help-block');

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

Johnny Theill committed
81 82 83 84 85 86
		$I->expectTo('see that user is created');
		$I->seeRecord('common\models\User', [
			'username'		=>	'tester',
			'email'			=>	'tester.email@example.com',
		]);

87
		$I->expectTo('see that user logged in');
Johnny Theill committed
88
		$I->seeLink('Logout (tester)');
89 90
	}
}