Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
cf61967d
Commit
cf61967d
authored
Dec 17, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored codeception/BasePage.
parent
4d1390ce
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
55 additions
and
38 deletions
+55
-38
AboutPage.php
apps/basic/tests/_pages/AboutPage.php
+2
-3
ContactPage.php
apps/basic/tests/_pages/ContactPage.php
+1
-1
LoginPage.php
apps/basic/tests/_pages/LoginPage.php
+1
-1
AboutCept.php
apps/basic/tests/acceptance/AboutCept.php
+1
-1
ContactCept.php
apps/basic/tests/acceptance/ContactCept.php
+2
-2
LoginCept.php
apps/basic/tests/acceptance/LoginCept.php
+2
-2
AboutCept.php
apps/basic/tests/functional/AboutCept.php
+1
-1
ContactCept.php
apps/basic/tests/functional/ContactCept.php
+2
-2
LoginCept.php
apps/basic/tests/functional/LoginCept.php
+2
-2
BasePage.php
extensions/yii/codeception/BasePage.php
+41
-23
No files found.
apps/basic/tests/_pages/AboutPage.php
View file @
cf61967d
...
...
@@ -6,5 +6,5 @@ use yii\codeception\BasePage;
class
AboutPage
extends
BasePage
{
public
static
$URL
=
'?r=site/about'
;
}
\ No newline at end of file
public
$route
=
'site/about'
;
}
apps/basic/tests/_pages/ContactPage.php
View file @
cf61967d
...
...
@@ -6,7 +6,7 @@ use yii\codeception\BasePage;
class
ContactPage
extends
BasePage
{
public
static
$URL
=
'?r=
site/contact'
;
public
$route
=
'
site/contact'
;
/**
* contact form name text field locator
...
...
apps/basic/tests/_pages/LoginPage.php
View file @
cf61967d
...
...
@@ -6,7 +6,7 @@ use yii\codeception\BasePage;
class
LoginPage
extends
BasePage
{
public
static
$URL
=
'?r=
site/login'
;
public
$route
=
'
site/login'
;
/**
* login form username text field locator
...
...
apps/basic/tests/acceptance/AboutCept.php
View file @
cf61967d
...
...
@@ -4,5 +4,5 @@ use tests\_pages\AboutPage;
$I
=
new
WebGuy
(
$scenario
);
$I
->
wantTo
(
'ensure that about works'
);
$I
->
amOnPage
(
AboutPage
::
$URL
);
AboutPage
::
openBy
(
$I
);
$I
->
see
(
'About'
,
'h1'
);
apps/basic/tests/acceptance/ContactCept.php
View file @
cf61967d
...
...
@@ -4,9 +4,9 @@ use tests\_pages\ContactPage;
$I
=
new
WebGuy
(
$scenario
);
$I
->
wantTo
(
'ensure that contact works'
);
$contactPage
=
ContactPage
::
of
(
$I
);
$I
->
amOnPage
(
ContactPage
::
$URL
);
$contactPage
=
ContactPage
::
openBy
(
$I
);
$I
->
see
(
'Contact'
,
'h1'
);
$I
->
amGoingTo
(
'submit contact form with no data'
);
...
...
apps/basic/tests/acceptance/LoginCept.php
View file @
cf61967d
...
...
@@ -4,9 +4,9 @@ use tests\_pages\LoginPage;
$I
=
new
WebGuy
(
$scenario
);
$I
->
wantTo
(
'ensure that login works'
);
$loginPage
=
LoginPage
::
of
(
$I
);
$I
->
amOnPage
(
LoginPage
::
$URL
);
$loginPage
=
LoginPage
::
openBy
(
$I
);
$I
->
see
(
'Login'
,
'h1'
);
$I
->
amGoingTo
(
'try to login with empty credentials'
);
...
...
apps/basic/tests/functional/AboutCept.php
View file @
cf61967d
...
...
@@ -4,5 +4,5 @@ use tests\_pages\AboutPage;
$I
=
new
TestGuy
(
$scenario
);
$I
->
wantTo
(
'ensure that about works'
);
$I
->
amOnPage
(
AboutPage
::
$URL
);
AboutPage
::
openBy
(
$I
);
$I
->
see
(
'About'
,
'h1'
);
apps/basic/tests/functional/ContactCept.php
View file @
cf61967d
...
...
@@ -4,9 +4,9 @@ use tests\functional\_pages\ContactPage;
$I
=
new
TestGuy
(
$scenario
);
$I
->
wantTo
(
'ensure that contact works'
);
$contactPage
=
ContactPage
::
of
(
$I
);
$I
->
amOnPage
(
ContactPage
::
$URL
);
$contactPage
=
ContactPage
::
openBy
(
$I
);
$I
->
see
(
'Contact'
,
'h1'
);
$I
->
amGoingTo
(
'submit contact form with no data'
);
...
...
apps/basic/tests/functional/LoginCept.php
View file @
cf61967d
...
...
@@ -4,9 +4,9 @@ use tests\functional\_pages\LoginPage;
$I
=
new
TestGuy
(
$scenario
);
$I
->
wantTo
(
'ensure that login works'
);
$loginPage
=
LoginPage
::
of
(
$I
);
$I
->
amOnPage
(
LoginPage
::
$URL
);
$loginPage
=
LoginPage
::
openBy
(
$I
);
$I
->
see
(
'Login'
,
'h1'
);
$I
->
amGoingTo
(
'try to login with empty credentials'
);
...
...
extensions/yii/codeception/BasePage.php
View file @
cf61967d
...
...
@@ -2,54 +2,72 @@
namespace
yii\codeception
;
use
Yii
;
use
yii\base\Component
;
use
yii\base\InvalidConfigException
;
/**
* Represents a web page to test
*
* Pages extend from this class and declare UI map for this page via
* static properties. CSS or XPath allowed.
*
* Here is an example:
* BasePage is the base class for page classes that represent Web pages to be tested.
*
* ```php
* public static $usernameField = '#username';
* public static $formSubmitButton = "#mainForm input[type=submit]";
* ```
* @property string $url the URL to this page
*
* @author Mark Jebri <mark.github@yandex.ru>
* @since 2.0
*/
abstract
class
BasePage
abstract
class
BasePage
extends
Component
{
/**
* @var string include url of current page. This property has to be overwritten by subclasses
* @var string|array the route (controller ID and action ID, e.g. `site/about`) to this page.
* Use array to represent a route with GET parameters. The first element of the array represents
* the route and the rest of the name-value pairs are treated as GET parameters, e.g. `array('site/page', 'name' => 'about')`.
*/
public
static
$URL
=
''
;
public
$route
;
/**
* @var \Codeception\AbstractGuy
* @var \Codeception\AbstractGuy
the testing guy object
*/
protected
$guy
;
/**
* Constructor.
* @param \Codeception\AbstractGuy the testing guy object
*/
public
function
__construct
(
$I
)
{
$this
->
guy
=
$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');
* Returns the URL to this page.
* The URL will be returned by calling the URL manager of the application
* with [[route]] and the provided parameters.
* @param array $params the GET parameters for creating the URL
* @return string the URL to this page
* @throws InvalidConfigException if [[route]] is not set or invalid
*/
public
static
function
route
(
$param
)
public
function
getUrl
(
$params
=
[]
)
{
return
static
::
$URL
.
$param
;
if
(
is_string
(
$this
->
route
))
{
return
Yii
::
$app
->
getUrlManager
()
->
createUrl
(
$this
->
route
,
$params
);
}
elseif
(
is_array
(
$this
->
route
)
&&
isset
(
$this
->
route
[
0
]))
{
$route
=
$this
->
route
[
0
];
$ps
=
$this
->
route
;
unset
(
$this
->
route
[
0
]);
return
Yii
::
$app
->
getUrlManager
()
->
createUrl
(
$route
,
array_merge
(
$ps
,
$params
));
}
else
{
throw
new
InvalidConfigException
(
'The "route" property must be set.'
);
}
}
/**
* @param $I
* @return static
* Creates a page instance and sets the test guy to use [[url]].
* @param \Codeception\AbstractGuy $I the test guy instance
* @param array $params the GET parameters to be used to generate [[url]]
* @return static the page instance
*/
public
static
function
o
f
(
$I
)
public
static
function
o
penBy
(
$I
,
$params
=
[]
)
{
return
new
static
(
$I
);
$page
=
new
static
(
$I
);
$I
->
amOnPage
(
$page
->
getUrl
(
$params
));
return
$page
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment