Skip to content

Commit

Permalink
Additional test updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta committed Jan 26, 2024
1 parent a889d00 commit 257db13
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ public function test_get_item_schema() {

$properties = $data['schema']['properties'];

$this->assertCount( 16, $properties );
$this->assertCount( 18, $properties );
$this->assertArrayHasKey( 'id', $properties, 'ID key should exist in properties.' );
$this->assertArrayHasKey( 'slug', $properties, 'Slug key should exist in properties.' );
$this->assertArrayHasKey( 'theme', $properties, 'Theme key should exist in properties.' );
Expand All @@ -326,6 +326,8 @@ public function test_get_item_schema() {
$this->assertArrayHasKey( 'modified', $properties, 'modified key should exist in properties.' );
$this->assertArrayHasKey( 'is_custom', $properties, 'is_custom key should exist in properties.' );
$this->assertArrayHasKey( 'parent', $properties, 'Parent key should exist in properties.' );
$this->assertArrayHasKey( 'author_text', $properties, 'Parent key should exist in properties.' );
$this->assertArrayHasKey( 'original_source', $properties, 'Parent key should exist in properties.' );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ public function test_get_item_schema() {
$data = $response->get_data();
$properties = $data['schema']['properties'];

$this->assertCount( 16, $properties );
$this->assertCount( 18, $properties );
$this->assertArrayHasKey( 'id', $properties, 'ID key should exist in properties.' );
$this->assertArrayHasKey( 'slug', $properties, 'Slug key should exist in properties.' );
$this->assertArrayHasKey( 'theme', $properties, 'Theme key should exist in properties.' );
Expand All @@ -465,6 +465,8 @@ public function test_get_item_schema() {
$this->assertArrayHasKey( 'modified', $properties, 'modified key should exist in properties.' );
$this->assertArrayHasKey( 'is_custom', $properties, 'is_custom key should exist in properties.' );
$this->assertArrayHasKey( 'parent', $properties, 'Parent key should exist in properties.' );
$this->assertArrayHasKey( 'author_text', $properties, 'Parent key should exist in properties.' );
$this->assertArrayHasKey( 'original_source', $properties, 'Parent key should exist in properties.' );
}

/**
Expand Down
28 changes: 18 additions & 10 deletions tests/phpunit/tests/rest-api/wpRestTemplatesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,8 @@ public function test_create_item() {
unset( $data['_links'] );
unset( $data['wp_id'] );

$author_name = get_user_by( 'id', self::$admin_id )->get( 'display_name' );

$this->assertSame(
array(
'id' => 'default//my_custom_template',
Expand All @@ -451,8 +453,8 @@ public function test_create_item() {
'is_custom' => true,
'author' => self::$admin_id,
'modified' => mysql_to_rfc3339( $modified ),
'author_text' => 'Test Blog',
'original_source' => 'site',
'author_text' => $author_name,
'original_source' => 'user',
),
$data
);
Expand Down Expand Up @@ -480,6 +482,8 @@ public function test_create_item_with_numeric_slug() {
unset( $data['_links'] );
unset( $data['wp_id'] );

$author_name = get_user_by( 'id', self::$admin_id )->get( 'display_name' );

$this->assertSame(
array(
'id' => 'default//404',
Expand All @@ -501,8 +505,8 @@ public function test_create_item_with_numeric_slug() {
'is_custom' => false,
'author' => self::$admin_id,
'modified' => mysql_to_rfc3339( $modified ),
'author_text' => 'Test Blog',
'original_source' => 'site',
'author_text' => $author_name,
'original_source' => 'user',
),
$data
);
Expand Down Expand Up @@ -534,6 +538,8 @@ public function test_create_item_raw() {
unset( $data['_links'] );
unset( $data['wp_id'] );

$author_name = get_user_by( 'id', self::$admin_id )->get( 'display_name' );

$this->assertSame(
array(
'id' => 'default//my_custom_template_raw',
Expand All @@ -555,8 +561,8 @@ public function test_create_item_raw() {
'is_custom' => true,
'author' => self::$admin_id,
'modified' => mysql_to_rfc3339( $modified ),
'author_text' => 'Test Blog',
'original_source' => 'site',
'author_text' => $author_name,
'original_source' => 'user',
),
$data
);
Expand Down Expand Up @@ -732,8 +738,8 @@ public function test_get_item_schema() {
$this->assertArrayHasKey( 'is_custom', $properties );
$this->assertArrayHasKey( 'author', $properties );
$this->assertArrayHasKey( 'modified', $properties );
$this->assertArrayHasKey( 'author_text', 'Test Blog' );
$this->assertArrayHasKey( 'original_source', 'site' );
$this->assertArrayHasKey( 'author_text', $properties );
$this->assertArrayHasKey( 'original_source', $properties );
}

protected function find_and_normalize_template_by_id( $templates, $id ) {
Expand Down Expand Up @@ -768,6 +774,10 @@ public function test_create_item_with_is_wp_suggestion( array $body_params, arra
$data = $response->get_data();
$modified = get_post( $data['wp_id'] )->post_modified;
$expected['modified'] = mysql_to_rfc3339( $modified );
$expected['author_text'] = get_user_by( 'id', self::$admin_id )->get( 'display_name' );
$expected['original_source'] = 'user';

Check failure on line 779 in tests/phpunit/tests/rest-api/wpRestTemplatesController.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Functions must not contain multiple empty lines in a row; found 2 empty lines

unset( $data['_links'] );
unset( $data['wp_id'] );

Expand Down Expand Up @@ -799,8 +809,6 @@ public function data_create_item_with_is_wp_suggestion() {
'has_theme_file' => false,
'is_custom' => false,
'author' => null,
'author_text' => 'Test Blog',
'original_source' => 'site',
);

return array(
Expand Down

0 comments on commit 257db13

Please sign in to comment.