-
Notifications
You must be signed in to change notification settings - Fork 12
/
TestCloneGroupWithoutPrefixCest.php
101 lines (76 loc) · 2.74 KB
/
TestCloneGroupWithoutPrefixCest.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
<?php
class TestCloneGroupWithoutPrefixCest {
public function _before( FunctionalTester $I, \Codeception\Scenario $scenario ) {
$acf_json = 'issue-172-b/acf-export-issue-172-b.json';
$I->importJson( $acf_json );
if ( ! $I->haveAcfProActive() ) {
$I->markTestSkipped( 'Skipping test. ACF Pro is required for clone fields' );
}
}
public function testAcfFieldGroupsShowInSchema( FunctionalTester $I ) {
$I->wantTo( 'Test imported field groups show in schema when querying the possible types of AcfFieldGroup' );
$I->haveHttpHeader( 'Content-Type', 'application/json' );
$query = '
query GetAcfFieldGroups {
__type(name:"AcfFieldGroup") {
name
possibleTypes {
name
}
}
}
';
$I->sendPost( '/graphql', json_encode([
'query' => $query
]));
$I->seeResponseCodeIs( 200 );
$I->seeResponseIsJson();
$response = $I->grabResponse();
$response = json_decode( $response, true );
$I->assertSame( 'AcfFieldGroup', $response['data']['__type']['name'] );
$I->assertNotEmpty( $response['data']['__type']['possibleTypes'] );
$possible_types = array_map( static function( $possible_type ) {
return $possible_type['name'];
}, $response['data']['__type']['possibleTypes'] );
$I->assertTrue( in_array( 'PostCategoryOptions', $possible_types, true ) );
$I->assertTrue( in_array( 'AuthorCustomFields', $possible_types, true ) );
$I->assertTrue( in_array( 'ContentGridOption', $possible_types, true ) );
$I->assertTrue( in_array( 'AcfPageOptions', $possible_types, true ) );
$I->assertTrue( in_array( 'AcfPageOptionsPageOptions', $possible_types, true ) );
$I->assertTrue( in_array( 'Schema', $possible_types, true ) );
}
public function testQueryPostWithPostSectionsAndAssertNoErrors( FunctionalTester $I ) {
$I->wantTo( 'Post Sections can be queried without errors' );
$I->haveHttpHeader( 'Content-Type', 'application/json' );
$query = '
query GetPostSections {
post(id:20754 idType:DATABASE_ID){
id
title
postSections {
postSections {
__typename
...on PostSectionsPostSectionsContentLayout {
dropcap
subLayout {
contentWidth
}
}
}
}
}
}
';
$I->sendPost( '/graphql', json_encode([
'query' => $query
]));
$I->seeResponseCodeIs( 200 );
$I->seeResponseIsJson();
$response = $I->grabResponse();
$response = json_decode( $response, true );
// The query should be valid and contain no errors
// We're not really testing for data resolution here, just that the
// query is valid and does not contain errors
$I->assertArrayNotHasKey( 'errors', $response, 'The response has no errors, meaning the query was valid, even if no data was returned');
}
}