Mark
11 years ago
25 changed files with 1959 additions and 876 deletions
@ -0,0 +1,10 @@
|
||||
<?php |
||||
|
||||
namespace tests\_pages; |
||||
|
||||
class AboutPage extends BasePage |
||||
{ |
||||
|
||||
public static $URL = '?r=site/about'; |
||||
|
||||
} |
@ -0,0 +1,45 @@
|
||||
<?php |
||||
|
||||
namespace tests\_pages; |
||||
|
||||
class BasePage |
||||
{ |
||||
|
||||
// include url of current page |
||||
public static $URL = ''; |
||||
|
||||
/** |
||||
* Declare UI map for this page here. CSS or XPath allowed. |
||||
* public static $usernameField = '#username'; |
||||
* public static $formSubmitButton = "#mainForm input[type=submit]"; |
||||
*/ |
||||
|
||||
/** |
||||
* 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; |
||||
} |
||||
|
||||
/** |
||||
* @var |
||||
*/ |
||||
protected $guy; |
||||
|
||||
public function __construct($I) |
||||
{ |
||||
$this->guy = $I; |
||||
} |
||||
|
||||
/** |
||||
* @return $this |
||||
*/ |
||||
public static function of($I) |
||||
{ |
||||
return new static($I); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,63 @@
|
||||
<?php |
||||
|
||||
namespace tests\_pages; |
||||
|
||||
class ContactPage extends BasePage |
||||
{ |
||||
|
||||
public static $URL = '?r=site/contact'; |
||||
|
||||
/** |
||||
* contact form name text field locator |
||||
* @var string |
||||
*/ |
||||
public $name = 'input[name="ContactForm[name]"]'; |
||||
|
||||
/** |
||||
* contact form email text field locator |
||||
* @var string |
||||
*/ |
||||
public $email = 'input[name="ContactForm[email]"]'; |
||||
|
||||
/** |
||||
* contact form subject text field locator |
||||
* @var string |
||||
*/ |
||||
public $subject = 'input[name="ContactForm[subject]"]'; |
||||
|
||||
/** |
||||
* contact form body textarea locator |
||||
* @var string |
||||
*/ |
||||
public $body = 'textarea[name="ContactForm[body]"]'; |
||||
|
||||
/** |
||||
* contact form verification code text field locator |
||||
* @var string |
||||
*/ |
||||
public $verifyCode = 'input[name="ContactForm[verifyCode]"]'; |
||||
|
||||
/** |
||||
* contact form submit button |
||||
* @var string |
||||
*/ |
||||
public $button = 'button[type=submit]'; |
||||
|
||||
/** |
||||
* |
||||
* @param array $contactData |
||||
*/ |
||||
public function submit(array $contactData) |
||||
{ |
||||
if (!empty($contactData)) |
||||
{ |
||||
$this->guy->fillField($this->name,$contactData['name']); |
||||
$this->guy->fillField($this->email,$contactData['email']); |
||||
$this->guy->fillField($this->subject,$contactData['subject']); |
||||
$this->guy->fillField($this->body,$contactData['body']); |
||||
$this->guy->fillField($this->verifyCode,$contactData['verifyCode']); |
||||
} |
||||
$this->guy->click($this->button); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,40 @@
|
||||
<?php |
||||
|
||||
namespace tests\_pages; |
||||
|
||||
class LoginPage extends BasePage |
||||
{ |
||||
|
||||
public static $URL = '?r=site/login'; |
||||
|
||||
/** |
||||
* login form username text field locator |
||||
* @var string |
||||
*/ |
||||
public $username = 'input[name="LoginForm[username]"]'; |
||||
|
||||
/** |
||||
* login form password text field locator |
||||
* @var string |
||||
*/ |
||||
public $password = 'input[name="LoginForm[password]"]'; |
||||
|
||||
/** |
||||
* login form submit button locator |
||||
* @var string |
||||
*/ |
||||
public $button = 'button[type=submit]'; |
||||
|
||||
/** |
||||
* |
||||
* @param string $username |
||||
* @param string $password |
||||
*/ |
||||
public function login($username, $password) |
||||
{ |
||||
$this->guy->fillField($this->username,$username); |
||||
$this->guy->fillField($this->password,$password); |
||||
$this->guy->click($this->button); |
||||
} |
||||
|
||||
} |
@ -1,5 +1,7 @@
|
||||
<?php |
||||
use tests\_pages\AboutPage; |
||||
|
||||
$I = new WebGuy($scenario); |
||||
$I->wantTo('ensure that about works'); |
||||
$I->amOnPage('?r=site/about'); |
||||
$I->amOnPage(AboutPage::$URL); |
||||
$I->see('About', 'h1'); |
||||
|
@ -1,23 +1,26 @@
|
||||
<?php |
||||
use tests\_pages\LoginPage; |
||||
|
||||
$I = new WebGuy($scenario); |
||||
$I->wantTo('ensure that login works'); |
||||
$I->amOnPage('?r=site/login'); |
||||
$loginPage = LoginPage::of($I); |
||||
|
||||
$I->amOnPage(LoginPage::$URL); |
||||
$I->see('Login', 'h1'); |
||||
|
||||
$I->submitForm('#login-form', []); |
||||
$I->dontSee('Logout (admin)'); |
||||
$I->see('Username cannot be blank'); |
||||
$I->see('Password cannot be blank'); |
||||
$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->submitForm('#login-form', [ |
||||
'LoginForm[username]' => 'admin', |
||||
'LoginForm[password]' => 'wrong', |
||||
]); |
||||
$I->dontSee('Logout (admin)'); |
||||
$I->see('Incorrect username or password'); |
||||
$I->amGoingTo('try to login with wrong credentials'); |
||||
$loginPage->login('admin', 'wrong'); |
||||
$I->expectTo('see validations errors'); |
||||
$I->see('Incorrect username or password.'); |
||||
|
||||
$I->submitForm('#login-form', [ |
||||
'LoginForm[username]' => 'admin', |
||||
'LoginForm[password]' => 'admin', |
||||
]); |
||||
$I->amGoingTo('try to login with correct credentials'); |
||||
$loginPage->login('admin', 'admin'); |
||||
$I->wait(3); |
||||
$I->expectTo('see user info'); |
||||
$I->see('Logout (admin)'); |
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,2 +1,11 @@
|
||||
<?php |
||||
// Here you can initialize variables that will for your tests |
||||
|
||||
$config = require(__DIR__.'/../yii_bootstrap.php'); |
||||
|
||||
$config = yii\helpers\ArrayHelper::merge( |
||||
$config, |
||||
require(__DIR__ . '/../../config/codeception/acceptance.php') |
||||
); |
||||
|
||||
$application = new yii\web\Application($config); |
||||
|
@ -1,5 +1,8 @@
|
||||
<?php |
||||
|
||||
use tests\_pages\AboutPage; |
||||
|
||||
$I = new TestGuy($scenario); |
||||
$I->wantTo('ensure that about works'); |
||||
$I->amOnPage('?r=site/about'); |
||||
$I->amOnPage(AboutPage::$URL); |
||||
$I->see('About', 'h1'); |
||||
|
@ -1,23 +1,25 @@
|
||||
<?php |
||||
use tests\functional\_pages\LoginPage; |
||||
|
||||
$I = new TestGuy($scenario); |
||||
$I->wantTo('ensure that login works'); |
||||
$I->amOnPage('?r=site/login'); |
||||
$loginPage = LoginPage::of($I); |
||||
|
||||
$I->amOnPage(LoginPage::$URL); |
||||
$I->see('Login', 'h1'); |
||||
|
||||
$I->submitForm('#login-form', []); |
||||
$I->dontSee('Logout (admin)'); |
||||
$I->see('Username cannot be blank'); |
||||
$I->see('Password cannot be blank'); |
||||
$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->submitForm('#login-form', [ |
||||
'LoginForm[username]' => 'admin', |
||||
'LoginForm[password]' => 'wrong', |
||||
]); |
||||
$I->dontSee('Logout (admin)'); |
||||
$I->see('Incorrect username or password'); |
||||
$I->amGoingTo('try to login with wrong credentials'); |
||||
$loginPage->login('admin', 'wrong'); |
||||
$I->expectTo('see validations errors'); |
||||
$I->see('Incorrect username or password.'); |
||||
|
||||
$I->submitForm('#login-form', [ |
||||
'LoginForm[username]' => 'admin', |
||||
'LoginForm[password]' => 'admin', |
||||
]); |
||||
$I->amGoingTo('try to login with correct credentials'); |
||||
$loginPage->login('admin', 'admin'); |
||||
$I->expectTo('see user info'); |
||||
$I->see('Logout (admin)'); |
||||
|
@ -1,2 +1,10 @@
|
||||
<?php |
||||
// Here you can initialize variables that will for your tests |
||||
|
||||
$config = require(__DIR__.'/../yii_bootstrap.php'); |
||||
|
||||
$config = yii\helpers\ArrayHelper::merge( |
||||
$config, |
||||
require(__DIR__ . '/../../config/codeception/functional.php') |
||||
); |
||||
|
||||
$application = new yii\web\Application($config); |
||||
|
@ -0,0 +1,56 @@
|
||||
<?php |
||||
|
||||
namespace tests\functional\_pages; |
||||
|
||||
class ContactPage extends \tests\_pages\ContactPage |
||||
{ |
||||
|
||||
/** |
||||
* contact form name text field locator |
||||
* @var string |
||||
*/ |
||||
public $name = 'ContactForm[name]'; |
||||
|
||||
/** |
||||
* contact form email text field locator |
||||
* @var string |
||||
*/ |
||||
public $email = 'ContactForm[email]'; |
||||
|
||||
/** |
||||
* contact form subject text field locator |
||||
* @var string |
||||
*/ |
||||
public $subject = 'ContactForm[subject]'; |
||||
|
||||
/** |
||||
* contact form body textarea locator |
||||
* @var string |
||||
*/ |
||||
public $body = 'ContactForm[body]'; |
||||
|
||||
/** |
||||
* contact form verification code text field locator |
||||
* @var string |
||||
*/ |
||||
public $verifyCode = 'ContactForm[verifyCode]'; |
||||
|
||||
/** |
||||
* |
||||
* @param array $contactData |
||||
*/ |
||||
public function submit(array $contactData) |
||||
{ |
||||
if (empty($contactData)) |
||||
$this->guy->submitForm('#contact-form',[]); |
||||
else |
||||
$this->guy->submitForm('#contact-form',[ |
||||
$this->name => $contactData['name'], |
||||
$this->email => $contactData['email'], |
||||
$this->subject => $contactData['subject'], |
||||
$this->body => $contactData['body'], |
||||
$this->verifyCode => $contactData['verifyCode'], |
||||
]); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,33 @@
|
||||
<?php |
||||
|
||||
namespace tests\functional\_pages; |
||||
|
||||
class LoginPage extends \tests\_pages\LoginPage |
||||
{ |
||||
|
||||
/** |
||||
* login form username text field locator |
||||
* @var string |
||||
*/ |
||||
public $username = 'LoginForm[username]'; |
||||
|
||||
/** |
||||
* login form password text field locator |
||||
* @var string |
||||
*/ |
||||
public $password = 'LoginForm[password]'; |
||||
|
||||
/** |
||||
* |
||||
* @param string $username |
||||
* @param string $password |
||||
*/ |
||||
public function login($username, $password) |
||||
{ |
||||
$this->guy->submitForm('#login-form',[ |
||||
$this->username => $username, |
||||
$this->password => $password, |
||||
]); |
||||
} |
||||
|
||||
} |
@ -1,2 +1,10 @@
|
||||
<?php |
||||
// Here you can initialize variables that will for your tests |
||||
|
||||
$config = require(__DIR__.'/../yii_bootstrap.php'); |
||||
|
||||
$config = yii\helpers\ArrayHelper::merge( |
||||
$config, |
||||
require(__DIR__ . '/../../config/codeception/unit.php') |
||||
); |
||||
|
||||
$application = new yii\web\Application($config); |
||||
|
@ -0,0 +1,16 @@
|
||||
<?php |
||||
|
||||
namespace tests\unit\models; |
||||
|
||||
class ContactFormTest extends \PHPUnit_Framework_TestCase |
||||
{ |
||||
|
||||
protected function setUp() |
||||
{ |
||||
} |
||||
|
||||
protected function tearDown() |
||||
{ |
||||
} |
||||
|
||||
} |
@ -0,0 +1,16 @@
|
||||
<?php |
||||
|
||||
namespace tests\unit\models; |
||||
|
||||
class LoginFormTest extends \PHPUnit_Framework_TestCase |
||||
{ |
||||
|
||||
protected function setUp() |
||||
{ |
||||
} |
||||
|
||||
protected function tearDown() |
||||
{ |
||||
} |
||||
|
||||
} |
@ -0,0 +1,27 @@
|
||||
<?php |
||||
|
||||
namespace tests\unit\models; |
||||
|
||||
#use yii\test\DbTestTrait; |
||||
|
||||
class UserTest extends \PHPUnit_Framework_TestCase |
||||
{ |
||||
|
||||
use DbTestTrait; |
||||
|
||||
protected function setUp() |
||||
{ |
||||
/* |
||||
* you can load fixtures in this way |
||||
* |
||||
$this->loadFixtures([ |
||||
'tbl_user', |
||||
]); |
||||
*/ |
||||
} |
||||
|
||||
protected function tearDown() |
||||
{ |
||||
} |
||||
|
||||
} |
@ -0,0 +1,10 @@
|
||||
<?php |
||||
|
||||
defined('YII_DEBUG') or define('YII_DEBUG', true); |
||||
|
||||
defined('YII_ENV') or define('YII_ENV', 'test'); |
||||
|
||||
require_once(__DIR__ . '/../vendor/autoload.php'); |
||||
require_once(__DIR__ . '/../vendor/yiisoft/yii2/yii/Yii.php'); |
||||
|
||||
return require(__DIR__ . '/../config/web.php'); |
Loading…
Reference in new issue