Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update tests
  • Loading branch information
ntsekouras authored and hellofromtonya committed Sep 20, 2022
commit 06c008215af1ca003e1d2ae22c168b2413771f22
Original file line number Diff line number Diff line change
Expand Up @@ -574,15 +574,13 @@ protected function prepare_item_for_database( $request ) {
$changes->post_excerpt = $template->description;
}

if ( 'wp_template' === $this->post_type ) {
if ( isset( $request['is_wp_suggestion'] ) ) {
$changes->meta_input = wp_parse_args(
array(
'is_wp_suggestion' => $request['is_wp_suggestion'],
),
$changes->meta_input = array()
);
}
if ( 'wp_template' === $this->post_type && isset( $request['is_wp_suggestion'] ) ) {
$changes->meta_input = wp_parse_args(
array(
'is_wp_suggestion' => $request['is_wp_suggestion'],
),
$changes->meta_input = array()
);
}

if ( 'wp_template_part' === $this->post_type ) {
Expand Down
81 changes: 46 additions & 35 deletions tests/phpunit/tests/block-template-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,152 +348,163 @@ function test_wp_generate_block_templates_export_file() {
*/
public function test_get_template_hierarchy() {
$hierarchy = get_template_hierarchy( 'front-page' );
$this->assertEquals( array( 'front-page', 'home', 'index' ), $hierarchy );
$this->assertSame( array( 'front-page', 'home', 'index' ), $hierarchy, 'Incorrect hierarchy for `front-page`.' );
// Custom templates.
$hierarchy = get_template_hierarchy( 'whatever-slug', true );
$this->assertEquals( array( 'page', 'singular', 'index' ), $hierarchy );
$this->assertSame( array( 'page', 'singular', 'index' ), $hierarchy, 'Incorrect hierarchy for custom template.' );
// Single slug templates(ex. page, tag, author, etc..
$hierarchy = get_template_hierarchy( 'page' );
$this->assertEquals( array( 'page', 'singular', 'index' ), $hierarchy );
$this->assertSame( array( 'page', 'singular', 'index' ), $hierarchy, 'Incorrect hierarchy for `page`.' );
$hierarchy = get_template_hierarchy( 'tag' );
$this->assertEquals( array( 'tag', 'archive', 'index' ), $hierarchy );
$this->assertSame( array( 'tag', 'archive', 'index' ), $hierarchy, 'Incorrect hierarchy for `tag`.' );
$hierarchy = get_template_hierarchy( 'author' );
$this->assertEquals( array( 'author', 'archive', 'index' ), $hierarchy );
$this->assertSame( array( 'author', 'archive', 'index' ), $hierarchy, 'Incorrect hierarchy for `author`.' );
$hierarchy = get_template_hierarchy( 'date' );
$this->assertEquals( array( 'date', 'archive', 'index' ), $hierarchy );
$this->assertSame( array( 'date', 'archive', 'index' ), $hierarchy, 'Incorrect hierarchy for `date`.' );
$hierarchy = get_template_hierarchy( 'taxonomy' );
$this->assertEquals( array( 'taxonomy', 'archive', 'index' ), $hierarchy );
$this->assertSame( array( 'taxonomy', 'archive', 'index' ), $hierarchy, 'Incorrect hierarchy for `taxonomy`.' );
$hierarchy = get_template_hierarchy( 'attachment' );
$this->assertEquals(
$this->assertSame(
array(
'attachment',
'single',
'singular',
'index',
),
$hierarchy
$hierarchy,
'Incorrect hierarchy for `attachment`.'
);
$hierarchy = get_template_hierarchy( 'singular' );
$this->assertEquals( array( 'singular', 'index' ), $hierarchy );
$this->assertSame( array( 'singular', 'index' ), $hierarchy, 'Incorrect hierarchy for `singular`.' );
$hierarchy = get_template_hierarchy( 'single' );
$this->assertEquals( array( 'single', 'singular', 'index' ), $hierarchy );
$this->assertSame( array( 'single', 'singular', 'index' ), $hierarchy, 'Incorrect hierarchy for `single`.' );
$hierarchy = get_template_hierarchy( 'archive' );
$this->assertEquals( array( 'archive', 'index' ), $hierarchy );
$this->assertSame( array( 'archive', 'index' ), $hierarchy, 'Incorrect hierarchy for `archive`.' );
$hierarchy = get_template_hierarchy( 'index' );
$this->assertEquals( array( 'index' ), $hierarchy );
$this->assertSame( array( 'index' ), $hierarchy, 'Incorrect hierarchy for `index`.' );

// Taxonomies.
$hierarchy = get_template_hierarchy( 'taxonomy-books', false, 'taxonomy-books' );
$this->assertEquals( array( 'taxonomy-books', 'taxonomy', 'archive', 'index' ), $hierarchy );
$this->assertSame( array( 'taxonomy-books', 'taxonomy', 'archive', 'index' ), $hierarchy, 'Incorrect hierarchy for specific taxonomies.' );
// Single word category.
$hierarchy = get_template_hierarchy( 'category-fruits', false, 'category' );
$this->assertEquals(
$this->assertSame(
array(
'category-fruits',
'category',
'archive',
'index',
),
$hierarchy
$hierarchy,
'Incorrect hierarchy for single word categories.'
);
// Multi word category.
$hierarchy = get_template_hierarchy( 'category-fruits-yellow', false, 'category' );
$this->assertEquals(
$this->assertSame(
array(
'category-fruits-yellow',
'category',
'archive',
'index',
),
$hierarchy
$hierarchy,
'Incorrect hierarchy for multi word categories.'
);
// Single word taxonomy.
// Single word taxonomy term.
$hierarchy = get_template_hierarchy( 'taxonomy-books-action', false, 'taxonomy-books' );
$this->assertEquals(
$this->assertSame(
array(
'taxonomy-books-action',
'taxonomy-books',
'taxonomy',
'archive',
'index',
),
$hierarchy
$hierarchy,
'Incorrect hierarchy for single word taxonomy and term.'
);
$hierarchy = get_template_hierarchy( 'taxonomy-books-action-adventure', false, 'taxonomy-books' );
$this->assertEquals(
$this->assertSame(
array(
'taxonomy-books-action-adventure',
'taxonomy-books',
'taxonomy',
'archive',
'index',
),
$hierarchy
$hierarchy,
'Incorrect hierarchy for single word taxonomy and multi word term.'
);
// Multi word taxonomy/terms.
$hierarchy = get_template_hierarchy( 'taxonomy-greek-books-action-adventure', false, 'taxonomy-greek-books' );
$this->assertEquals(
$this->assertSame(
array(
'taxonomy-greek-books-action-adventure',
'taxonomy-greek-books',
'taxonomy',
'archive',
'index',
),
$hierarchy
$hierarchy,
'Incorrect hierarchy for multi word taxonomy and term.'
);
// Post types.
$hierarchy = get_template_hierarchy( 'single-book', false, 'single-book' );
$this->assertEquals(
$this->assertSame(
array(
'single-book',
'single',
'singular',
'index',
),
$hierarchy
$hierarchy,
'Incorrect hierarchy for single word post type.'
);
$hierarchy = get_template_hierarchy( 'single-art-project', false, 'single-art-project' );
$this->assertEquals(
$this->assertSame(
array(
'single-art-project',
'single',
'singular',
'index',
),
$hierarchy
$hierarchy,
'Incorrect hierarchy for multi word post type.'
);
$hierarchy = get_template_hierarchy( 'single-art-project-imagine', false, 'single-art-project' );
$this->assertEquals(
$this->assertSame(
array(
'single-art-project-imagine',
'single-art-project',
'single',
'singular',
'index',
),
$hierarchy
$hierarchy,
'Incorrect hierarchy for single post with multi word post type.'
);
$hierarchy = get_template_hierarchy( 'page-hi', false, 'page' );
$this->assertEquals(
$this->assertSame(
array(
'page-hi',
'page',
'singular',
'index',
),
$hierarchy
$hierarchy,
'Incorrect hierarchy for single page.'
);
// Authors.
$hierarchy = get_template_hierarchy( 'author-rigas', false, 'author' );
$this->assertEquals(
$this->assertSame(
array(
'author-rigas',
'author',
'archive',
'index',
),
$hierarchy
$hierarchy,
'Incorrect hierarchy for single author.'
);
}
}
26 changes: 13 additions & 13 deletions tests/phpunit/tests/rest-api/rest-post-types-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,19 +162,19 @@ public function test_get_item_schema() {
$data = $response->get_data();
$properties = $data['schema']['properties'];
$this->assertCount( 13, $properties );
$this->assertArrayHasKey( 'capabilities', $properties );
$this->assertArrayHasKey( 'description', $properties );
$this->assertArrayHasKey( 'hierarchical', $properties );
$this->assertArrayHasKey( 'viewable', $properties );
$this->assertArrayHasKey( 'labels', $properties );
$this->assertArrayHasKey( 'name', $properties );
$this->assertArrayHasKey( 'slug', $properties );
$this->assertArrayHasKey( 'supports', $properties );
$this->assertArrayHasKey( 'taxonomies', $properties );
$this->assertArrayHasKey( 'rest_base', $properties );
$this->assertArrayHasKey( 'rest_namespace', $properties );
$this->assertArrayHasKey( 'visibility', $properties );
$this->assertArrayHasKey( 'icon', $properties );
$this->assertArrayHasKey( 'capabilities', $properties, '`capabilities` should be included in the schema.' );
$this->assertArrayHasKey( 'description', $properties, '`description` should be included in the schema.' );
$this->assertArrayHasKey( 'hierarchical', $properties, '`hierarchical` should be included in the schema.' );
$this->assertArrayHasKey( 'viewable', $properties, '`viewable` should be included in the schema.' );
$this->assertArrayHasKey( 'labels', $properties, '`labels` should be included in the schema.' );
$this->assertArrayHasKey( 'name', $properties, '`name` should be included in the schema.' );
$this->assertArrayHasKey( 'slug', $properties, '`slug` should be included in the schema.' );
$this->assertArrayHasKey( 'supports', $properties, '`supports` should be included in the schema.' );
$this->assertArrayHasKey( 'taxonomies', $properties, '`taxonomies` should be included in the schema.' );
$this->assertArrayHasKey( 'rest_base', $properties, '`rest_base` should be included in the schema.' );
$this->assertArrayHasKey( 'rest_namespace', $properties, '`rest_namespace` should be included in the schema.' );
$this->assertArrayHasKey( 'visibility', $properties, '`visibility` should be included in the schema.' );
$this->assertArrayHasKey( 'icon', $properties, '`icon` should be included in the schema.' );
}

public function test_get_additional_field_registration() {
Expand Down
12 changes: 6 additions & 6 deletions tests/phpunit/tests/rest-api/wpRestTemplatesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ public function test_create_item_with_is_wp_suggestion() {
'is_custom' => false,
'author' => self::$admin_id,
);
$this->assertSame( $expected, $data );
$this->assertSame( $expected, $data, 'Incorrect response when `is_wp_suggestion:true` is set.' );
// `is_wp_suggestion` false.
$body_params = wp_parse_args(
array(
Expand All @@ -747,7 +747,7 @@ public function test_create_item_with_is_wp_suggestion() {
),
$expected
);
$this->assertSame( $expected, $data );
$this->assertSame( $expected, $data, 'Incorrect response when `is_wp_suggestion:false` is set.' );
}

/**
Expand All @@ -758,17 +758,17 @@ public function test_get_template_fallback() {
wp_set_current_user( self::$admin_id );
switch_theme( 'block-theme' );
$request = new WP_REST_Request( 'GET', '/wp/v2/templates/lookup' );
// Should fallback to `index.html` .
// Should fallback to `index.html`.
$request->set_param( 'slug', 'tag-status' );
$request->set_param( 'is_custom', false );
$request->set_param( 'template_prefix', 'tag' );
$response = rest_get_server()->dispatch( $request );
$this->assertEquals( 'index', $response->get_data()->slug );
// Should fallback to `page.html` .
$this->assertSame( 'index', $response->get_data()->slug, 'Should fallback to `index.html`.' );
// Should fallback to `page.html`.
$request->set_param( 'slug', 'page-hello' );
$request->set_param( 'is_custom', false );
$request->set_param( 'template_prefix', 'page' );
$response = rest_get_server()->dispatch( $request );
$this->assertEquals( 'page', $response->get_data()->slug );
$this->assertSame( 'page', $response->get_data()->slug, 'Should fallback to `page.html`.' );
}
}