forked from timber/timber
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-timber-post-convert.php
73 lines (66 loc) · 2.26 KB
/
test-timber-post-convert.php
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
/**
* @group called-post-constructor
*/
class TestTimberPostConvert extends Timber_UnitTestCase
{
public function testConvertWP_Post()
{
$post_id = $this->factory->post->create();
$post = Timber::get_post($post_id);
$post_id = $this->factory->post->create([
'post_title' => 'Maybe Child Post',
]);
$posts = get_posts([
'post__in' => [$post_id],
]);
$converted = $post->convert($posts[0]);
$this->assertEquals($post_id, $converted->id);
$this->assertEquals('Timber\Post', get_class($converted));
}
public function testConvertSingleItemArray()
{
$post_id = $this->factory->post->create();
$post = Timber::get_post($post_id);
$post_id = $this->factory->post->create([
'post_title' => 'Maybe Child Post',
]);
$posts = get_posts([
'post__in' => [$post_id],
]);
$converted = $post->convert($posts);
$this->assertEquals($post_id, $converted[0]->id);
$this->assertEquals('Timber\Post', get_class($converted[0]));
}
public function testConvertArray()
{
$post_ids = $this->factory->post->create_many(8, [
'post_title' => 'Sample Post ' . rand(1, 999),
]);
$post_id = $this->factory->post->create();
$post = Timber::get_post($post_id);
$posts = get_posts([
'post__in' => $post_ids,
'orderby' => 'post__in',
]);
$converted = $post->convert($posts);
$this->assertEquals($post_ids[2], $converted[2]->id);
$this->assertEquals('Timber\Post', get_class($converted[3]));
}
public function testNestedArray()
{
$post_ids = $this->factory->post->create_many(8, [
'post_title' => 'Sample Post ' . rand(1, 999),
]);
$post_id = $this->factory->post->create();
$post = Timber::get_post($post_id);
$posts = get_posts([
'post__in' => $post_ids,
'orderby' => 'post__in',
]);
$arr = [$post, $posts];
$converted = $post->convert($arr);
$this->assertEquals($post_ids[2], $converted[1][2]->id);
$this->assertEquals('Timber\Post', get_class($converted[1][3]));
}
}