Created
August 1, 2013 09:17
-
-
Save jamband/6129797 to your computer and use it in GitHub Desktop.
Codeception::PageObject acceptance sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$yii = dirname(__FILE__).'/../../../vendor/yiisoft/yii/framework/yii.php'; | |
$config = dirname(__FILE__).'/../../config/test.php'; | |
require_once(dirname(__FILE__).'/../../helpers/functions.php'); | |
require_once($yii); | |
if (!Yii::app()) { | |
Yii::createWebApplication($config); | |
} | |
$error404 = 'データがありません。'; | |
$error400 = '無効なリクエストです。'; | |
$requiredErrorMessage = function ($label) { | |
return strtr(Yii::t('yii','{attribute} cannot be blank.'), array( | |
'{attribute}' => $label, | |
)); | |
}; | |
\Codeception\Util\Autoload::registerSuffix('Page', __DIR__.DIRECTORY_SEPARATOR.'_pages'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$scenario->group('containJs'); | |
$I = new WebGuy($scenario); | |
$I->amOnPage(WordPage::URL_EDIT); | |
SitePage::of($I)->login(); | |
$I->amGoingTo('400エラーの確認'); | |
$I->amOnPage(WordPage::URL_DELETE.'/5'); | |
$I->see($error400); | |
$I->amOnPage(WordPage::URL_EDIT); | |
$I->see(WordPage::$maxResult.WordPage::$resultLabel); | |
$I->see(WordPage::$data['en5']); | |
$I->click(WordPage::$deleteLinkLabel); | |
$I->seeInPopup(param('confirmDelete')); | |
$I->acceptPopup(); | |
$I->see(WordPage::$enLabel.'の削除が完了いたしました。'); | |
$I->see((WordPage::$maxResult - 1).WordPage::$resultLabel); | |
$I->dontSee(WordPage::$data['en5']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$I = new WebGuy($scenario); | |
$I->amOnPage(WordPage::URL_EDIT); | |
SitePage::of($I)->login(); | |
$I->amGoingTo('データが全件表示されているか確認'); | |
$I->see(WordPage::$maxResult.WordPage::$resultLabel); | |
WordPage::of($I)->checkSortArea(); | |
$I->amGoingTo('データ検索フォームの確認'); | |
$I->fillfield(WordPage::$searchField, ' a '); | |
$I->click(WordPage::$searchButton); | |
$I->seeInField(WordPage::$searchField, 'a'); | |
$I->see('1'.WordPage::$resultLabel); | |
$I->see(WordPage::$data['en1']); | |
$I->amGoingTo('データ追加フォームの確認'); | |
$I->click(WordPage::$createButton); | |
$I->see($requiredErrorMessage(WordPage::$enLabel)); | |
$I->see($requiredErrorMessage(WordPage::$jaLabel)); | |
$I->fillfield(WordPage::$enField, ' hello '); | |
$I->fillfield(WordPage::$jaField, ' こんにちは '); | |
$I->click(WordPage::$createButton); | |
$I->see(WordPage::$enLabel.'の追加が完了いたしました。'); | |
$I->see('hello'); | |
$I->see('こんにちは'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$I = new WebGuy($scenario); | |
$I->amOnPage(WordPage::URL_INDEX); | |
SitePage::of($I)->login(); | |
$I->amGoingTo('データが全件表示されているか確認'); | |
$I->see(WordPage::$maxResult.WordPage::$resultLabel); | |
WordPage::of($I)->checkSortArea(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$I = new WebGuy($scenario); | |
$I->amOnPage('/'); | |
SitePage::of($I)->login('', ''); | |
$I->see(SitePage::$loginErrorMessage); | |
SitePage::of($I)->login(SitePage::USERNAME, ''); | |
$I->see(SitePage::$loginErrorMessage); | |
SitePage::of($I)->login(''); | |
$I->see(SitePage::$loginErrorMessage); | |
SitePage::of($I)->login(); | |
$I->see(SitePage::$logoutButton); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$I = new WebGuy($scenario); | |
$I->amOnPage('/'); | |
SitePage::of($I)->login(); | |
$I->see(SitePage::$logoutButton); | |
$I->click(SitePage::$logoutButton); | |
$I->seeInCurrentUrl(SitePage::URL_LOGIN); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class SitePage | |
{ | |
const URL = ''; | |
const URL_LOGIN = '/site/login'; | |
const USERNAME = 'admin'; | |
const PASSWORD = 'adminadmin'; | |
/** | |
* @var WebGuy; | |
*/ | |
protected $webGuy; | |
public static $loginButton = 'ログイン'; | |
public static $logoutButton = 'ログアウト'; | |
public static $usernameField = 'LoginForm[username]'; | |
public static $passwordField = 'LoginForm[password]'; | |
public static $loginErrorMessage = 'ログイン情報が正しくありません。'; | |
public function __construct(WebGuy $I) | |
{ | |
$this->webGuy = $I; | |
} | |
public static function of(WebGuy $I) | |
{ | |
return new static($I); | |
} | |
/** | |
* Basic route example for your current URL | |
* You can append any additional parameter to URL | |
* and use it in tests like: EditPage::route('/123-post'); | |
*/ | |
public static function route($param) | |
{ | |
return static::URL.$param; | |
} | |
public function login($username = SitePage::USERNAME, $password = SitePage::PASSWORD) | |
{ | |
$I = $this->webGuy; | |
$I->fillField(SitePage::$usernameField, $username); | |
$I->fillField(SitePage::$passwordField, $password); | |
$I->click(SitePage::$loginButton); | |
return $this; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$I = new WebGuy($scenario); | |
$I->amOnPage(WordPage::URL_UPDATE); | |
SitePage::of($I)->login(); | |
$I->amGoingTo('404エラーの確認'); | |
$I->amOnPage(WordPage::URL_UPDATE.'/99999'); | |
$I->see($error404); | |
$I->amGoingTo('データ更新フォームの確認'); | |
$I->amOnPage(WordPage::URL_UPDATE.'/1'); | |
$I->seeInField(WordPage::$enField, WordPage::$data['en1']); | |
$I->seeInField(WordPage::$jaField, WordPage::$data['ja1']); | |
$I->fillfield(WordPage::$enField, ''); | |
$I->fillfield(WordPage::$jaField, ''); | |
$I->click(WordPage::$updateButton); | |
$I->see($requiredErrorMessage(WordPage::$enLabel)); | |
$I->see($requiredErrorMessage(WordPage::$jaLabel)); | |
$I->fillfield(WordPage::$enField, ' hello '); | |
$I->fillfield(WordPage::$jaField, ' こんにちは '); | |
$I->click(WordPage::$updateButton); | |
$I->see(WordPage::$enLabel.'の更新が完了いたしました。'); | |
$I->see('hello'); | |
$I->see('こんにちは'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$I = new WebGuy($scenario); | |
$I->amOnPage(WordPage::URL.'/1'); | |
SitePage::of($I)->login(); | |
$I->amGoingTo('404エラーの確認'); | |
$I->amOnPage(WordPage::URL.'/99999'); | |
$I->see($error404); | |
$I->amGoingTo('特定のデータが表示されているか確認'); | |
$I->amOnPage(WordPage::URL.'/1'); | |
$I->see(WordPage::$data['en1']); | |
$I->see(WordPage::$data['ja1']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class WordPage | |
{ | |
const URL = '/word'; | |
const URL_INDEX = '/word/index'; | |
const URL_EDIT = '/word/edit'; | |
const URL_UPDATE = '/word/update'; | |
const URL_DELETE = '/word/delete'; | |
/** | |
* @var WebGuy; | |
*/ | |
protected $webGuy; | |
public static $enLabel = '英単語'; | |
public static $jaLabel = '日本語訳'; | |
public static $createButton = 'Create'; | |
public static $updateButton = 'Update'; | |
public static $searchButton = 'Search'; | |
public static $updateLinkLabel = 'update'; | |
public static $deleteLinkLabel = 'delete'; | |
public static $maxResult = 5; | |
public static $resultLabel = ' results'; | |
public static $searchField = 'q'; | |
public static $enField = 'Word[en]'; | |
public static $jaField = 'Word[ja]'; | |
public static $data = array( | |
'en1' => 'aaa', | |
'ja1' => 'えーえーえー', | |
'en2' => 'bbb', | |
'en5' => 'eee', | |
); | |
public function __construct(WebGuy $I) | |
{ | |
$this->webGuy = $I; | |
} | |
public static function of(WebGuy $I) | |
{ | |
return new static($I); | |
} | |
/** | |
* Basic route example for your current URL | |
* You can append any additional parameter to URL | |
* and use it in tests like: EditPage::route('/123-post'); | |
*/ | |
public static function route($param) | |
{ | |
return static::URL.$param; | |
} | |
public function checkSortArea() | |
{ | |
$I = $this->webGuy; | |
$I->amGoingTo('データ並び替えリンクの確認'); | |
$I->click('a'); | |
$I->see('1'.WordPage::$resultLabel); | |
$I->see(WordPage::$data['en1']); | |
$I->dontSee(WordPage::$data['en2']); | |
$I->click('b'); | |
$I->see('1'.WordPage::$resultLabel); | |
$I->see(WordPage::$data['en2']); | |
$I->dontSee(WordPage::$data['en1']); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment