<?php /** @type Codeception\Scenario $scenario */ $scenario->groups(array('nonauthenticated', 'blog')); $I = new WebGuy\MemberSteps($scenario); $I->wantTo('Play with comments'); $I->amGoingTo('Be very stupid and leave comment several times until blog ' . 'will consider it correct'); $I->logout(); $I->amOnPage(\BlogFeedPage::$url); $I->click(\BlogFeedPage::$postTitleSelector); $I->see('text.commentThisPost'); $currentUrl = $I->grabFromCurrentUrl('~(.*)~'); $I->submitCommentForm(); $I->seeCurrentUrlMatches('~^' . $currentUrl . '~'); \PostPage::of($I)->hasErrors(); $I->submitCommentForm('tralalal'); $I->seeCurrentUrlMatches('~^' . $currentUrl . '~'); \PostPage::of($I)->hasErrors(); $I->submitCommentForm('Hey, look at my local email address!', 'marabou', 'marabou@localhost'); $I->seeCurrentUrlMatches('~^' . $currentUrl . '~'); \PostPage::of($I)->hasErrors(); // checking form saving $I->seeInField(\PostPage::$commentTextArea, 'Hey, look at my local email address!'); $I->seeInField(\PostPage::$commentUsernameField, 'marabou'); $I->seeInField(\PostPage::$commentEmailField, 'marabou@localhost'); $I->submitCommentForm('This is first correct comment', 'marabou', ''); $I->seeCurrentUrlMatches('~^' . $currentUrl . '~'); \PostPage::of($I)->hasNoErrors(); $I->see('This is first correct comment'); $I->submitCommentForm('Second correct comment, now using gravatar', 'marabou', '*****@*****.**'); $I->seeCurrentUrlMatches('~^' . $currentUrl . '~');
<?php /** @type \Codeception\Scenario $scenario */ $scenario->groups('admin', 'settings'); $I = new \WebGuy\MemberSteps($scenario); $I->wantTo('Play with settings'); $I->amGoingTo('Tweak themes, languages and names'); $I->autoLogin(); $I->amOnPage(\OptionsPage::$url); $I->seeCurrentUrlEquals(\OptionsPage::$url); $I->setCookie('useDefaultLanguage', 'true'); \OptionsPage::of($I)->updateOptions('Horse Tickler\'s Dagger Fan Club', 'ru', 'ambinight'); $I->seeCurrentUrlEquals(\OptionsPage::$url); $I->seeInTitle('Horse Tickler\'s Dagger Fan Club'); $I->seeOptionIsSelected(\OptionsPage::$siteLanguageList, 'ru'); $I->seeOptionIsSelected(\OptionsPage::$themeList, 'ambinight'); $I->see('Настройки', \OptionsPage::$pageHeaderSelector); \OptionsPage::of($I)->hasNoErrorFlashMessages(); $I->amOnPage(\BlogFeedPage::$url); $I->see('Категории', \BlogFeedPage::$sidebarSelector); $I->resetApplicationSettings(); $I->resetCookie('useDefaultLanguage');
<?php use Codeception\Util\Fixtures; /** @type \Codeception\Scenario $scenario */ $scenario->groups('auth', 'front'); $i = new \WebGuy\MemberSteps($scenario); $i->am('admin'); $i->wantTo('check auth mechanism'); $i->expect('login failure on invalid data and login success on valid data'); $i->logout(); $i->seeCurrentUrlEquals(\BlogFeedPage::$url); $i->seeAlert('auth.logout.guestAttempt'); $i->seeElement(\FeedPage::$loginLink); $i->click('link.login'); $i->seeCurrentUrlEquals(\LoginPage::$url); $i->login(null, null); $i->seeAlert('auth.login.fail'); $i->login('missing username', 'nonexisting password'); $i->seeAlert('auth.login.fail'); $i->autoLogin(); $i->see('auth.login.greeting'); $i->seeCurrentUrlEquals(\AdminPanelPage::$url); $i->amOnPage(\LoginPage::$url); $i->seeCurrentUrlEquals(\AdminPanelPage::$url); $i->seeAlert('auth.login.alreadyAuthorized'); $i->seeLink('link.logout'); $i->click('link.logout'); $i->seeCurrentUrlEquals(\BlogFeedPage::$url); //$i->canSee('You have successfully logged out');
<?php /** @type \Codeception\Scenario $scenario */ $scenario->groups('content'); $I = new WebGuy\MemberSteps($scenario); $I->wantTo('Publish my post'); $I->amGoingTo('Write a post, edit it, delete it, write lots of posts'); $I->autoLogin(); $I->writePost('', ''); $I->seeCurrentUrlEquals(\PostFormPage::$newPostUrl); \PostFormPage::of($I)->hasErrors(); $I->writePost('What a title', ''); $I->seeCurrentUrlEquals(\PostFormPage::$newPostUrl); \PostFormPage::of($I)->hasErrors(); $I->writePost('What a title', 'whatapost'); $I->seeCurrentUrlEquals(\PostFormPage::$newPostUrl); \PostFormPage::of($I)->hasErrors(); $I->writePost('', 'whatapostapost'); $I->seeCurrentUrlEquals(\PostFormPage::$newPostUrl); \PostFormPage::of($I)->hasErrors(); $I->writePost('What a title', '*whatapostapost*'); $I->dontSeeInCurrentUrl(\PostFormPage::$newPostUrl); \PostFormPage::of($I)->hasNoErrors(); $I->seeCurrentUrlEquals(\PostPage::route('what-a-title')); $I->see('whatapostapost', 'article em'); $I->seeInTitle('What a title'); $I->seeLink('link.edit'); $I->click('link.edit'); $id = $I->grabFromCurrentUrl('~(\\d+)~'); $I->amOnPage(\BlogFeedPage::$url); $I->see('What a title', '.sidebar');
<?php use Codeception\Util\Fixtures; /** @type \Codeception\Scenario $scenario */ $I = new WebGuy\MemberSteps($scenario); $I->wantTo('Update my password to another one'); $newPassword = md5(microtime()); $I->autoLogin(); $I->updatePassword($newPassword); $I->logout(); $I->login(Fixtures::get('data:users[0]:login'), $newPassword); $I->seeCurrentUrlEquals(\AdminPanelPage::$url); $I->logout(); $I->autoLogin(); $I->seeCurrentUrlEquals(\LoginPage::$url); $I->logout(); $I->login(Fixtures::get('data:users[0]:login'), $newPassword); $I->seeCurrentUrlEquals(\AdminPanelPage::$url); $I->updatePassword(Fixtures::get('data:users[0]:password')); $I->logout(); $I->login(Fixtures::get('data:users[0]:login'), $newPassword); $I->seeCurrentUrlEquals(\LoginPage::$url); $I->logout(); $I->autoLogin(); $I->seeCurrentUrlEquals(\AdminPanelPage::$url);
<?php /** @type \Codeception\Scenario $scenario */ $scenario->groups('front', 'settings'); $I = new WebGuy\MemberSteps($scenario); $I->am('admin'); $I->wantTo('add my friend as a new user'); $random = md5(microtime()); $I->autoLogin(); $I->amOnPage(\UsersDashboardPage::$url); $I->seeCurrentUrlEquals(\UsersDashboardPage::$url); $I->click(\UsersDashboardPage::$createNewButtonSelector); $I->seeCurrentUrlEquals(\CreateNewUserPage::$url); $I->fillField(\CreateNewUserPage::$usernameFieldSelector, $random); $I->click(\CreateNewUserPage::$submitButtonSelector); $I->seeCurrentUrlEquals(\CreateNewUserPage::$url); $I->seeAlert('user.creation.fail'); // testing validation and data binding $I->seeElement(\CreateNewUserPage::$passwordFieldSelector . '.error'); $I->seeElement(\CreateNewUserPage::$repeatPasswordFieldSelector . '.error'); $I->dontSeeElement(\CreateNewUserPage::$usernameFieldSelector . '.error'); $I->seeInField(\CreateNewUserPage::$usernameFieldSelector, $random); $I->fillField(\CreateNewUserPage::$passwordFieldSelector, $random); $I->click(\CreateNewUserPage::$submitButtonSelector); $I->seeCurrentUrlEquals(\CreateNewUserPage::$url); $I->seeAlert('user.creation.fail'); $I->seeInField(\CreateNewUserPage::$usernameFieldSelector, $random); $I->seeInField(\CreateNewUserPage::$passwordFieldSelector, $random); $I->seeElement(\CreateNewUserPage::$repeatPasswordFieldSelector . '.error'); $I->dontSeeElement(\CreateNewUserPage::$passwordFieldSelector . '.error'); $I->dontSeeElement(\CreateNewUserPage::$usernameFieldSelector . '.error');
<?php /** @type \Codeception\Scenario $scenario */ $scenario->groups('front', 'posts', 'cache'); $I = new WebGuy\MemberSteps($scenario); $I->am('Web developer'); $I->wantTo('Test cache system by writing post and tweaking service settings'); $I->expectTo('See changes instantly'); $I->autoLogin(); // if any other category is modified but the top one, categories may change // positions in sidebar, and this behavior would be much harder to test. $categoryNumber = 0; $I->flushCache(); $stats = \ServiceStatusPage::of($I)->grabStats(); $totalPostsNumber = $stats['totalPosts']; $postsTodayNumber = $stats['postsToday']; $commentsTodayNumber = $stats['commentsToday']; $totalCommentsNumber = $stats['totalComments']; $I->amOnPage(\BlogFeedPage::$url); $categoryTitle = \BlogFeedPage::of($I)->grabCategoryTitle($categoryNumber); $categoryPostCount = \BlogFeedPage::of($I)->grabCategoryPostCount($categoryNumber); $posts = array(); // there were issues with stall cache after series of fast posts, so this // construct verifies that it doesn't happen again for ($i = 0; $i < 5; $i++) { $title = md5(time()) . $i; $I->amOnPage(\BlogFeedPage::$url); $I->dontSee($title); $I->writePost($title, 'superpost is superposted', null, $categoryTitle); $elemId = $I->grabAttributeFrom(\PostPage::$postSelector, 'id'); preg_match('#\\d+#', $elemId, $matches);
<?php use Codeception\Util\Fixtures; /** @type \Codeception\Scenario $scenario */ $scenario->groups('blog', 'front', 'auth'); $lastPost = Fixtures::get('data:posts:length') - 1; $penultimatePagePost = $lastPost - 5; $I = new \WebGuy\MemberSteps($scenario); $I->wantTo('read blog'); $I->amGoingTo('read posts from different pages on the main feed and category/author page'); $I->expectTo('see blog posts and encounter 404 on invalid pages'); $I->amOnPage(\BlogFeedPage::$url); $I->see('heading.lastPosts'); $I->see('heading.categories'); $I->see(Fixtures::get("data:posts[{$lastPost}]:title"), 'article'); $I->dontSee(Fixtures::get("data:posts[{$penultimatePagePost}]:title"), 'article'); $I->see('2', 'ul.pagination'); $I->click('2', 'ul.pagination'); $I->seeCurrentUrlEquals(\BlogFeedPage::route(2)); $I->see(Fixtures::get("data:posts[{$penultimatePagePost}]:title"), 'article'); $I->dontSee(Fixtures::get("data:posts[{$lastPost}]:title"), 'article'); $I->amOnPage(\BlogFeedPage::route(ceil(Fixtures::get('data:posts:length') / 5) + 1)); $I->seeHttpErrorPage(404); // categories $I->amOnPage(\BlogFeedPage::$url); $category = \BlogFeedPage::of($I)->getSidebarCategoryTitle(1); $otherCategory = \BlogFeedPage::of($I)->getSidebarCategoryTitle(2); $I->click($category, '.sidebar'); $I->seeCurrentUrlMatches(\CategoryFeedPage::$urlRegexp); $I->seeInTitle($category); $I->see($category, \CategoryFeedPage::$pageHeaderSelector);