/** * * @param \TestGuy $I * @param \Codeception\Scenario $scenario */ public function testUserSignup($I, $scenario) { $I->wantTo('ensure that signup works'); $signupPage = SignupPage::openBy($I); $I->see('Signup', 'h1'); $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'); $I->see('Username cannot be blank.', '.help-block'); $I->see('Email cannot be blank.', '.help-block'); $I->see('Password cannot be blank.', '.help-block'); $I->amGoingTo('submit signup form with not correct email'); $signupPage->submit(['username' => 'tester', 'email' => 'tester.email', 'password' => 'tester_password']); $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'); $I->amGoingTo('submit signup form with correct email'); $signupPage->submit(['username' => 'tester', 'email' => '*****@*****.**', 'password' => 'tester_password']); $I->expectTo('see that user is created'); $I->seeRecord('common\\models\\User', ['username' => 'tester', 'email' => '*****@*****.**']); $I->expectTo('see that user logged in'); $I->seeLink('Logout (tester)'); }
public function _submitEmptyModuleForm(TestGuy $I) { $I->wantTo('submit empty module form test'); $I->amOnPage('/sections/create-empty-module/0/'); // remove root element $data['form'] = array('name' => 'notification', 'namespace' => 'urn:ietf:params:xml:ns:netconf:notification:1.0'); $I->submitForm('form.create-empty-module', $data); // check what is in answer $I->see('block--state'); $I->dontSee('500 Internal Server Error'); }
<?php $I = new TestGuy($scenario); $I->wantTo('perform shadow login as first user'); $I->haveInSession('identity', 1); $I->haveInSession('identity-name', 'Phalcon'); $I->amOnPage('/'); $I->see('Log In with Github');
<?php use frontend\tests\_pages\ContactPage; $I = new TestGuy($scenario); $I->wantTo('ensure that contact works'); $contactPage = ContactPage::openBy($I); $I->see('Contact', 'h1'); $I->amGoingTo('submit contact form with no data'); $contactPage->submit([]); $I->expectTo('see validations errors'); $I->see('Contact', 'h1'); $I->see('Name cannot be blank', '.help-block'); $I->see('Email cannot be blank', '.help-block'); $I->see('Subject cannot be blank', '.help-block'); $I->see('Body cannot be blank', '.help-block'); $I->see('The verification code is incorrect', '.help-block'); $I->amGoingTo('submit contact form with not correct email'); $contactPage->submit(['name' => 'tester', 'email' => 'tester.email', 'subject' => 'test subject', 'body' => 'test content', 'verifyCode' => 'testme']); $I->expectTo('see that email adress is wrong'); $I->dontSee('Name cannot be blank', '.help-block'); $I->see('Email is not a valid email address.', '.help-block'); $I->dontSee('Subject cannot be blank', '.help-block'); $I->dontSee('Body cannot be blank', '.help-block'); $I->dontSee('The verification code is incorrect', '.help-block'); $I->amGoingTo('submit contact form with correct data'); $contactPage->submit(['name' => 'tester', 'email' => '*****@*****.**', 'subject' => 'test subject', 'body' => 'test content', 'verifyCode' => 'testme']); $I->see('Thank you for contacting us. We will respond to you as soon as possible.');
<?php $I = new TestGuy($scenario); $I->wantTo('ensure that home page works'); $I->amOnPage(''); $I->see('My Company'); $I->seeLink('About'); $I->click('About'); $I->see('This is the About page.');
<?php use tests\_pages\SignupPage; $I = new TestGuy($scenario); $I->wantTo('ensure that signup works correctly'); $signupPage = SignupPage::openBy($I); $I->amGoingTo('sign up coreectly'); $signupPage->signup('*****@*****.**', 'password', 'password'); $I->expectTo('see success message'); $I->see('Now you can sign in.'); $I->amGoingTo('sign up with empty fields'); $signupPage = SignupPage::openBy($I); $signupPage->signup('', '', ''); $I->expectTo('see validations errors'); $I->see('Email cannot be blank.'); $I->see('Password cannot be blank.'); $I->amGoingTo('sign up with different passwords'); $signupPage = SignupPage::openBy($I); $signupPage->signup('*****@*****.**', 'password', 'pa$$word'); $I->expectTo('see password validations errors'); $I->see("Passwords don't match"); $I->amGoingTo('sign up with invalid email'); $signupPage = SignupPage::openBy($I); $signupPage->signup('invalid@mail', 'password', 'password'); $I->expectTo('see email validations error'); $I->see("Email is not a valid email address"); $I->amGoingTo('sign up with already used email'); $signupPage = SignupPage::openBy($I); $signupPage->signup('*****@*****.**', 'password', 'password'); $I->expectTo('see email validations error'); $I->see("This email address has already been taken");
<?php use tests\_pages\CreatePadPage; $I = new TestGuy($scenario); $I->wantTo('ensure that pad creation works correctly'); $user = ['email' => '*****@*****.**', 'password' => '123123']; $padPage = CreatePadPage::openBy($I, [], $user); $I->amGoingTo('create pad'); $padPage->create('new pad'); $I->expectTo('see success message'); $I->see('Pad is successfully created'); $I->amGoingTo('create pad with blank name'); $padPage = CreatePadPage::openBy($I, [], $user); $padPage->create(''); $I->expectTo('see validation error'); $I->see('Name cannot be blank');
<?php use tests\_pages\EditPadPage; $I = new TestGuy($scenario); $I->wantTo('ensure that edit pad works correctly'); $user = ['email' => '*****@*****.**', 'password' => '123123']; $padPage = EditPadPage::openBy($I, ['id' => 1], $user); $I->amGoingTo('edit pad'); $newName = 'new pad name'; $padPage->edit($newName); $I->expectTo('see success message'); $I->see('Pad is successfully updated'); $I->expectTo('see new name'); $I->see($newName); $I->amGoingTo('edit pad with blank name'); $padPage = EditPadPage::openBy($I, ['id' => 1], $user); $padPage->edit(''); $I->expectTo('see validation error'); $I->see('Name cannot be blank'); // @TODO //$I->amGoingTo('edit not my pad');
<?php use tests\_pages\ViewPage; $I = new TestGuy($scenario); $I->wantTo('保证site/view?slug=readme页面正常工作'); ViewPage::openBy($I); $I->see('yii2-blog说明', 'h2');
<?php use tests\_pages\AboutPage; $I = new TestGuy($scenario); $I->wantTo('ensure that about works'); AboutPage::openBy($I); $I->see('About', 'h1');
<?php // Most idiotic cept ever // Checks that every page has correct translation and correct access control // That means that it has to be updated nearly on every sneeze use Codeception\Util\Fixtures; /** @type \Codeception\Scenario $scenario */ $scenario->groups('front'); \Yii::app()->fixtureManager->prepare(); $I = new TestGuy($scenario); $I->am('A superpedantic person'); $I->wantTo('Find translation error or improper "back to" link'); $I->expectTo('Fail in my quest'); $languages = array('en', 'ru'); $basePath = \Yii::getPathOfAlias('application.tests._data.pageData'); $privatePages = (require $basePath . '/pages-auth.php'); $publicPages = (require $basePath . '/pages-public.php'); $I->amOnPage(\LoginPage::$url); $I->submitForm(\LoginPage::$formSelector, array(\LoginPage::$loginField => Fixtures::get('data:users[0]:login'), \LoginPage::$passwordField => Fixtures::get('data:users[0]:password'))); foreach ($languages as $language) { \Yii::app()->language = $language; $I->setCookie('language', $language); $path = $basePath . '/language-' . $language . '.php'; $data = (require $path); foreach ($data as $url => $details) { $I->amOnPage($url); if (isset($details['title'])) { $I->seeInTitle($details['title']); } if (isset($details['nav'])) { foreach ($details['nav'] as $navItem) {
<?php use common\tests\_pages\LoginPage; $I = new TestGuy($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.'); $I->see('Password cannot be blank.'); $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.'); $I->amGoingTo('try to login with correct credentials'); $loginPage->login('erau', 'password_0'); $I->expectTo('see that user is logged'); $I->see('Logout (erau)'); $I->dontSee('Login'); $I->dontSee('Signup'); $I->click('Logout (erau)'); $I->dontSee('Logout (erau)'); $I->see('Login');
<?php use hipstercreative\user\tests\_pages\RecoveryPage; use hipstercreative\user\tests\_pages\LoginPage; use yii\helpers\Html; use yii\helpers\Url; use hipstercreative\user\models\User; $I = new TestGuy($scenario); $I->wantTo('ensure that password recovery works'); $page = RecoveryPage::openBy($I); $I->amGoingTo('try to request recovery token for unconfirmed account'); $user = $I->getFixture('user')->getModel('unconfirmed'); $page->recover($user->email); $I->see('You need to confirm your email address'); $I->amGoingTo('try to request recovery token'); $user = $I->getFixture('user')->getModel('user'); $page->recover($user->email); $I->see('You have been sent an email with instructions on how to reset your password.'); $user = $I->grabRecord(User::className(), ['email' => $user->email]); $I->seeInEmail(Html::encode($user->getRecoveryUrl())); $I->seeInEmailRecipients($user->email); $I->amGoingTo('reset password with invalid token'); $user = $I->getFixture('user')->getModel('user_with_expired_recovery_token'); $I->amOnPage(Url::toRoute(['/user/recovery/reset', 'id' => $user->id, 'token' => $user->recovery_token])); $I->see('Recovery token is invalid'); $I->amGoingTo('reset password'); $user = $I->getFixture('user')->getModel('user_with_recovery_token'); $I->amOnPage(Url::toRoute(['/user/recovery/reset', 'id' => $user->id, 'token' => $user->recovery_token])); $I->fillField('#recovery-form-password', 'newpass'); $I->click('Finish'); $I->see('Password recovery finished');
<?php use tests\_pages\CreateNotePage; $I = new TestGuy($scenario); $I->wantTo('ensure that note creation works correctly'); $user = ['email' => '*****@*****.**', 'password' => '123123']; $notePage = CreateNotePage::openBy($I, [], $user); $I->amGoingTo('create note'); $notePage->create('new note', 'note text'); $I->expectTo('see success message'); $I->see('Note is successfully created'); $I->amGoingTo('create note with blank fields'); $notePage = CreateNotePage::openBy($I, [], $user); $notePage->create('', ''); $I->expectTo('see validation errors'); $I->see('Name cannot be blank'); $I->see('Text cannot be blank'); $I->amGoingTo('create note by anonymous'); $notePage->signout($I); $I->amOnPage(\Yii::$app->getUrlManager()->createUrl(['note/create'])); $I->expectTo('be redirected to signin page'); $I->seeInCurrentUrl('/signin'); // @TODO add note not in my pad // $I->amGoingTo('create note by anonymous');
<?php $I = new TestGuy($scenario); $I->wantTo('Verify that the home page wellcome me'); $I->amOnPage('/'); $I->see('Log In with Github'); $I->click('Log In with Github'); $I->see('Profile');
<?php /* @var \Codeception\Scenario $scenario */ $I = new TestGuy($scenario); $I->wantTo('perform some named routes'); $I->sendGET('/route1'); $I->seeResponseEquals('hello world'); $I->sendGET('/route2'); $I->seeResponseEquals('hello world'); $I->sendGET('/route3'); $I->seeResponseEquals('hello world');
<?php use Codeception\Util\Fixtures; /** @type \Codeception\Scenario $scenario */ $scenario->groups('front', 'user-management'); \Yii::app()->fixtureManager->prepare(); $I = new TestGuy($scenario); $I->wantTo('Delete my account'); $I->expectTo('Lose ability to sign in under my regular account and all my posts'); $login = Fixtures::get('data:users[0]:login'); $password = Fixtures::get('data:users[0]:password'); $I->amOnPage(\AuthorFeedPage::route(1)); // confirming that test landed on required page $I->see($login, \AuthorFeedPage::$postSelector); $I->amOnPage(\LoginPage::$url); $I->submitForm(\LoginPage::$formSelector, array(\LoginPage::$loginField => $login, \LoginPage::$passwordField => $password)); $I->amOnPage(\SuicideBoothPage::$url); $I->click(\SuicideBoothPage::$benderButtonXPath); $I->seeCurrentUrlEquals('/'); $I->amOnPage(\LoginPage::$url); $I->submitForm(\LoginPage::$formSelector, array(\LoginPage::$loginField => $login, \LoginPage::$passwordField => $password)); $I->see('auth.login.fail'); $I->amOnPage(\AuthorFeedPage::route(1)); $I->see('pageTitle.site.error', \AuthorFeedPage::$pageHeaderSelector); $I->seeResponseCodeIs(404); $h = fopen(\Yii::getPathOfAlias('application.runtime.login'), 'a'); fwrite($h, $login . PHP_EOL); fclose($h); $I->assertNull(\User::findByUsername($login, false)); $I->assertEmpty(\Post::model()->with(array('author' => array('condition' => 'author.username = :login', 'params' => array(':login' => $login))))->findAll());
<?php /* @var \Codeception\Scenario $scenario */ $I = new TestGuy($scenario); $I->wantTo('check callback parameters'); $I->sendGET('/parameters'); $I->seeResponseEquals('yup'); $I->sendGET('/parameters/app'); $I->seeResponseEquals('Hahns\\Hahns'); $I->sendGET('/parameters/invalid'); $I->seeResponseCodeIs(500);
<?php use hipstercreative\user\tests\_pages\CreatePage; use hipstercreative\user\tests\_pages\LoginPage; $I = new TestGuy($scenario); $I->wantTo('ensure that user creation works'); $loginPage = LoginPage::openBy($I); $user = $I->getFixture('user')->getModel('user'); $loginPage->login($user->email, 'qwerty'); $page = CreatePage::openBy($I); $I->amGoingTo('try to create user with empty fields'); $page->create('', '', ''); $I->expectTo('see validations errors'); $I->see('Username cannot be blank.'); $I->see('Email cannot be blank.'); $page->create('toster', '*****@*****.**', 'toster'); $I->see('User has been created'); $I->see('toster'); $I->see('*****@*****.**'); Yii::$app->user->logout(); $I->grabRecord('hipstercreative\\user\\models\\User', ['email' => '*****@*****.**'])->confirm(); LoginPage::openBy($I)->login('*****@*****.**', 'toster'); $I->see('Logout');
<?php use tests\_pages\DeletePadPage; $I = new TestGuy($scenario); $I->wantTo('ensure that pad deletion works correctly'); $user = ['email' => '*****@*****.**', 'password' => '123123']; $padPage = DeletePadPage::openBy($I, ['id' => 1], $user); $I->amGoingTo('delete pad'); $padPage->delete(); $I->expectTo('see success message'); $I->see('Pad is successfully deleted'); // @TODO //$I->amGoingTo('delete not my pad');
<?php /* @var \Codeception\Scenario $scenario */ $I = new TestGuy($scenario); $I->wantTo('perform not founding request'); $I->sendGET('/wdwadwadwayccy'); $I->seeResponseCodeIs(404); $I->seeResponseEquals('1');
<?php /* @var \Codeception\Scenario $scenario */ $I = new TestGuy($scenario); $I->wantTo('check redirections'); $I->sendGET('/redirect'); $I->seeResponseCodeIs(404); $I->amOnPage('/redirected');
<?php use tests\_pages\DeleteNotePage; $I = new TestGuy($scenario); $I->wantTo('ensure that note deletion works correctly'); $user = ['email' => '*****@*****.**', 'password' => '123123']; $notePage = DeleteNotePage::openBy($I, ['id' => 1], $user); $I->amGoingTo('delete pad'); $notePage->delete(); $I->expectTo('see success message'); $I->see('Note is successfully deleted'); // @TODO //$I->amGoingTo('delete not my note');
<?php use tests\_pages\EditNotePage; $I = new TestGuy($scenario); $I->wantTo('ensure that edit note works correctly'); $user = ['email' => '*****@*****.**', 'password' => '123123']; $notePage = EditNotePage::openBy($I, ['id' => 1], $user); $I->amGoingTo('edit note'); $newName = 'new note name'; $newText = 'new pad text'; $notePage->edit($newName, $newText); $I->expectTo('see success message'); $I->see('Note is successfully updated'); $I->expectTo('see new name and new text'); $I->see($newName); $I->see($newText); $I->amGoingTo('edit note with blank fields'); $notePage = EditNotePage::openBy($I, ['id' => 1], $user); $notePage->edit('', ''); $I->expectTo('see validation errors'); $I->see('Name cannot be blank'); $I->see('Text cannot be blank'); // @TODO //$I->amGoingTo('edit not my note');
<?php use tests\_pages\LoginPage; $I = new TestGuy($scenario); $I->wantTo('ensure that login works'); $loginPage = LoginPage::openBy($I); $I->see('Login', 'h1'); $I->amGoingTo('try to login with empty credentials'); $loginPage->login('', ''); $I->expectTo('see validations errors'); $I->see('Username cannot be blank.'); $I->see('Password cannot be blank.'); $I->amGoingTo('try to login with wrong credentials'); $loginPage->login('admin', 'wrong'); $I->expectTo('see validations errors'); $I->see('Incorrect username or password.'); $I->amGoingTo('try to login with correct credentials'); $loginPage->login('admin', 'admin'); $I->expectTo('see user info'); $I->see('Logout (admin)');
<?php $I = new TestGuy($scenario); $I->wantTo('保证site/index页面正常工作'); $I->amOnPage(Yii::$app->homeUrl); $I->seeLink('Yii2 Blog'); $I->seeLink('首页'); $I->seeLink('yii2-blog说明'); $I->click('yii2-blog说明'); $I->see('yii2-blog说明');
<?php /* @var \Codeception\Scenario $scenario */ $I = new TestGuy($scenario); $I->wantTo('perform some GET requests'); $I->sendGET('/text'); $I->seeHttpHeader('Content-Type', 'text/plain'); $I->seeResponseEquals('yep');
<?php /* @var \Codeception\Scenario $scenario */ $I = new TestGuy($scenario); $I->wantTo('perform some POST requests'); $I->sendPOST('/post', ['id' => 400]); $I->seeResponseIsJson(); $I->seeResponseContainsJson(['message' => 'home', 'id' => 400]); $I->sendPOST('/hello/peter', ['say' => 'nice to meet you!']); $I->seeResponseIsJson(); $I->seeResponseContainsJson(['message' => 'nice to meet you!']);
<?php use tests\_pages\ViewPadPage; $I = new TestGuy($scenario); $I->wantTo('ensure that pad viewing works correctly'); $user = ['email' => '*****@*****.**', 'password' => '123123']; $padPage = ViewPadPage::openBy($I, ['id' => 1], $user); $I->amGoingTo('view pad'); $I->expectTo('see pad name'); $I->see('Pad name (1)'); // @TODO //$I->amGoingTo('view not my pad');
<?php /* @var \Codeception\Scenario $scenario */ $I = new TestGuy($scenario); $I->wantTo('check events'); $I->sendGET('/event'); $I->seeResponseEquals('/event');