Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
syncEnrollments
Project
Project
Details
Activity
Releases
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
Yeray Santana Hualde
syncEnrollments
Commits
1b75302d
Commit
1b75302d
authored
Sep 16, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added session payload tests.
parent
917d4cb1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
156 additions
and
1 deletion
+156
-1
payload.php
laravel/session/payload.php
+1
-1
SessionPayloadTest.php
tests/Session/SessionPayloadTest.php
+155
-0
No files found.
laravel/session/payload.php
View file @
1b75302d
<?php
namespace
Laravel\Session
;
use
Closure
;
use
Laravel\Str
;
use
Laravel\Closure
;
class
Payload
{
...
...
tests/Session/SessionPayloadTest.php
0 → 100644
View file @
1b75302d
<?php
use
Laravel\Session\Payload
;
class
SessionPayloadTest
extends
PHPUnit_Framework_TestCase
{
public
function
testHasMethodIndicatesIfItemExistsInPayload
()
{
$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
testGetMethodReturnsItemFromPayload
()
{
$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
testGetMethodReturnsDefaultWhenItemDoesntExist
()
{
$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
testPutMethodAddsToPayload
()
{
$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
testFlashMethodPutsItemInFlashData
()
{
$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
testReflashKeepsAllSessionData
()
{
$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
testKeepMethodKeepsSpecificSessionData
()
{
$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
testFlushMethodShouldClearPayloadData
()
{
$payload
=
new
Payload
(
array
(
'data'
=>
array
(
'name'
=>
'Taylor'
)));
$payload
->
flush
();
$this
->
assertEquals
(
count
(
$payload
->
session
[
'data'
]),
0
);
}
public
function
testRegenerateMethodSetsNewSessionID
()
{
$payload
=
new
Payload
(
array
(
'id'
=>
'something'
));
$payload
->
regenerate
();
$this
->
assertEquals
(
strlen
(
$payload
->
session
[
'id'
]),
40
);
}
public
function
testAgeMethodSetsLastActivityTime
()
{
$data
=
$this
->
getDummyData
();
unset
(
$data
[
'last_activity'
]);
$payload
=
new
Payload
(
$data
);
$payload
->
age
();
$this
->
assertTrue
(
isset
(
$payload
->
session
[
'last_activity'
]));
}
public
function
testAgeMethodAgesAllFlashData
()
{
$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
testAgeMethodReturnsSessionArray
()
{
$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