Skip to content

Commit 709a256

Browse files
ORN-1197: allowed post types (#21)
* feat: 🎸 ORN-1197 allowed post types ✅ Closes: ORN-1197 * feat: 🎸 ORN-1197 fix linter errors ✅ Closes: ORN-1197
1 parent ffbaca4 commit 709a256

File tree

5 files changed

+91
-5
lines changed

5 files changed

+91
-5
lines changed

‎phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
>
1010
<testsuites>
1111
<testsuite name="unit-tests">
12-
<directory prefix="test-" suffix=".php">./tests/</directory>
12+
<directory suffix=".test.php">./tests/</directory>
1313
<!-- <exclude>./tests/test-sample.php</exclude> -->
1414
</testsuite>
1515
</testsuites>

‎tests/src/test-aggregate-query.php renamed to ‎tests/src/aggregate-query.test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
class TestAggregateQuery extends WP_UnitTestCase {
3+
class AggregateQueryTest extends WP_UnitTestCase {
44

55
protected static $category_animal_id = null;
66
protected static $category_feline_id = null;

‎tests/src/test-filter-query.php renamed to ‎tests/src/filter-query.test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
class TestFilterQuery extends WP_UnitTestCase {
3+
class FilterQueryTest extends WP_UnitTestCase {
44

55
protected static $category_animal_id = null;
66
protected static $category_feline_id = null;
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
3+
class Wp_GraphqlFilterQueryTest extends WP_UnitTestCase {
4+
5+
protected function setUp(): void {
6+
register_post_type(
7+
'zombie',
8+
array(
9+
'labels' => array(
10+
'name' => 'Zombies',
11+
),
12+
'public' => true,
13+
'capability_type' => 'post',
14+
'map_meta_cap' => false,
15+
/** WP GRAPHQL */
16+
'show_in_graphql' => true,
17+
'hierarchical' => true,
18+
'graphql_single_name' => 'zombie',
19+
'graphql_plural_name' => 'zombies',
20+
)
21+
);
22+
23+
register_post_type(
24+
'vampire',
25+
array(
26+
'labels' => array(
27+
'name' => 'Vampires',
28+
),
29+
'public' => true,
30+
'capability_type' => 'post',
31+
'map_meta_cap' => false,
32+
/** WP GRAPHQL */
33+
'show_in_graphql' => true,
34+
'hierarchical' => true,
35+
'graphql_single_name' => 'vampire',
36+
'graphql_plural_name' => 'vampires',
37+
)
38+
);
39+
40+
register_post_type(
41+
'rabbit',
42+
array(
43+
'labels' => array(
44+
'name' => 'Rabbits',
45+
),
46+
'public' => true,
47+
'capability_type' => 'post',
48+
'map_meta_cap' => false,
49+
/** WP GRAPHQL */
50+
'show_in_graphql' => false,
51+
'hierarchical' => true,
52+
'graphql_single_name' => 'rabbit',
53+
'graphql_plural_name' => 'rabbits',
54+
)
55+
);
56+
}
57+
58+
public function test_filter_query_get_supported_post_types() {
59+
$post_types = filter_query_get_supported_post_types();
60+
$expected_types = [
61+
'post' => [
62+
'name' => 'post',
63+
'capitalize_name' => 'Post',
64+
'plural_name' => 'posts',
65+
],
66+
'page' => [
67+
'name' => 'page',
68+
'capitalize_name' => 'Page',
69+
'plural_name' => 'pages',
70+
],
71+
'zombie' => [
72+
'name' => 'zombie',
73+
'capitalize_name' => 'Zombie',
74+
'plural_name' => 'zombies',
75+
],
76+
'vampire' => [
77+
'name' => 'vampire',
78+
'capitalize_name' => 'Vampire',
79+
'plural_name' => 'vampires',
80+
],
81+
];
82+
$this->assertEquals( $expected_types, $post_types );
83+
}
84+
85+
}

‎wp-graphql-filter-query.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ function filter_query_get_supported_post_types(): array {
3232

3333
$cpt_type_names = get_post_types(
3434
[
35-
'public' => true,
36-
'_builtin' => false,
35+
'public' => true,
36+
'_builtin' => false,
37+
'show_in_graphql' => true,
3738
],
3839
'names'
3940
);

0 commit comments

Comments
 (0)