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
f1798268
Commit
f1798268
authored
Jun 09, 2014
by
Mark
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
application advanced template tests fixed
parent
4498ccd4
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
134 additions
and
48 deletions
+134
-48
_console.php
apps/advanced/backend/tests/unit/_console.php
+7
-0
DbTestCase.php
apps/advanced/common/tests/unit/DbTestCase.php
+1
-1
_console.php
apps/advanced/common/tests/unit/_console.php
+7
-0
user.php
.../advanced/common/tests/unit/fixtures/data/models/user.php
+14
-0
LoginFormTest.php
apps/advanced/common/tests/unit/models/LoginFormTest.php
+40
-21
_console.php
apps/advanced/console/tests/unit/_console.php
+7
-0
_console.php
apps/advanced/frontend/tests/unit/_console.php
+7
-0
user.php
...dvanced/frontend/tests/unit/fixtures/data/models/user.php
+0
-0
PasswordResetRequestFormTest.php
...ontend/tests/unit/models/PasswordResetRequestFormTest.php
+12
-2
ResetPasswordFormTest.php
...nced/frontend/tests/unit/models/ResetPasswordFormTest.php
+20
-12
SignupFormTest.php
apps/advanced/frontend/tests/unit/models/SignupFormTest.php
+19
-12
No files found.
apps/advanced/backend/tests/unit/_console.php
View file @
f1798268
...
...
@@ -11,5 +11,12 @@ return yii\helpers\ArrayHelper::merge(
'dsn'
=>
'mysql:host=localhost;dbname=yii2_advanced_unit'
,
],
],
'controllerMap'
=>
[
'fixture'
=>
[
'class'
=>
'yii\faker\FixtureController'
,
'fixtureDataPath'
=>
'@backend/tests/unit/fixtures/data'
,
'templatePath'
=>
'@commmon/tests/templates/fixtures'
],
],
]
);
apps/advanced/common/tests/unit/DbTestCase.php
View file @
f1798268
...
...
@@ -4,5 +4,5 @@ namespace common\tests\unit;
class
DbTestCase
extends
\yii\codeception\DbTestCase
{
public
$appConfig
=
'@
frontend
/tests/unit/_config.php'
;
public
$appConfig
=
'@
common
/tests/unit/_config.php'
;
}
apps/advanced/common/tests/unit/_console.php
View file @
f1798268
...
...
@@ -11,5 +11,12 @@ return yii\helpers\ArrayHelper::merge(
'dsn'
=>
'mysql:host=localhost;dbname=yii2_advanced_unit'
,
],
],
'controllerMap'
=>
[
'fixture'
=>
[
'class'
=>
'yii\faker\FixtureController'
,
'fixtureDataPath'
=>
'@common/tests/unit/fixtures/data'
,
'templatePath'
=>
'@common/tests/templates/fixtures'
],
],
]
);
apps/advanced/common/tests/unit/fixtures/data/models/user.php
0 → 100644
View file @
f1798268
<?php
return
[
[
'username'
=>
'bayer.hudson'
,
'auth_key'
=>
'HP187Mvq7Mmm3CTU80dLkGmni_FUH_lR'
,
//password_0
'password_hash'
=>
'$2y$13$EjaPFBnZOQsHdGuHI.xvhuDp1fHpo8hKRSk6yshqa9c5EG8s3C3lO'
,
'password_reset_token'
=>
'ExzkCOaYc1L8IOBs4wdTGGbgNiG3Wz1I_1402312317'
,
'created_at'
=>
'1402312317'
,
'updated_at'
=>
'1402312317'
,
'email'
=>
'nicole.paucek@schultz.info'
,
],
];
apps/advanced/common/tests/unit/models/LoginFormTest.php
View file @
f1798268
...
...
@@ -3,14 +3,29 @@
namespace
common\tests\unit\models
;
use
Yii
;
use
frontend\tests\unit\TestCase
;
use
common\models\User
;
use
yii\helpers\Security
;
use
common\tests\unit\DbTestCase
;
use
Codeception\Specify
;
use
common\models\LoginForm
;
use
common\tests\fixtures\UserFixture
;
class
LoginFormTest
extends
TestCase
class
LoginFormTest
extends
Db
TestCase
{
use
\Codeception\Specify
;
use
Specify
;
public
function
setUp
()
{
parent
::
setUp
();
Yii
::
configure
(
Yii
::
$app
,
[
'components'
=>
[
'user'
=>
[
'class'
=>
'yii\web\User'
,
'identityClass'
=>
'common\models\User'
,
],
],
]);
}
protected
function
tearDown
()
{
...
...
@@ -20,10 +35,10 @@ class LoginFormTest extends TestCase
public
function
testLoginNoUser
()
{
$model
=
$this
->
mockUser
(
null
);
$model
->
username
=
'some_username'
;
$model
->
password
=
'some_password'
;
$model
=
new
LoginForm
([
'username'
=>
'not_existing_username'
,
'password'
=>
'not_existing_password'
,
])
;
$this
->
specify
(
'user should not be able to login, when there is no identity'
,
function
()
use
(
$model
)
{
expect
(
'model should not login user'
,
$model
->
login
())
->
false
();
...
...
@@ -33,10 +48,10 @@ class LoginFormTest extends TestCase
public
function
testLoginWrongPassword
()
{
$model
=
$this
->
mockUser
(
new
User
([
'password_hash'
=>
Security
::
generatePasswordHash
(
'will-not-match'
)]));
$model
->
username
=
'demo'
;
$model
->
password
=
'wrong-password'
;
$model
=
new
LoginForm
([
'username'
=>
'bayer.hudson'
,
'password'
=>
'wrong_password'
,
])
;
$this
->
specify
(
'user should not be able to login with wrong password'
,
function
()
use
(
$model
)
{
expect
(
'model should not login user'
,
$model
->
login
())
->
false
();
...
...
@@ -47,10 +62,11 @@ class LoginFormTest extends TestCase
public
function
testLoginCorrect
()
{
$model
=
$this
->
mockUser
(
new
User
([
'password_hash'
=>
Security
::
generatePasswordHash
(
'demo'
)]));
$model
->
username
=
'demo'
;
$model
->
password
=
'demo'
;
$model
=
new
LoginForm
([
'username'
=>
'bayer.hudson'
,
'password'
=>
'password_0'
,
]);
$this
->
specify
(
'user should be able to login with correct credentials'
,
function
()
use
(
$model
)
{
expect
(
'model should login user'
,
$model
->
login
())
->
true
();
...
...
@@ -59,11 +75,14 @@ class LoginFormTest extends TestCase
});
}
p
rivate
function
mockUser
(
$user
)
p
ublic
function
fixtures
(
)
{
$loginForm
=
$this
->
getMock
(
'common\models\LoginForm'
,
[
'getUser'
]);
$loginForm
->
expects
(
$this
->
any
())
->
method
(
'getUser'
)
->
will
(
$this
->
returnValue
(
$user
));
return
$loginForm
;
return
[
'user'
=>
[
'class'
=>
UserFixture
::
className
(),
'dataFile'
=>
'@common/tests/unit/fixtures/data/models/user.php'
],
];
}
}
apps/advanced/console/tests/unit/_console.php
View file @
f1798268
...
...
@@ -11,5 +11,12 @@ return yii\helpers\ArrayHelper::merge(
'dsn'
=>
'mysql:host=localhost;dbname=yii2_advanced_unit'
,
],
],
'controllerMap'
=>
[
'fixture'
=>
[
'class'
=>
'yii\faker\FixtureController'
,
'fixtureDataPath'
=>
'@console/tests/unit/fixtures/data'
,
'templatePath'
=>
'@common/tests/templates/fixtures'
],
],
]
);
apps/advanced/frontend/tests/unit/_console.php
View file @
f1798268
...
...
@@ -11,5 +11,12 @@ return yii\helpers\ArrayHelper::merge(
'dsn'
=>
'mysql:host=localhost;dbname=yii2_advanced_unit'
,
],
],
'controllerMap'
=>
[
'fixture'
=>
[
'class'
=>
'yii\faker\FixtureController'
,
'fixtureDataPath'
=>
'@console/tests/unit/fixtures/data'
,
'templatePath'
=>
'@common/tests/templates/fixtures'
],
],
]
);
apps/advanced/frontend/tests/unit/fixtures/data/user.php
→
apps/advanced/frontend/tests/unit/fixtures/data/
models/
user.php
View file @
f1798268
File moved
apps/advanced/frontend/tests/unit/models/PasswordResetRequestFormTest.php
View file @
f1798268
...
...
@@ -7,14 +7,16 @@ use frontend\tests\unit\DbTestCase;
use
frontend\models\PasswordResetRequestForm
;
use
common\tests\fixtures\UserFixture
;
use
common\models\User
;
use
Codeception\Specify
;
class
PasswordResetRequestFormTest
extends
DbTestCase
{
use
\Codeception\
Specify
;
use
Specify
;
protected
function
setUp
()
{
parent
::
setUp
();
Yii
::
$app
->
mail
->
fileTransportCallback
=
function
(
$mailer
,
$message
)
{
return
'testing_message.eml'
;
};
...
...
@@ -23,23 +25,28 @@ class PasswordResetRequestFormTest extends DbTestCase
protected
function
tearDown
()
{
@
unlink
(
$this
->
getMessageFile
());
parent
::
tearDown
();
}
public
function
testSendEmailWrongUser
()
{
$this
->
specify
(
'no user with such email, message should not be send'
,
function
()
{
$model
=
new
PasswordResetRequestForm
();
$model
->
email
=
'not-existing-email@example.com'
;
expect
(
'email not send'
,
$model
->
sendEmail
())
->
false
();
});
$this
->
specify
(
'user is not active, message should not be send'
,
function
()
{
$model
=
new
PasswordResetRequestForm
();
$model
->
email
=
$this
->
user
[
1
][
'email'
];
expect
(
'email not send'
,
$model
->
sendEmail
())
->
false
();
});
}
...
...
@@ -53,11 +60,13 @@ class PasswordResetRequestFormTest extends DbTestCase
expect
(
'user has valid token'
,
$user
->
password_reset_token
)
->
notNull
();
$this
->
specify
(
'message has correct format'
,
function
()
use
(
$model
)
{
expect
(
'message file exists'
,
file_exists
(
$this
->
getMessageFile
()))
->
true
();
$message
=
file_get_contents
(
$this
->
getMessageFile
());
expect
(
'message "from" is correct'
,
$message
)
->
contains
(
Yii
::
$app
->
params
[
'supportEmail'
]);
expect
(
'message "to" is correct'
,
$message
)
->
contains
(
$model
->
email
);
});
}
...
...
@@ -66,7 +75,7 @@ class PasswordResetRequestFormTest extends DbTestCase
return
[
'user'
=>
[
'class'
=>
UserFixture
::
className
(),
'dataFile'
=>
'@frontend/tests/unit/fixtures/data/user.php'
'dataFile'
=>
'@frontend/tests/unit/fixtures/data/
models/
user.php'
],
];
}
...
...
@@ -75,4 +84,5 @@ class PasswordResetRequestFormTest extends DbTestCase
{
return
Yii
::
getAlias
(
Yii
::
$app
->
mail
->
fileTransportPath
)
.
'/testing_message.eml'
;
}
}
apps/advanced/frontend/tests/unit/models/ResetPasswordFormTest.php
View file @
f1798268
...
...
@@ -9,19 +9,26 @@ use frontend\models\ResetPasswordForm;
class
ResetPasswordFormTest
extends
DbTestCase
{
use
\Codeception\Specify
;
/**
* @expectedException yii\base\InvalidParamException
*/
public
function
testResetWrongToken
()
{
new
ResetPasswordForm
(
'notexistingtoken_1391882543'
);
}
/**
* @expectedException yii\base\InvalidParamException
*/
public
function
testResetEmptyToken
()
{
new
ResetPasswordForm
(
''
);
}
public
function
testReset
Password
()
public
function
testReset
CorrectToken
()
{
$this
->
specify
(
'wrong reset token'
,
function
()
{
$this
->
setExpectedException
(
'\Exception'
,
'Wrong password reset token.'
);
new
ResetPasswordForm
(
'notexistingtoken_1391882543'
);
});
$this
->
specify
(
'not correct token'
,
function
()
{
$this
->
setExpectedException
(
'yii\base\InvalidParamException'
,
'Password reset token cannot be blank.'
);
new
ResetPasswordForm
(
''
);
});
$form
=
new
ResetPasswordForm
(
$this
->
user
[
0
][
'password_reset_token'
]);
expect
(
'password should be resetted'
,
$form
->
resetPassword
())
->
true
();
}
public
function
fixtures
()
...
...
@@ -29,8 +36,9 @@ class ResetPasswordFormTest extends DbTestCase
return
[
'user'
=>
[
'class'
=>
UserFixture
::
className
(),
'dataFile'
=>
'@frontend/tests/unit/fixtures/data/user.php'
'dataFile'
=>
'@frontend/tests/unit/fixtures/data/
models/
user.php'
],
];
}
}
apps/advanced/frontend/tests/unit/models/SignupFormTest.php
View file @
f1798268
...
...
@@ -4,23 +4,26 @@ namespace frontend\tests\unit\models;
use
frontend\tests\unit\DbTestCase
;
use
common\tests\fixtures\UserFixture
;
use
Codeception\Specify
;
use
frontend\models\SignupForm
;
class
SignupFormTest
extends
DbTestCase
{
use
\Codeception\
Specify
;
use
Specify
;
public
function
testCorrectSignup
()
{
$model
=
$this
->
getMock
(
'frontend\models\SignupForm'
,
[
'validate'
]);
$model
->
expects
(
$this
->
once
())
->
method
(
'validate'
)
->
will
(
$this
->
returnValue
(
true
));
$model
->
username
=
'some_username'
;
$model
->
email
=
'some_email@example.com'
;
$model
->
password
=
'some_password'
;
$model
=
new
SignupForm
([
'username'
=>
'some_username'
,
'email'
=>
'some_email@example.com'
,
'password'
=>
'some_password'
,
]);
$user
=
$model
->
signup
();
$this
->
assertInstanceOf
(
'common\models\User'
,
$user
);
$this
->
assertInstanceOf
(
'common\models\User'
,
$user
,
'user should be valid'
);
expect
(
'username should be correct'
,
$user
->
username
)
->
equals
(
'some_username'
);
expect
(
'email should be correct'
,
$user
->
email
)
->
equals
(
'some_email@example.com'
);
expect
(
'password should be correct'
,
$user
->
validatePassword
(
'some_password'
))
->
true
();
...
...
@@ -28,10 +31,13 @@ class SignupFormTest extends DbTestCase
public
function
testNotCorrectSignup
()
{
$model
=
$this
->
getMock
(
'frontend\models\SignupForm'
,
[
'validate'
]);
$model
->
expects
(
$this
->
once
())
->
method
(
'validate'
)
->
will
(
$this
->
returnValue
(
false
));
$model
=
new
SignupForm
([
'username'
=>
'troy.becker'
,
'email'
=>
'nicolas.dianna@hotmail.com'
,
'password'
=>
'some_password'
,
]);
expect
(
'user should not be created'
,
$model
->
signup
())
->
null
();
expect
(
'user
name and email are in use, user
should not be created'
,
$model
->
signup
())
->
null
();
}
public
function
fixtures
()
...
...
@@ -39,8 +45,9 @@ class SignupFormTest extends DbTestCase
return
[
'user'
=>
[
'class'
=>
UserFixture
::
className
(),
'dataFile'
=>
false
,
//do not load test data, only table cleanup
'dataFile'
=>
'@frontend/tests/unit/fixtures/data/models/user.php'
,
],
];
}
}
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