@@ -14,6 +14,11 @@ class DaysActiveTest extends WP_UnitTestCase {
1414 * Test days active calculation with valid activation date.
1515 */
1616 public function test_days_active_with_valid_date () {
17+ // Skip this test if WordPress functions aren't available.
18+ if ( ! function_exists ( 'update_option ' ) || ! function_exists ( 'delete_option ' ) ) {
19+ $ this ->markTestSkipped ( 'WordPress option functions not available in test environment. ' );
20+ }
21+
1722 // Set a mock activation date 10 days ago.
1823 $ ten_days_ago = gmdate ( 'Y-m-d H:i:s ' , strtotime ( '-10 days ' ) );
1924 update_option ( 'edac_activation_date ' , $ ten_days_ago );
@@ -33,6 +38,11 @@ public function test_days_active_with_valid_date() {
3338 * Test days active calculation with recent activation date.
3439 */
3540 public function test_days_active_with_recent_date () {
41+ // Skip this test if WordPress functions aren't available.
42+ if ( ! function_exists ( 'update_option ' ) || ! function_exists ( 'delete_option ' ) ) {
43+ $ this ->markTestSkipped ( 'WordPress option functions not available in test environment. ' );
44+ }
45+
3646 // Set activation date to 1 hour ago.
3747 $ one_hour_ago = gmdate ( 'Y-m-d H:i:s ' , strtotime ( '-1 hour ' ) );
3848 update_option ( 'edac_activation_date ' , $ one_hour_ago );
@@ -51,6 +61,11 @@ public function test_days_active_with_recent_date() {
5161 * Test days active calculation with future date (edge case).
5262 */
5363 public function test_days_active_with_future_date () {
64+ // Skip this test if WordPress functions aren't available.
65+ if ( ! function_exists ( 'update_option ' ) || ! function_exists ( 'delete_option ' ) ) {
66+ $ this ->markTestSkipped ( 'WordPress option functions not available in test environment. ' );
67+ }
68+
5469 // Set activation date to 5 days in the future.
5570 $ five_days_future = gmdate ( 'Y-m-d H:i:s ' , strtotime ( '+5 days ' ) );
5671 update_option ( 'edac_activation_date ' , $ five_days_future );
@@ -70,6 +85,11 @@ public function test_days_active_with_future_date() {
7085 * Test days active calculation with no activation date set.
7186 */
7287 public function test_days_active_with_no_activation_date () {
88+ // Skip this test if WordPress functions aren't available.
89+ if ( ! function_exists ( 'delete_option ' ) ) {
90+ $ this ->markTestSkipped ( 'WordPress option functions not available in test environment. ' );
91+ }
92+
7393 // Ensure the option doesn't exist.
7494 delete_option ( 'edac_activation_date ' );
7595
@@ -84,6 +104,11 @@ public function test_days_active_with_no_activation_date() {
84104 * Test days active calculation with empty activation date.
85105 */
86106 public function test_days_active_with_empty_activation_date () {
107+ // Skip this test if WordPress functions aren't available.
108+ if ( ! function_exists ( 'update_option ' ) || ! function_exists ( 'delete_option ' ) ) {
109+ $ this ->markTestSkipped ( 'WordPress option functions not available in test environment. ' );
110+ }
111+
87112 // Set empty activation date.
88113 update_option ( 'edac_activation_date ' , '' );
89114
@@ -101,6 +126,11 @@ public function test_days_active_with_empty_activation_date() {
101126 * Test days active calculation with malformed date.
102127 */
103128 public function test_days_active_with_malformed_date () {
129+ // Skip this test if WordPress functions aren't available.
130+ if ( ! function_exists ( 'update_option ' ) || ! function_exists ( 'delete_option ' ) ) {
131+ $ this ->markTestSkipped ( 'WordPress option functions not available in test environment. ' );
132+ }
133+
104134 // Set malformed activation date.
105135 update_option ( 'edac_activation_date ' , 'not-a-date ' );
106136
@@ -117,6 +147,11 @@ public function test_days_active_with_malformed_date() {
117147 * Test days active calculation with very old activation date.
118148 */
119149 public function test_days_active_with_old_date () {
150+ // Skip this test if WordPress functions aren't available.
151+ if ( ! function_exists ( 'update_option ' ) || ! function_exists ( 'delete_option ' ) ) {
152+ $ this ->markTestSkipped ( 'WordPress option functions not available in test environment. ' );
153+ }
154+
120155 // Set activation date to 365 days ago.
121156 $ one_year_ago = gmdate ( 'Y-m-d H:i:s ' , strtotime ( '-365 days ' ) );
122157 update_option ( 'edac_activation_date ' , $ one_year_ago );
@@ -141,6 +176,11 @@ public function test_days_active_with_old_date() {
141176 * @param string $description Test description.
142177 */
143178 public function test_days_active_with_different_date_formats ( $ date_string , $ description ) {
179+ // Skip this test if WordPress functions aren't available.
180+ if ( ! function_exists ( 'update_option ' ) || ! function_exists ( 'delete_option ' ) ) {
181+ $ this ->markTestSkipped ( 'WordPress option functions not available in test environment. ' );
182+ }
183+
144184 update_option ( 'edac_activation_date ' , $ date_string );
145185
146186 $ result = edac_days_active ();
@@ -183,6 +223,11 @@ public function date_format_data() {
183223 * Test that the function handles timezone differences appropriately.
184224 */
185225 public function test_days_active_timezone_handling () {
226+ // Skip this test if WordPress functions aren't available.
227+ if ( ! function_exists ( 'update_option ' ) || ! function_exists ( 'delete_option ' ) ) {
228+ $ this ->markTestSkipped ( 'WordPress option functions not available in test environment. ' );
229+ }
230+
186231 // The function uses gmdate() which is UTC-based.
187232 // Set a specific time that's close to midnight in UTC.
188233 $ utc_yesterday_23_59 = gmdate ( 'Y-m-d H:i:s ' , strtotime ( 'yesterday 23:59:00 UTC ' ) );
0 commit comments