Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d343f65
WIP: Refactor Font API font family GET POST testing round 1
pbking Dec 12, 2023
4b342c5
Added GET font family collection tests and implementation
pbking Dec 12, 2023
3343b98
add font family IDs to API responses
pbking Dec 12, 2023
3374120
Move data into 'data' object
pbking Dec 12, 2023
8a4c798
Added delete API implementation and tests
pbking Dec 13, 2023
140faf0
Adding 'force' to font family delete api
pbking Dec 13, 2023
7d26ae9
Got basic font family updating service working
pbking Dec 13, 2023
f71111c
Moved implementation of adding font faces to use font family put inst…
pbking Dec 13, 2023
2ed64b2
Removed route tests (testing the routes seems sufficient and they are…
pbking Dec 13, 2023
88d70ba
Renamed controller to 'Font Family Controller'
pbking Dec 13, 2023
dc9fb0b
Renamed controller to 'Font Family Controller' (continued)
pbking Dec 13, 2023
95e9ce5
Refactored font collection API into its own controller
pbking Dec 13, 2023
9ef8086
Simplifying font family update logic (WIP)
pbking Dec 13, 2023
f28f616
Added better error handling for Font Family creation and updating. A…
pbking Dec 14, 2023
47eb63a
Adding tests for font families with downloaded font face assets
pbking Dec 14, 2023
759a08b
Added upload font face asset tests. Cleaned up update logic.
pbking Dec 14, 2023
efb51e8
Refactored existing tests into individual files and cleaned them up
pbking Dec 15, 2023
592faac
Refactored existing tests into individual files and cleaned them up
pbking Dec 15, 2023
8aade9f
Added PATCH operation and remove file assets for font faces that were…
pbking Dec 15, 2023
aa15a94
Added ability to update font family via POST
pbking Dec 15, 2023
53e9001
Removed unused functions, moved 'create font folder' logic to class, …
pbking Dec 15, 2023
edefab4
Refactored font face asset handling to ONLY accept UPLOADED and HOSTE…
pbking Jan 10, 2024
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
Adding tests for font families with downloaded font face assets
  • Loading branch information
pbking committed Dec 14, 2023
commit 47eb63ab89763f8667e71ad35c547fd9b6618be0
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ public function data_create_font_family_with_improper_inputs() {
}

/**
* Tests responses when sucessfully creating Font Families
* Tests responses when sucessfully creating Font Families with hosted (or absent) assets
*
* @dataProvider data_create_font_family
* @dataProvider data_create_hosted_font_family
*
* @param array $font_family Font families to install in theme.json format.
* @param array $expected_response Expected response data.
*/
public function test_create_font_family( $font_family ) {
public function test_create_hosted_font_family( $font_family ) {
$install_request = new WP_REST_Request( 'POST', '/wp/v2/font-families' );
$install_request->set_param( 'data', $font_family );
$response = rest_get_server()->dispatch( $install_request );
Expand All @@ -133,10 +133,37 @@ public function test_create_font_family( $font_family ) {
}
}

/**
* Tests responses when sucessfully creating Font Families with downloaded assets
*
* @dataProvider data_create_downloaded_font_family
*
* @param array $font_family Font families to install in theme.json format.
* @param array $expected_response Expected response data.
*/
public function test_create_downloaded_font_family( $font_family ) {
$install_request = new WP_REST_Request( 'POST', '/wp/v2/font-families' );
$install_request->set_param( 'data', $font_family );
$response = rest_get_server()->dispatch( $install_request );
$response_data = $response->get_data();

$this->assertSame( 200, $response->get_status(), 'The response status is not 200.' );
$this->assertSame( $font_family['slug'], $response_data['data']['slug'], 'The slug response did not match expected.' );
$this->assertSame( $font_family['name'], $response_data['data']['name'], 'The name response did not match expected.' );
$this->assertSame( $font_family['fontFamily'], $response_data['data']['fontFamily'], 'The font_family response did not match expected.' );
$this->assertIsInt( $response_data['id'], 'The id response did not match expected.' );

$this->assertIsString( $response_data['data']['fontFace'][0]['src'], 'The font_family response did not match expected.' );
$this->assertArrayNotHasKey('downloadFromUrl', $response_data['data']['fontFace'][0], 'The font_family response did not match expected.' );

$this->assertIsString( $response_data['data']['fontFace'][1]['src'], 'The font_family response did not match expected.' );
$this->assertArrayNotHasKey('downloadFromUrl', $response_data['data']['fontFace'][1], 'The font_family response did not match expected.' );
}

/**
* Tests responses when getting existing Font Families
*
* @dataProvider data_create_font_family
* @dataProvider data_create_hosted_font_family
*
* @param array $font_families Font families to install in theme.json format.
* @param array $expected_response Expected response data.
Expand Down Expand Up @@ -174,7 +201,7 @@ public function test_delete_font_family_not_exist() {
/**
* Tests deleting existing Font Families. First creates a font family, then deletes it, then gets it to make sure it's gone.
*
* @dataProvider data_create_font_family
* @dataProvider data_create_hosted_font_family
*
* @param array $font_family Font families to install in theme.json format.
* @param array $expected_response Expected response data.
Expand Down Expand Up @@ -206,9 +233,9 @@ public function test_delete_font_family( $font_family ) {
}

/**
* Data provider for test_install_fonts
* Data provider for test_install_hosted_fonts
*/
public function data_create_font_family() {
public function data_create_hosted_font_family() {
return array(
'Arial' => array( array(
'slug' => 'arial',
Expand All @@ -225,16 +252,43 @@ public function data_create_font_family() {
'fontStyle' => 'normal',
'fontWeight' => '400',
'preview' => 'https://s.w.org/images/fonts/16.7/previews/abeezee/abeezee-400-normal.svg',
//'src' => 'https://fonts.gstatic.com/s/abeezee/v22/esDR31xSG-6AGleN6tKukbcHCpE.ttf',
'downloadFromUrl' => 'https://fonts.gstatic.com/s/abeezee/v22/esDR31xSG-6AGleN6tKukbcHCpE.ttf',
'src' => 'https://fonts.gstatic.com/s/abeezee/v22/esDR31xSG-6AGleN6tKukbcHCpE.ttf',
),
array(
'fontFamily' => 'ABeeZee',
'fontStyle' => 'italic',
'fontWeight' => '400',
'preview' => 'https://s.w.org/images/fonts/16.7/previews/abeezee/abeezee-400-italic.svg',
//'src' => 'https://fonts.gstatic.com/s/abeezee/v22/esDT31xSG-6AGleN2tCklZUCGpG-GQ.ttf',
'downloadFromUrl' => 'https://fonts.gstatic.com/s/abeezee/v22/esDT31xSG-6AGleN2tCklZUCGpG-GQ.ttf',
'src' => 'https://fonts.gstatic.com/s/abeezee/v22/esDT31xSG-6AGleN2tCklZUCGpG-GQ.ttf',
),
),
)),
);
}

/**
* Data provider for test_install_hosted_fonts
*/
public function data_create_downloaded_font_family() {
return array(
'Downloaded Font Face' => array( array(
'slug' => 'abeezee',
'name' => 'ABeeZee',
'fontFamily' => 'ABeeZee',
'fontFace' => array(
array(
'fontFamily' => 'ABeeZee',
'fontStyle' => 'normal',
'fontWeight' => '400',
'preview' => 'https://s.w.org/images/fonts/16.7/previews/abeezee/abeezee-400-normal.svg',
'downloadFromUrl' => 'https://fonts.gstatic.com/s/abeezee/v22/esDR31xSG-6AGleN6tKukbcHCpE.ttf',
),
array(
'fontFamily' => 'ABeeZee',
'fontStyle' => 'italic',
'fontWeight' => '400',
'preview' => 'https://s.w.org/images/fonts/16.7/previews/abeezee/abeezee-400-italic.svg',
'downloadFromUrl' => 'https://fonts.gstatic.com/s/abeezee/v22/esDT31xSG-6AGleN2tCklZUCGpG-GQ.ttf',
),
),
)),
Expand Down Expand Up @@ -279,6 +333,7 @@ public function test_update_font_family() {

}


/**
* Test getting a collection of all created font families
*/
Expand Down