Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
UserAdminV2
Overview
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
庄欣
UserAdminV2
Commits
3998066e
Commit
3998066e
authored
Oct 12, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactored session tests.
parent
ba751b43
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
183 additions
and
184 deletions
+183
-184
laravel/session/manager.php
+6
-5
tests/Cases/Session/SessionManagerTest.php
+177
-48
tests/Cases/Session/SessionPayloadTest.php
+0
-131
No files found.
laravel/session/manager.php
View file @
3998066e
<?php
namespace
Laravel\Session
;
<?php
namespace
Laravel\Session
;
use
Closure
;
use
Laravel\Str
;
use
Laravel\Str
;
use
Laravel\Config
;
use
Laravel\Config
;
use
Laravel\Session\Drivers\Driver
;
use
Laravel\Session\Drivers\Driver
;
...
@@ -12,21 +13,21 @@ class Manager {
...
@@ -12,21 +13,21 @@ class Manager {
*
*
* @var array
* @var array
*/
*/
p
rotected
static
$session
=
array
();
p
ublic
static
$session
=
array
();
/**
/**
* Indicates if the session exists in persistent storage.
* Indicates if the session exists in persistent storage.
*
*
* @var bool
* @var bool
*/
*/
p
rotected
static
$exists
=
true
;
p
ublic
static
$exists
=
true
;
/**
/**
* Indicates if the session ID has been regenerated.
* Indicates if the session ID has been regenerated.
*
*
* @var bool
* @var bool
*/
*/
p
rotected
static
$regenerated
=
false
;
p
ublic
static
$regenerated
=
false
;
/**
/**
* Start the session handling for the current request.
* Start the session handling for the current request.
...
@@ -167,7 +168,7 @@ class Manager {
...
@@ -167,7 +168,7 @@ class Manager {
*/
*/
public
static
function
keep
(
$key
)
public
static
function
keep
(
$key
)
{
{
if
(
is_array
(
$key
))
return
array_map
(
array
(
$this
,
'keep'
),
$key
);
if
(
is_array
(
$key
))
return
array_map
(
array
(
'Laravel\\Session\\Manager'
,
'keep'
),
$key
);
static
::
flash
(
$key
,
static
::
get
(
$key
));
static
::
flash
(
$key
,
static
::
get
(
$key
));
...
@@ -214,7 +215,7 @@ class Manager {
...
@@ -214,7 +215,7 @@ class Manager {
*
*
* @return array
* @return array
*/
*/
p
rotected
static
function
age
()
p
ublic
static
function
age
()
{
{
static
::
$session
[
'last_activity'
]
=
time
();
static
::
$session
[
'last_activity'
]
=
time
();
...
...
tests/Cases/Session/SessionManagerTest.php
View file @
3998066e
This diff is collapsed.
Click to expand it.
tests/Cases/Session/SessionPayloadTest.php
deleted
100644 → 0
View file @
ba751b43
<?php
use
Laravel\Session\Payload
;
class
SessionPayloadTest
extends
PHPUnit_Framework_TestCase
{
public
function
test_has_method_indicates_if_item_exists_in_payload
()
{
$payload
=
new
Payload
(
$this
->
getDummyData
());
$this
->
assertTrue
(
$payload
->
has
(
'name'
));
$this
->
assertTrue
(
$payload
->
has
(
'age'
));
$this
->
assertTrue
(
$payload
->
has
(
'gender'
));
$this
->
assertFalse
(
$payload
->
has
(
'something'
));
$this
->
assertFalse
(
$payload
->
has
(
'id'
));
$this
->
assertFalse
(
$payload
->
has
(
'last_activity'
));
}
public
function
test_get_method_returns_item_from_payload
()
{
$payload
=
new
Payload
(
$this
->
getDummyData
());
$this
->
assertEquals
(
$payload
->
get
(
'name'
),
'Taylor'
);
$this
->
assertEquals
(
$payload
->
get
(
'age'
),
25
);
$this
->
assertEquals
(
$payload
->
get
(
'gender'
),
'male'
);
}
public
function
test_get_method_returns_default_when_item_doesnt_exist
()
{
$payload
=
new
Payload
(
$this
->
getDummyData
());
$this
->
assertNull
(
$payload
->
get
(
'something'
));
$this
->
assertEquals
(
'Taylor'
,
$payload
->
get
(
'something'
,
'Taylor'
));
$this
->
assertEquals
(
'Taylor'
,
$payload
->
get
(
'something'
,
function
()
{
return
'Taylor'
;}));
}
public
function
test_put_method_adds_to_payload
()
{
$payload
=
new
Payload
(
$this
->
getDummyData
());
$payload
->
put
(
'name'
,
'Weldon'
);
$payload
->
put
(
'workmate'
,
'Joe'
);
$this
->
assertEquals
(
$payload
->
session
[
'data'
][
'name'
],
'Weldon'
);
$this
->
assertEquals
(
$payload
->
session
[
'data'
][
'workmate'
],
'Joe'
);
$this
->
assertInstanceOf
(
'Laravel\\Session\\Payload'
,
$payload
->
put
(
'something'
,
'test'
));
}
public
function
test_flash_method_puts_item_in_flash_data
()
{
$payload
=
new
Payload
(
array
());
$payload
->
flash
(
'name'
,
'Taylor'
);
$this
->
assertEquals
(
$payload
->
session
[
'data'
][
':new:name'
],
'Taylor'
);
$this
->
assertInstanceOf
(
'Laravel\\Session\\Payload'
,
$payload
->
flash
(
'something'
,
'test'
));
}
public
function
test_reflash_keeps_all_session_data
()
{
$payload
=
new
Payload
(
array
(
'data'
=>
array
(
':old:name'
=>
'Taylor'
,
':old:age'
=>
25
)));
$payload
->
reflash
();
$this
->
assertTrue
(
isset
(
$payload
->
session
[
'data'
][
':new:name'
]));
$this
->
assertTrue
(
isset
(
$payload
->
session
[
'data'
][
':new:age'
]));
$this
->
assertFalse
(
isset
(
$payload
->
session
[
'data'
][
':old:name'
]));
$this
->
assertFalse
(
isset
(
$payload
->
session
[
'data'
][
':old:age'
]));
}
public
function
test_keep_method_keeps_specified_session_data
()
{
$payload
=
new
Payload
(
array
(
'data'
=>
array
(
':old:name'
=>
'Taylor'
,
':old:age'
=>
25
)));
$payload
->
keep
(
'name'
);
$this
->
assertTrue
(
isset
(
$payload
->
session
[
'data'
][
':new:name'
]));
$this
->
assertFalse
(
isset
(
$payload
->
session
[
'data'
][
':old:name'
]));
$payload
=
new
Payload
(
array
(
'data'
=>
array
(
':old:name'
=>
'Taylor'
,
':old:age'
=>
25
)));
$payload
->
keep
(
array
(
'name'
,
'age'
));
$this
->
assertTrue
(
isset
(
$payload
->
session
[
'data'
][
':new:name'
]));
$this
->
assertTrue
(
isset
(
$payload
->
session
[
'data'
][
':new:age'
]));
$this
->
assertFalse
(
isset
(
$payload
->
session
[
'data'
][
':old:name'
]));
$this
->
assertFalse
(
isset
(
$payload
->
session
[
'data'
][
':old:age'
]));
}
public
function
test_flush_method_clears_payload_data
()
{
$payload
=
new
Payload
(
array
(
'data'
=>
array
(
'name'
=>
'Taylor'
)));
$payload
->
flush
();
$this
->
assertEquals
(
count
(
$payload
->
session
[
'data'
]),
0
);
}
public
function
test_regenerate_session_sets_new_session_id
()
{
$payload
=
new
Payload
(
array
(
'id'
=>
'something'
));
$payload
->
regenerate
();
$this
->
assertTrue
(
$payload
->
regenerated
);
$this
->
assertEquals
(
strlen
(
$payload
->
session
[
'id'
]),
40
);
}
public
function
test_age_method_sets_last_activity_time
()
{
$data
=
$this
->
getDummyData
();
unset
(
$data
[
'last_activity'
]);
$payload
=
new
Payload
(
$data
);
$payload
->
age
();
$this
->
assertTrue
(
isset
(
$payload
->
session
[
'last_activity'
]));
}
public
function
test_age_method_ages_all_flash_data
()
{
$payload
=
new
Payload
(
$this
->
getDummyData
());
$payload
->
age
();
$this
->
assertTrue
(
isset
(
$payload
->
session
[
'data'
][
':old:age'
]));
$this
->
assertFalse
(
isset
(
$payload
->
session
[
'data'
][
':old:gender'
]));
}
public
function
test_age_method_returns_session_array
()
{
$payload
=
new
Payload
(
$this
->
getDummyData
());
$age
=
$payload
->
age
();
$this
->
assertEquals
(
$age
[
'id'
],
'something'
);
}
// ---------------------------------------------------------------------
// Support Functions
// ---------------------------------------------------------------------
public
function
getDummyData
()
{
return
array
(
'id'
=>
'something'
,
'last_activity'
=>
time
(),
'data'
=>
array
(
'name'
=>
'Taylor'
,
':new:age'
=>
25
,
':old:gender'
=>
'male'
,
'state'
=>
'Oregon'
,
));
}
}
\ 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