-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathPostPreviewQueryTest.php
119 lines (103 loc) · 3.34 KB
/
PostPreviewQueryTest.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
// XXX: Can we autoload this somehow?
require_once __DIR__ . '/PolylangUnitTestCase.php';
class PostObjectQueryTest extends PolylangUnitTestCase
{
static function wpSetUpBeforeClass()
{
parent::wpSetUpBeforeClass();
self::set_default_language('en_US');
self::create_language('en_US');
self::create_language('fr_FR');
self::create_language('fi');
self::create_language('de_DE_formal');
self::create_language('es_ES');
}
public function setUp(): void
{
parent::setUp();
}
public function testCanHaveLanguageField()
{
$post_id = $this->factory()->post->create([
'post_title' => 'Original post',
'post_content' => '',
'post_type' => 'post',
'post_status' => 'publish',
]);
pll_set_post_language($post_id, 'fi');
$preview_id = $this->factory()->post->create([
'post_title' => 'Preview post',
'post_content' => 'Preview Content',
'post_type' => 'revision',
'post_status' => 'inherit',
'post_parent' => $post_id,
]);
pll_set_post_language($preview_id, 'en');
$query = "
query Preview {
post(id: \"$post_id\", idType: DATABASE_ID, asPreview: true) {
title
language {
code
}
}
}
";
wp_set_current_user(1);
$result = do_graphql_request($query);
$this->assertArrayNotHasKey('errors', $result, print_r($result, true));
$this->assertEquals($result['data']['post']['language']['code'], 'EN');
}
public function testCanFetchTranslatedVersions()
{
$fi_post_id = wp_insert_post([
'post_title' => 'Finnish post version',
'post_content' => '',
'post_type' => 'post',
'post_status' => 'publish',
]);
pll_set_post_language($fi_post_id, 'fi');
$en_post_id = wp_insert_post([
'post_title' => 'English post version',
'post_content' => '',
'post_type' => 'post',
'post_status' => 'publish',
]);
pll_set_post_language($en_post_id, 'en');
pll_save_post_translations([
'en' => $en_post_id,
'fi' => $fi_post_id,
]);
$preview_id = $this->factory()->post->create([
'post_title' => 'Preview post',
'post_content' => 'Preview Content',
'post_type' => 'revision',
'post_status' => 'inherit',
'post_parent' => $en_post_id,
]);
$query = "
query Preview {
post(id: \"$en_post_id\", idType: DATABASE_ID, asPreview: true) {
title
translations {
title
}
}
}
";
wp_set_current_user(1);
$data = do_graphql_request($query);
$this->assertArrayNotHasKey('errors', $data, print_r($data, true));
error_log(print_r($data, true));
$expected = [
'title' => 'Preview post',
'translations' => [
[
'title' => 'Finnish post version',
],
],
];
$this->assertEquals($expected, $data['data']['post']);
}
}