Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
WP Revisions Control
Manage
Activity
Members
Labels
Plan
Issues
3
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
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
WP Revisions Control
Commits
92163b49
Commit
92163b49
authored
5 years ago
by
Erick Hitter
Browse files
Options
Downloads
Patches
Plain Diff
Test for `purge_excess` method
parent
54c5119c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!4
Add bulk actions
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/test-hooks.php
+0
-45
0 additions, 45 deletions
tests/test-hooks.php
tests/test-purges.php
+118
-0
118 additions, 0 deletions
tests/test-purges.php
with
118 additions
and
45 deletions
tests/test-hooks.php
+
0
−
45
View file @
92163b49
...
...
@@ -62,49 +62,4 @@ class TestHooks extends WP_UnitTestCase {
wp_revisions_to_keep
(
get_post
(
$post_id_unlimited
)
)
);
}
/**
* Test revision purging.
*/
public
function
test_purge_all
()
{
$post_id
=
$this
->
factory
->
post
->
create
();
$iterations
=
10
;
for
(
$i
=
0
;
$i
<
$iterations
;
$i
++
)
{
wp_update_post
(
array
(
'ID'
=>
$post_id
,
'post_content'
=>
wp_rand
(),
)
);
}
$revisions_to_purge
=
count
(
wp_get_post_revisions
(
$post_id
)
);
$this
->
assertEquals
(
$iterations
,
$revisions_to_purge
,
'Failed to assert that there are revisions to purge.'
);
$purge
=
WP_Revisions_Control
::
get_instance
()
->
do_purge_all
(
$post_id
);
$revisions_remaining
=
count
(
wp_get_post_revisions
(
$post_id
)
);
$this
->
assertEquals
(
0
,
$revisions_remaining
,
'Failed to assert that all revisions were purged.'
);
$this
->
assertEquals
(
10
,
$purge
[
'count'
],
'Failed to assert that response includes expected count of purged revisions.'
);
$this
->
assertEquals
(
'Removed 10 revisions associated with this post.'
,
$purge
[
'success'
],
'Failed to assert that response includes expected success message.'
);
}
}
This diff is collapsed.
Click to expand it.
tests/test-purges.php
0 → 100755
+
118
−
0
View file @
92163b49
<?php
/**
* Test purge methods.
*
* @package WP_Revisions_Control
*/
/**
* Class TestPurges.
*/
class
TestPurges
extends
WP_UnitTestCase
{
/**
* Plugin slug used in many settings etc.
*
* @var string
*/
protected
static
$settings_section
=
'wp_revisions_control'
;
/**
* Plugin's limit meta key.
*
* @var string
*/
protected
static
$meta_key
=
'_wp_rev_ctl_limit'
;
/**
* Test revision purging.
*/
public
function
test_purge_all
()
{
$post_id
=
$this
->
factory
->
post
->
create
();
$iterations
=
10
;
for
(
$i
=
0
;
$i
<
$iterations
;
$i
++
)
{
wp_update_post
(
array
(
'ID'
=>
$post_id
,
'post_content'
=>
wp_rand
(),
)
);
}
$revisions_to_purge
=
count
(
wp_get_post_revisions
(
$post_id
)
);
$this
->
assertEquals
(
$iterations
,
$revisions_to_purge
,
'Failed to assert that there are revisions to purge.'
);
$purge
=
WP_Revisions_Control
::
get_instance
()
->
do_purge_all
(
$post_id
);
$revisions_remaining
=
count
(
wp_get_post_revisions
(
$post_id
)
);
$this
->
assertEquals
(
0
,
$revisions_remaining
,
'Failed to assert that all revisions were purged.'
);
$this
->
assertEquals
(
10
,
$purge
[
'count'
],
'Failed to assert that response includes expected count of purged revisions.'
);
$this
->
assertEquals
(
'Removed 10 revisions associated with this post.'
,
$purge
[
'success'
],
'Failed to assert that response includes expected success message.'
);
}
/**
* Test revision purging.
*/
public
function
test_purge_excess
()
{
$post_id
=
$this
->
factory
->
post
->
create
();
$iterations
=
10
;
$limit
=
4
;
for
(
$i
=
0
;
$i
<
$iterations
;
$i
++
)
{
wp_update_post
(
array
(
'ID'
=>
$post_id
,
'post_content'
=>
wp_rand
(),
)
);
}
$revisions_to_purge
=
count
(
wp_get_post_revisions
(
$post_id
)
);
$this
->
assertEquals
(
$iterations
,
$revisions_to_purge
,
'Failed to assert that there are revisions to purge.'
);
update_post_meta
(
$post_id
,
static
::
$meta_key
,
$limit
);
$this
->
assertEquals
(
$limit
,
wp_revisions_to_keep
(
get_post
(
$post_id
)
),
'Failed to assert that post is limited to a given number of revisions.'
);
$purge
=
WP_Revisions_Control
::
get_instance
()
->
do_purge_excess
(
$post_id
);
$revisions_remaining
=
count
(
wp_get_post_revisions
(
$post_id
)
);
$this
->
assertEquals
(
4
,
$revisions_remaining
,
'Failed to assert that specified number of revisions were retained.'
);
$this
->
assertEquals
(
6
,
$purge
[
'count'
],
'Failed to assert that response includes expected count of purged revisions.'
);
}
}
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