Skip to content

Commit 678d1dc

Browse files
oandregalspacedmonkey
authored andcommitted
View Config: set summary fields.
Props oandregal, ntsekouras, jorgefilipecosta, gigitux. Part of #65981. git-svn-id: https://develop.svn.wordpress.org/trunk@63434 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 246a55b commit 678d1dc

2 files changed

Lines changed: 73 additions & 0 deletions

File tree

‎src/wp-includes/view-config.php‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ function _wp_get_default_posttype_form() {
7676
array(
7777
'id' => 'status',
7878
'label' => __( 'Status' ),
79+
'layout' => array(
80+
'type' => 'panel',
81+
'summary' => 'status',
82+
),
7983
'children' => array(
8084
array(
8185
'id' => 'status',
@@ -96,6 +100,10 @@ function _wp_get_default_posttype_form() {
96100
array(
97101
'id' => 'discussion',
98102
'label' => __( 'Discussion' ),
103+
'layout' => array(
104+
'type' => 'panel',
105+
'summary' => 'discussion',
106+
),
99107
'children' => array(
100108
array(
101109
'id' => 'comment_status',

‎tests/phpunit/tests/view-config.php‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,71 @@ public function tear_down() {
7474
parent::tear_down();
7575
}
7676

77+
/**
78+
* Returns the form field with the given id from a view configuration.
79+
*
80+
* @param array $config The view configuration.
81+
* @param string $id The form field id.
82+
* @return array|null The form field, or null when absent.
83+
*/
84+
private function get_form_field( $config, $id ) {
85+
foreach ( $config['form']['fields'] as $field ) {
86+
if ( is_array( $field ) && isset( $field['id'] ) && $id === $field['id'] ) {
87+
return $field;
88+
}
89+
}
90+
return null;
91+
}
92+
93+
/**
94+
* The `status` and `discussion` groups of the default post type form declare
95+
* their panel summary explicitly, for built-in and custom post types alike.
96+
*
97+
* @ticket 65981
98+
*
99+
* @dataProvider data_default_form_post_types
100+
*
101+
* @param string $post_type The post type.
102+
*/
103+
public function test_default_form_groups_declare_summary( $post_type ) {
104+
if ( ! post_type_exists( $post_type ) ) {
105+
register_post_type( $post_type );
106+
}
107+
108+
$config = wp_get_entity_view_config( 'postType', $post_type );
109+
110+
foreach ( array( 'status', 'discussion' ) as $group ) {
111+
$field = $this->get_form_field( $config, $group );
112+
$this->assertNotNull( $field, "The `{$group}` group is present." );
113+
$this->assertNotEmpty( $field['children'], "The `{$group}` group keeps its children." );
114+
$this->assertSame(
115+
array(
116+
'type' => 'panel',
117+
'summary' => $group,
118+
),
119+
$field['layout'],
120+
"The `{$group}` group summary is explicit."
121+
);
122+
}
123+
124+
if ( 'page' !== $post_type && 'post' !== $post_type ) {
125+
unregister_post_type( $post_type );
126+
}
127+
}
128+
129+
/**
130+
* Data provider.
131+
*
132+
* @return array[]
133+
*/
134+
public function data_default_form_post_types() {
135+
return array(
136+
'page' => array( 'page' ),
137+
'post' => array( 'post' ),
138+
'custom post type' => array( 'summaries_cpt' ),
139+
);
140+
}
141+
77142
/**
78143
* The default configuration exposes the documented shape for an unknown entity.
79144
*/

0 commit comments

Comments
 (0)