Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
Redis User Session Storage
Manage
Activity
Members
Labels
Plan
Issues
1
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
WP Plugins
Redis User Session Storage
Commits
50fb8acf
Commit
50fb8acf
authored
2 years ago
by
Erick Hitter
Browse files
Options
Downloads
Patches
Plain Diff
Test coverage
parent
0ccbeefc
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!6
Add tests
Pipeline
#5048
failed with stages
in 3 minutes and 10 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
phpcs.xml
+1
-1
1 addition, 1 deletion
phpcs.xml
tests/bootstrap.php
+5
-4
5 additions, 4 deletions
tests/bootstrap.php
tests/inc/class-test-plugin.php
+174
-13
174 additions, 13 deletions
tests/inc/class-test-plugin.php
with
180 additions
and
18 deletions
phpcs.xml
+
1
−
1
View file @
50fb8acf
...
...
@@ -32,7 +32,7 @@
<rule
ref=
"WordPress.NamingConventions.PrefixAllGlobals"
>
<properties>
<!-- Value: replace the function, class, and variable prefixes used. Separate multiple prefixes with a comma. -->
<property
name=
"prefixes"
type=
"array"
value=
"redis_user_session_storage,wp_redis_user_session
_storage
"
/>
<property
name=
"prefixes"
type=
"array"
value=
"redis_user_session_storage,wp_redis_user_session"
/>
</properties>
</rule>
<rule
ref=
"WordPress.WP.I18n"
>
...
...
This diff is collapsed.
Click to expand it.
tests/bootstrap.php
+
5
−
4
View file @
50fb8acf
...
...
@@ -5,10 +5,6 @@
* @package WP_Revisions_Control
*/
if
(
!
defined
(
'WP_REDIS_USER_SESSION_HOST'
)
)
{
define
(
'WP_REDIS_USER_SESSION_HOST'
,
'redis'
);
}
$redis_user_session_storage
=
getenv
(
'WP_TESTS_DIR'
);
if
(
!
$redis_user_session_storage
)
{
...
...
@@ -33,3 +29,8 @@ tests_add_filter( 'muplugins_loaded', 'redis_user_session_storage_tests_manually
// Start up the WP testing environment.
require
$redis_user_session_storage
.
'/includes/bootstrap.php'
;
// Set Redis host for CI.
if
(
!
defined
(
'WP_REDIS_USER_SESSION_HOST'
)
)
{
define
(
'WP_REDIS_USER_SESSION_HOST'
,
'redis'
);
}
This diff is collapsed.
Click to expand it.
tests/inc/class-test-plugin.php
+
174
−
13
View file @
50fb8acf
...
...
@@ -167,20 +167,71 @@ class Test_Plugin extends WP_UnitTestCase {
* Test `update_session()` method.
*
* @covers ::update_session()
* @covers ::update_sessions()
* @return void
*/
public
function
test_update_session
()
{
$
this
->
markTestIncomple
te
();
}
$
user_id
=
$this
->
factory
->
user
->
crea
te
();
$plugin
=
new
Plugin
(
$user_id
);
/**
* Test `update_sessions()` method.
*
* @covers ::update_sessions()
* @return void
*/
public
function
test_update_sessions
()
{
$this
->
markTestIncomplete
();
$plugin
->
create
(
time
()
+
60
);
$sessions
=
$this
->
_invoke_method
(
$user_id
,
'get_sessions'
);
$verifier
=
array_keys
(
$sessions
)[
0
];
$this
->
assertNotEmpty
(
$sessions
,
'Failed to assert that session was created.'
);
$this
->
_invoke_method
(
$user_id
,
'update_session'
,
array
(
$verifier
,
)
);
$this
->
assertEmpty
(
$this
->
_invoke_method
(
$user_id
,
'get_session'
,
array
(
$verifier
,
)
),
'Failed to assert that session is not destroyed when no session data is provided.'
);
$plugin
->
create
(
time
()
+
60
);
$sessions
=
$this
->
_invoke_method
(
$user_id
,
'get_sessions'
);
$verifier
=
array_keys
(
$sessions
)[
0
];
$session_data
=
array
(
'expiration'
=>
time
()
+
60
,
'foo'
=>
'bar'
,
);
$this
->
_invoke_method
(
$user_id
,
'update_session'
,
array
(
$verifier
,
$session_data
,
)
);
$this
->
assertEquals
(
$session_data
,
$this
->
_invoke_method
(
$user_id
,
'get_session'
,
array
(
$verifier
,
)
),
'Failed to assert that session is updated when session data is provided.'
);
}
/**
...
...
@@ -190,7 +241,39 @@ class Test_Plugin extends WP_UnitTestCase {
* @return void
*/
public
function
test_destroy_other_sessions
()
{
$this
->
markTestIncomplete
();
$user_id
=
$this
->
factory
->
user
->
create
();
$plugin
=
new
Plugin
(
$user_id
);
$plugin
->
create
(
time
()
+
60
);
$plugin
->
create
(
time
()
+
120
);
$plugin
->
create
(
time
()
+
180
);
$sessions
=
$this
->
_invoke_method
(
$user_id
,
'get_sessions'
);
$this
->
assertCount
(
3
,
$sessions
,
'Failed to assert that multiple sessions were created.'
);
$verifier
=
array_keys
(
$sessions
)[
0
];
$this
->
_invoke_method
(
$user_id
,
'destroy_other_sessions'
,
array
(
$verifier
,
)
);
$this
->
assertCount
(
1
,
$this
->
_invoke_method
(
$user_id
,
'get_sessions'
),
'Failed to assert that other sessions are destroyed.'
);
}
/**
...
...
@@ -200,7 +283,36 @@ class Test_Plugin extends WP_UnitTestCase {
* @return void
*/
public
function
test_destroy_all_sessions
()
{
$this
->
markTestIncomplete
();
$user_id
=
$this
->
factory
->
user
->
create
();
$plugin
=
new
Plugin
(
$user_id
);
$plugin
->
create
(
time
()
+
60
);
$plugin
->
create
(
time
()
+
120
);
$plugin
->
create
(
time
()
+
180
);
$sessions
=
$this
->
_invoke_method
(
$user_id
,
'get_sessions'
);
$this
->
assertCount
(
3
,
$this
->
_invoke_method
(
$user_id
,
'get_sessions'
),
'Failed to assert that multiple sessions were created.'
);
$this
->
_invoke_method
(
$user_id
,
'destroy_all_sessions'
);
$this
->
assertEmpty
(
$this
->
_invoke_method
(
$user_id
,
'get_sessions'
),
'Failed to assert that all sessions were destroyed.'
);
}
/**
...
...
@@ -211,7 +323,56 @@ class Test_Plugin extends WP_UnitTestCase {
* @return void
*/
public
function
test_drop_sessions
()
{
$this
->
markTestIncomplete
();
$user_1
=
$this
->
factory
->
user
->
create
();
$plugin_user_1
=
new
Plugin
(
$user_1
);
$user_2
=
$this
->
factory
->
user
->
create
();
$plugin_user_2
=
new
Plugin
(
$user_2
);
$plugin_user_1
->
create
(
time
()
+
60
);
$plugin_user_1
->
create
(
time
()
+
120
);
$plugin_user_1
->
create
(
time
()
+
180
);
$plugin_user_2
->
create
(
time
()
+
60
);
$plugin_user_2
->
create
(
time
()
+
120
);
$plugin_user_2
->
create
(
time
()
+
180
);
$this
->
assertCount
(
3
,
$this
->
_invoke_method
(
$user_1
,
'get_sessions'
),
'Failed to assert that multiple sessions were created for user 1.'
);
$this
->
assertCount
(
3
,
$this
->
_invoke_method
(
$user_2
,
'get_sessions'
),
'Failed to assert that multiple sessions were created for user 2.'
);
$this
->
_invoke_method
(
$user_1
,
'flush_redis_db'
);
$this
->
assertEmpty
(
$this
->
_invoke_method
(
$user_1
,
'get_sessions'
),
'Failed to assert that sessions were destroyed for user 1.'
);
$this
->
assertEmpty
(
$this
->
_invoke_method
(
$user_2
,
'get_sessions'
),
'Failed to assert that sessions were destroyed for user 2.'
);
}
/**
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment