Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix font library unit tests nit-picks [round 2] #58612

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @group font-library
*/
class Tests_Font_Family_Backwards_Compatibility extends WP_UnitTestCase {
private $post_ids_to_delete = array();
private $post_ids_to_delete;

public function set_up() {
parent::set_up();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function mock_request( $preempt, $args, $url ) {
}

return array(
'body' => json_encode( self::$mock_collection_data ),
'body' => wp_json_encode( self::$mock_collection_data ),
'response' => array(
'code' => 200,
),
Expand All @@ -122,7 +122,7 @@ public function mock_request_missing_slug( $preempt, $args, $url ) {
unset( $mock_collection_data['slug'] );

return array(
'body' => json_encode( $mock_collection_data ),
'body' => wp_json_encode( $mock_collection_data ),
'response' => array(
'code' => 200,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function test_should_get_mock_font_collection() {
WP_Font_Library::register_font_collection( 'my-font-collection', $my_font_collection_config );

$font_collections = WP_Font_Library::get_font_collections();
$this->assertNotEmpty( $font_collections, 'Sould return an array of font collections.' );
$this->assertNotEmpty( $font_collections, 'Should return an array of font collections.' );
$this->assertCount( 1, $font_collections, 'Should return an array with one font collection.' );
$this->assertArrayHasKey( 'my-font-collection', $font_collections, 'The array should have the key of the registered font collection id.' );
$this->assertInstanceOf( 'WP_Font_Collection', $font_collections['my-font-collection'], 'The value of the array $font_collections[id] should be an instance of WP_Font_Collection class.' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function test_should_unregister_font_collection() {
}

public function unregister_non_existing_collection() {
// Unregisters non existing font collection.
// Unregisters non-existing font collection.
WP_Font_Library::unregister_font_collection( 'non-existing-collection' );
$collections = WP_Font_Library::get_font_collections();
$this->assertEmpty( $collections, 'Should not be registered collections.' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public function test_register_routes() {
$this->assertCount( 1, $routes['/wp/v2/font-collections'], 'Rest server has not the collections path initialized.' );
$this->assertCount( 1, $routes['/wp/v2/font-collections/(?P<slug>[\/\w-]+)'], 'Rest server has not the collection path initialized.' );

$this->assertArrayHasKey( 'GET', $routes['/wp/v2/font-collections'][0]['methods'], 'Rest server has not the GET method for collections intialized.' );
$this->assertArrayHasKey( 'GET', $routes['/wp/v2/font-collections/(?P<slug>[\/\w-]+)'][0]['methods'], 'Rest server has not the GET method for collection intialized.' );
$this->assertArrayHasKey( 'GET', $routes['/wp/v2/font-collections'][0]['methods'], 'Rest server has not the GET method for collections initialized.' );
$this->assertArrayHasKey( 'GET', $routes['/wp/v2/font-collections/(?P<slug>[\/\w-]+)'][0]['methods'], 'Rest server has not the GET method for collection initialized.' );
}

/**
Expand Down
14 changes: 7 additions & 7 deletions phpunit/tests/fonts/font-library/wpRestFontFacesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,12 +386,12 @@ public function test_create_item() {
$settings = $data['font_face_settings'];
unset( $settings['src'] );
$this->assertSame(
$settings,
array(
'fontFamily' => '"Open Sans"',
'fontWeight' => '200',
'fontStyle' => 'normal',
),
$settings,
'The font_face_settings data should match the expected data.'
);

Expand Down Expand Up @@ -730,14 +730,14 @@ public function test_create_item_invalid_file_src() {
}

/**
* @dataProvider data_create_item_santize_font_family
* @dataProvider data_create_item_sanitize_font_family
*
* @covers WP_REST_Font_Face_Controller::sanitize_font_face_settings
*
* @param string $font_family_setting Setting to test.
* @param string $expected Expected result.
*/
public function test_create_item_santize_font_family( $font_family_setting, $expected ) {
public function test_create_item_sanitize_font_family( $font_family_setting, $expected ) {
$settings = array_merge( self::$default_settings, array( 'fontFamily' => $font_family_setting ) );

wp_set_current_user( self::$admin_id );
Expand All @@ -755,7 +755,7 @@ public function test_create_item_santize_font_family( $font_family_setting, $exp
*
* @return array
*/
public function data_create_item_santize_font_family() {
public function data_create_item_sanitize_font_family() {
return array(
'multiword font with integer' => array(
'font_family_setting' => 'Libre Barcode 128 Text',
Expand Down Expand Up @@ -930,11 +930,11 @@ protected function check_font_face_data( $data, $post_id, $links ) {
$this->assertSame( $expected, $links['parent'][0]['href'], 'The links for a parent URL from the response data should match the parent\'s REST endpoint.' );
}

protected function check_file_meta( $font_face_id, $srcs ) {
protected function check_file_meta( $font_face_id, $src_attributes ) {
$file_meta = get_post_meta( $font_face_id, '_wp_font_face_file' );

foreach ( $srcs as $src ) {
$file_name = basename( $src );
foreach ( $src_attributes as $src_attribute ) {
$file_name = basename( $src_attribute );
$this->assertContains( $file_name, $file_meta, 'The uploaded font file path should be saved in the post meta.' );
}
}
Expand Down
Loading