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
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Rotua Panjaitan
yii2
Commits
e105f1ae
Commit
e105f1ae
authored
Jul 06, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of github.com:yiisoft/yii2
parents
ba6c10eb
e2bdfbb7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
117 additions
and
1 deletion
+117
-1
AssetManager.php
framework/yii/web/AssetManager.php
+1
-1
AutoTimestampTest.php
tests/unit/framework/behaviors/AutoTimestampTest.php
+116
-0
No files found.
framework/yii/web/AssetManager.php
View file @
e105f1ae
...
...
@@ -126,8 +126,8 @@ class AssetManager extends Component
$config
=
$this
->
bundles
[
$name
];
if
(
!
isset
(
$config
[
'class'
]))
{
$config
[
'class'
]
=
'yii\\web\\AssetBundle'
;
$this
->
bundles
[
$name
]
=
Yii
::
createObject
(
$config
);
}
$this
->
bundles
[
$name
]
=
Yii
::
createObject
(
$config
);
}
return
$this
->
bundles
[
$name
];
...
...
tests/unit/framework/behaviors/AutoTimestampTest.php
0 → 100644
View file @
e105f1ae
<?php
namespace
yiiunit\framework\behaviors
;
use
Yii
;
use
yiiunit\TestCase
;
use
yii\db\Connection
;
use
yii\db\ActiveRecord
;
use
yii\behaviors\AutoTimestamp
;
/**
* Unit test for [[\yii\behaviors\AutoTimestamp]].
* @see AutoTimestamp
*/
class
AutoTimestampTest
extends
TestCase
{
/**
* @var Connection test db connection
*/
protected
$dbConnection
;
public
static
function
setUpBeforeClass
()
{
if
(
!
extension_loaded
(
'pdo'
)
||
!
extension_loaded
(
'pdo_sqlite'
))
{
static
::
markTestSkipped
(
'PDO and SQLite extensions are required.'
);
}
}
public
function
setUp
()
{
$this
->
mockApplication
(
array
(
'components'
=>
array
(
'db'
=>
array
(
'class'
=>
'\yii\db\Connection'
,
'dsn'
=>
'sqlite::memory:'
,
)
)
)
);
$columns
=
array
(
'id'
=>
'pk'
,
'create_time'
=>
'integer'
,
'update_time'
=>
'integer'
,
);
Yii
::
$app
->
getDb
()
->
createCommand
()
->
createTable
(
'test_auto_timestamp'
,
$columns
)
->
execute
();
}
public
function
tearDown
()
{
Yii
::
$app
->
getDb
()
->
close
();
parent
::
tearDown
();
}
// Tests :
public
function
testNewRecord
()
{
$currentTime
=
time
();
$model
=
new
ActiveRecordAutoTimestamp
();
$model
->
save
(
false
);
$this
->
assertTrue
(
$model
->
create_time
>=
$currentTime
);
$this
->
assertTrue
(
$model
->
update_time
>=
$currentTime
);
}
/**
* @depends testNewRecord
*/
public
function
testUpdateRecord
()
{
$currentTime
=
time
();
$model
=
new
ActiveRecordAutoTimestamp
();
$model
->
save
(
false
);
$enforcedTime
=
$currentTime
-
100
;
$model
->
create_time
=
$enforcedTime
;
$model
->
update_time
=
$enforcedTime
;
$model
->
save
(
false
);
$this
->
assertEquals
(
$enforcedTime
,
$model
->
create_time
,
'Create time has been set on update!'
);
$this
->
assertTrue
(
$model
->
update_time
>=
$currentTime
,
'Update time has NOT been set on update!'
);
}
}
/**
* Test Active Record class with [[AutoTimestamp]] behavior attached.
*
* @property integer $id
* @property integer $create_time
* @property integer $update_time
*/
class
ActiveRecordAutoTimestamp
extends
ActiveRecord
{
public
function
behaviors
()
{
return
array
(
'timestamp'
=>
array
(
'class'
=>
AutoTimestamp
::
className
(),
'attributes'
=>
array
(
static
::
EVENT_BEFORE_INSERT
=>
array
(
'create_time'
,
'update_time'
),
static
::
EVENT_BEFORE_UPDATE
=>
'update_time'
,
),
),
);
}
public
static
function
tableName
()
{
return
'test_auto_timestamp'
;
}
}
\ No newline at end of file
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