Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
WP Plugins
Cron-Control
Commits
8ed0c38e
Commit
8ed0c38e
authored
Oct 03, 2017
by
Erick Hitter
Browse files
Tests for event addition
Removal of existing Internal Events is covered by the existing tests.
parent
746cc6b7
Changes
2
Hide whitespace changes
Inline
Side-by-side
tests/bootstrap.php
View file @
8ed0c38e
...
...
@@ -19,6 +19,14 @@ require_once $_tests_dir . '/includes/functions.php';
function
_manually_load_plugin
()
{
define
(
'WP_CRON_CONTROL_SECRET'
,
'testtesttest'
);
define
(
'CRON_CONTROL_ADDITIONAL_INTERNAL_EVENTS'
,
array
(
array
(
'schedule'
=>
'hourly'
,
'action'
=>
'cron_control_additional_internal_event'
,
'callback'
=>
'__return_true'
,
),
)
);
require
dirname
(
dirname
(
__FILE__
)
)
.
'/cron-control.php'
;
// Plugin loads after `wp_install()` is called, so we compensate.
...
...
tests/tests/class-internal-events-tests.php
View file @
8ed0c38e
...
...
@@ -6,11 +6,14 @@
*/
namespace
Automattic\WP\Cron_Control\Tests
;
use
Automattic\WP\Cron_Control
;
use
Automattic\WP\Cron_Control\Internal_Events
;
use
WP_UnitTestCase
;
/**
* Internal Events tests
*/
class
Internal_Events_Tests
extends
\
WP_UnitTestCase
{
class
Internal_Events_Tests
extends
WP_UnitTestCase
{
/**
* Prepare test environment
*/
...
...
@@ -19,6 +22,8 @@ class Internal_Events_Tests extends \WP_UnitTestCase {
// make sure the schedule is clear.
_set_cron_array
(
array
()
);
Internal_Events
::
instance
()
->
schedule_internal_events
();
}
/**
...
...
@@ -34,17 +39,36 @@ class Internal_Events_Tests extends \WP_UnitTestCase {
/**
* Internal events should be scheduled
*/
function
test_events
()
{
\
Automattic\WP\Cron_Control\Internal_Events
::
instance
()
->
schedule_internal_events
();
function
test_events_scheduled
()
{
$events
=
Cron_Control\collapse_events_array
(
get_option
(
'cron'
)
);
$expected
=
4
;
// Number of events created by the Internal_Events::prepare_internal_events() method, which is private.
$expected
+=
count
(
CRON_CONTROL_ADDITIONAL_INTERNAL_EVENTS
);
$events
=
\
Automattic\WP\Cron_Control\collapse_events_array
(
get_option
(
'cron'
)
);
$this
->
assertEquals
(
count
(
$events
),
$expected
,
'Incorrect number of Internal Events registered'
);
}
// Check that the plugin scheduled the expected number of events.
$this
->
assertEquals
(
count
(
$events
),
4
);
/**
* Test that all scheduled events are from the Internal Events class
*/
function
test_events_are_internal
()
{
$events
=
Cron_Control\collapse_events_array
(
get_option
(
'cron'
)
);
// Confirm that the scheduled jobs came from the Internal Events class.
foreach
(
$events
as
$event
)
{
$this
->
assertTrue
(
\
Automattic\WP\Cron_Control\is_internal_event
(
$event
[
'action'
]
)
);
$this
->
assertTrue
(
Cron_Control\is_internal_event
(
$event
[
'action'
]
),
sprintf
(
'Action `%s` is not an Internal Event'
,
$event
[
'action'
]
)
);
}
}
/**
* Test that additional Internal Events can be added
*/
function
test_add_events
()
{
$additional
=
CRON_CONTROL_ADDITIONAL_INTERNAL_EVENTS
;
foreach
(
$additional
as
$added
)
{
$next
=
wp_next_scheduled
(
$added
[
'action'
],
array
()
);
$this
->
assertInternalType
(
'int'
,
$next
,
sprintf
(
'Additional Internal Event `%s` not scheduled'
,
$added
[
'action'
]
)
);
}
}
}
Write
Preview
Supports
Markdown
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