Skip to content

Commit cd7f5cb

Browse files
committed
Add unit tests for wp_is_valid_last_changed function
Introduce PHPUnit tests to validate the behavior of the wp_is_valid_last_changed function. Tests cover various scenarios, including valid usage, missing or mismatched timestamps, and invalid input types. These additions ensure robustness and prevent potential regressions.
1 parent 2b1639d commit cd7f5cb

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
/**
4+
* @group functions
5+
*
6+
* @covers ::wp_is_valid_last_changed
7+
*/
8+
class Tests_Functions_wpIsValidLastChanged extends WP_UnitTestCase {
9+
10+
public function test_wp_is_valid_last_changed() {
11+
$last_changed = microtime();
12+
$cache_value = array(
13+
'last_changed' => $last_changed,
14+
'value' => 'test_value',
15+
);
16+
$this->assertTrue( wp_is_valid_last_changed( $cache_value, $last_changed ) );
17+
}
18+
19+
public function test_wp_is_valid_last_changed_no_last_chaned() {
20+
$last_changed = microtime();
21+
$cache_value = array(
22+
'value' => 'test_value',
23+
);
24+
$this->assertFalse( wp_is_valid_last_changed( $cache_value, $last_changed ) );
25+
}
26+
27+
public function test_wp_is_valid_last_changed_different_last_chaned() {
28+
$last_changed = microtime();
29+
$cache_value = array(
30+
'last_changed' => 444444,
31+
'value' => 'test_value',
32+
);
33+
$this->assertFalse( wp_is_valid_last_changed( $cache_value, $last_changed ) );
34+
}
35+
36+
/**
37+
* @dataProvider data_invalid_values
38+
*/
39+
public function test_wp_is_valid_last_changed_invalid_values( $value ) {
40+
$this->assertFalse( wp_is_valid_last_changed( $value, '' ) );
41+
}
42+
43+
public function data_invalid_values() {
44+
return array(
45+
'empty' => array( '' ),
46+
'null' => array( null ),
47+
'number 0' => array( 0 ),
48+
'number 1' => array( 1 ),
49+
'false' => array( false ),
50+
'true' => array( true ),
51+
'array' => array( array() ),
52+
'object' => array( new stdClass() ),
53+
);
54+
}
55+
}

0 commit comments

Comments
 (0)