forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiterators.php
More file actions
53 lines (44 loc) · 1.66 KB
/
iterators.php
File metadata and controls
53 lines (44 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
/**
* @ticket 22435
*/
class Test_WP_Post_IDs_Iterator extends WP_UnitTestCase {
function setUp() {
if ( ! class_exists( 'WP_Post_IDs_Iterator' ) ) {
$this->markTestSkipped( "WP_Post_IDs_Iterator class doesn't exist" );
}
parent::setUp();
}
function test_create() {
new WP_Post_IDs_Iterator( array( 1, 2, 3 ) );
}
function test_no_posts() {
$this->assertIteratorReturnsSamePostIDs( array() );
}
function test_less_ids_than_limit() {
$post_id_0 = $this->factory->post->create();
$post_id_1 = $this->factory->post->create();
$this->assertIteratorReturnsSamePostIDs( array( $post_id_0, $post_id_1 ), 10 );
}
function test_ids_exactly_as_limit() {
$post_id_0 = $this->factory->post->create();
$post_id_1 = $this->factory->post->create();
$this->assertIteratorReturnsSamePostIDs( array( $post_id_0, $post_id_1 ), 2 );
}
function test_more_ids_than_limit() {
$post_id_0 = $this->factory->post->create();
$post_id_1 = $this->factory->post->create();
$post_id_2 = $this->factory->post->create();
$this->assertIteratorReturnsSamePostIDs( array( $post_id_0, $post_id_1, $post_id_2 ), 2 );
}
function test_ids_exactly_twice_more_than_limit() {
$post_id_0 = $this->factory->post->create();
$post_id_1 = $this->factory->post->create();
$post_id_2 = $this->factory->post->create();
$post_id_3 = $this->factory->post->create();
$this->assertIteratorReturnsSamePostIDs( array( $post_id_0, $post_id_1, $post_id_2, $post_id_3 ), 2 );
}
private function assertIteratorReturnsSamePostIDs( $post_ids, $limit = 2 ) {
$this->assertEquals( $post_ids, wp_list_pluck( iterator_to_array( new WP_Post_IDs_Iterator( $post_ids, $limit ) ), 'ID' ) );
}
}