From 5a3878e72ed5c8bcb4ce09894c7a8297292d9552 Mon Sep 17 00:00:00 2001
From: Erick Hitter <git-contrib@ethitter.com>
Date: Mon, 11 Sep 2017 14:39:21 -0700
Subject: [PATCH] Add scheduling tests

---
 tests/tests/class-plugin-functions.php | 38 ++++++++++++++++++++++++--
 1 file changed, 36 insertions(+), 2 deletions(-)

diff --git a/tests/tests/class-plugin-functions.php b/tests/tests/class-plugin-functions.php
index 9d1b7b7..e26c00f 100644
--- a/tests/tests/class-plugin-functions.php
+++ b/tests/tests/class-plugin-functions.php
@@ -10,9 +10,29 @@ use Automattic\WP\WP_CLI_Cron_Control_Offload;
 use WP_UnitTestCase;
 
 /**
- * Sample test case.
+ * Core function tests
  */
-class SampleTest extends WP_UnitTestCase {
+class Plugin_Functions extends WP_UnitTestCase {
+	/**
+	 * Prepare test environment
+	 */
+	function setUp() {
+		parent::setUp();
+
+		// make sure the schedule is clear.
+		_set_cron_array( array() );
+	}
+
+	/**
+	 * Clean up after our tests
+	 */
+	function tearDown() {
+		// make sure the schedule is clear.
+		_set_cron_array( array() );
+
+		parent::tearDown();
+	}
+
 	/**
 	 * Test whitelisted commands
 	 */
@@ -42,4 +62,18 @@ class SampleTest extends WP_UnitTestCase {
 		$this->assertTrue( is_wp_error( WP_CLI_Cron_Control_Offload\validate_command( 'wp cli info' ) ) );
 		$this->assertTrue( is_wp_error( WP_CLI_Cron_Control_Offload\validate_command( 'cli info' ) ) );
 	}
+
+	/**
+	 * Test event scheduling
+	 */
+	function test_event_scheduling() {
+		// Should succeed, returning a timestamp.
+		$this->assertTrue( is_int( WP_CLI_Cron_Control_Offload\schedule_cli_command( 'wp cli info' ) ) );
+
+		// Should be blocked as a duplicate, thanks to Core's 10-minute lookahead.
+		$this->assertTrue( is_wp_error( WP_CLI_Cron_Control_Offload\schedule_cli_command( 'wp cli info' ) ) );
+
+		// Should also fail as normalization makes it a duplicate.
+		$this->assertTrue( is_wp_error( WP_CLI_Cron_Control_Offload\schedule_cli_command( 'cli info' ) ) );
+	}
 }
-- 
GitLab