Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
111 commits
Select commit Hold shift + click to select a range
9a00814
add main backend files
matiasbenedetto Sep 22, 2023
6f9aefc
add comment about CDN link
matiasbenedetto Sep 22, 2023
d78d99b
load main files
matiasbenedetto Sep 22, 2023
1d74144
add routes from font library to routes test
matiasbenedetto Sep 22, 2023
42eeb48
adding PHP unit tests for font library
matiasbenedetto Sep 22, 2023
9e06a93
fix register post type for font family post type
matiasbenedetto Sep 22, 2023
b323b67
move the font library functions
matiasbenedetto Sep 22, 2023
715eea9
avoid loading file deleted
matiasbenedetto Sep 22, 2023
e54426a
add wp_register_default_font_collection function
matiasbenedetto Sep 22, 2023
1078767
load font-library functions file
matiasbenedetto Sep 22, 2023
699f45b
register default font collection with init hook
matiasbenedetto Sep 22, 2023
a6dca33
fix rest-schema test
matiasbenedetto Sep 22, 2023
9ba9187
Merge branch 'trunk' into port/font-library
matiasbenedetto Sep 23, 2023
5084180
settings the right 'supports' values for wp_font_family post type
matiasbenedetto Sep 23, 2023
46a1e9f
set hierarchical as false for wp_font_family post type
matiasbenedetto Sep 23, 2023
7e666e6
fix url in test
matiasbenedetto Sep 23, 2023
e6cce43
fix set_upload_dir unit test
matiasbenedetto Sep 23, 2023
673c042
fix unit test by using solvable host name
matiasbenedetto Sep 23, 2023
72bbec5
avoid using gutenberg class, use core class instead
matiasbenedetto Sep 23, 2023
1d8de84
add the font assets for the tests
matiasbenedetto Sep 23, 2023
d769cc5
Remove font files created after tests run
matiasbenedetto Sep 25, 2023
c4a31d2
removing unwanted echo line
matiasbenedetto Sep 25, 2023
57f05a1
Merge branch 'trunk' into port/font-library
matiasbenedetto Sep 25, 2023
8933cb8
add the custom post type routes to the routes test
matiasbenedetto Sep 25, 2023
9aeb0ba
Removing class re-declaration check
matiasbenedetto Sep 25, 2023
1725825
format php
matiasbenedetto Sep 25, 2023
d4bce59
updating wp-api-generated.js schema
matiasbenedetto Sep 25, 2023
89e888f
Merge branch 'trunk' into port/font-library
matiasbenedetto Sep 25, 2023
ab70608
Revert "updating wp-api-generated.js schema"
matiasbenedetto Sep 25, 2023
739edeb
moving font library rest controller to the endpoints folder
matiasbenedetto Sep 25, 2023
534264e
Removing 'gutenberg' translation domain
matiasbenedetto Sep 25, 2023
c2d38d6
add comment about mime types logic
matiasbenedetto Sep 25, 2023
2a715cd
using wordpress.org cdn to host google fonts collection data json file
matiasbenedetto Sep 25, 2023
6bf7be3
updating wp-api-generated.js fixtures
matiasbenedetto Sep 25, 2023
bbb09e9
avoid deprecation error in test
matiasbenedetto Sep 25, 2023
654dd1d
Moving default font collection registration to font.php file
matiasbenedetto Sep 25, 2023
635d870
moving font library files to the main fonts folder
matiasbenedetto Sep 25, 2023
8714206
remove path from deleted file
matiasbenedetto Sep 25, 2023
2e08b53
Merge branch 'trunk' into port/font-library
matiasbenedetto Sep 25, 2023
8c5ddec
replace strpos by str_contains
matiasbenedetto Sep 26, 2023
ae15e18
Merge branch 'trunk' into port/font-library
matiasbenedetto Sep 27, 2023
04fe719
Testeable mime type conditionals
matiasbenedetto Sep 27, 2023
839ff70
Change expected OTF files mime type
matiasbenedetto Sep 28, 2023
5116443
standardize the output of install and uninstall endpoints
matiasbenedetto Sep 29, 2023
d89e201
update install and uninstall enpoints tests for the new standard outp…
matiasbenedetto Sep 29, 2023
e4b2a85
remove class_exist check coming from gutenberg
matiasbenedetto Oct 2, 2023
8e3e711
remove unused line
matiasbenedetto Oct 2, 2023
947e2cb
add trailing dot
matiasbenedetto Oct 2, 2023
88ec9b7
se snake_case instead of camelCase on fontFamilies endpoint param
matiasbenedetto Oct 2, 2023
3e63080
Merge branch 'trunk' into port/font-library
matiasbenedetto Oct 2, 2023
e218ec8
using DIR_TESTDATA for file assets paths
matiasbenedetto Oct 2, 2023
02d6767
Remove extra new line
matiasbenedetto Oct 2, 2023
641e9f3
emoving an unnecessary line break
matiasbenedetto Oct 2, 2023
5178b1e
use self::factory() to insert post in test
matiasbenedetto Oct 2, 2023
4612703
avoid adding variable name in return comment
matiasbenedetto Oct 2, 2023
f69e6e5
update return type of function
matiasbenedetto Oct 2, 2023
17c9fd3
update comments
matiasbenedetto Oct 2, 2023
3021090
move property definition on top of the class
matiasbenedetto Oct 2, 2023
db11c1f
replace EDITABLE by CREATABLE
matiasbenedetto Oct 2, 2023
31af894
move uninstall endpoint schema
matiasbenedetto Oct 2, 2023
21e3d33
updating wp-api-generated.js file
matiasbenedetto Oct 2, 2023
9aa43bf
Rename function
matiasbenedetto Oct 2, 2023
f38bb59
make string translatable
matiasbenedetto Oct 2, 2023
b005321
Add id argument to the font collection.
anton-vlasenko Oct 2, 2023
2b29de4
remove triling comma
matiasbenedetto Oct 2, 2023
aaf3741
change WP_REST_Response by rest_ensure_response
matiasbenedetto Oct 2, 2023
d6534cc
Remove path_join() for constant in tests
hellofromtonya Oct 2, 2023
3b01b46
Change subpackage to Fonts
hellofromtonya Oct 2, 2023
f16ead0
Initialize properties to empty array
hellofromtonya Oct 2, 2023
30369c6
Empty line before end of function return.
hellofromtonya Oct 2, 2023
e1f0b58
1. Implement schema.
anton-vlasenko Oct 2, 2023
aec6c93
Removes passing PHP version to WP_Font_Library::get_font_mime_types().
hellofromtonya Oct 2, 2023
b34fe52
Implement the schema for the font collections endpoint.
anton-vlasenko Oct 2, 2023
e948c1b
Multiline comments props costdev
hellofromtonya Oct 2, 2023
0926426
Update wp-api-generated.js.
anton-vlasenko Oct 2, 2023
11b26db
PHPCS: Remove extra empty line at end of file
hellofromtonya Oct 2, 2023
feb1199
Remove isset() where empty() is also used. Prop costdev
hellofromtonya Oct 2, 2023
a776cee
Use $request['id'] - props spacedmonkey
hellofromtonya Oct 3, 2023
909da30
make install and uninstall endpoints singular.
matiasbenedetto Oct 3, 2023
fd706d1
rename font library enpoints and split font library controller in 2 d…
matiasbenedetto Oct 3, 2023
7081941
remove unwanted enpoint from WP_REST_Font_Families_Controller class
matiasbenedetto Oct 4, 2023
b49da9a
dont show custom post type in rest endpoints
matiasbenedetto Oct 4, 2023
2d369aa
use lowercase in error message
matiasbenedetto Oct 4, 2023
86dab9e
update wording
matiasbenedetto Oct 4, 2023
b167d7f
Implementing get_item and get_items for /font-families/ endpoints
matiasbenedetto Oct 4, 2023
1c23f09
Refactored font-family GET and DELETE api endpoints to use SLUG inste…
pbking Oct 4, 2023
4f7fd91
Added or refactored tests for Font Family createItem, deleteItem, get…
pbking Oct 4, 2023
14ca3bd
Refactored Font Family tests to use getPostBySlug
pbking Oct 4, 2023
8d9f496
use snake_case schema in font collections endpoints
matiasbenedetto Oct 4, 2023
1243b31
update api endpoint routes test and fixture
matiasbenedetto Oct 4, 2023
c5c6ec4
fix the font collections schema to accomodate arrays instead of a sin…
matiasbenedetto Oct 4, 2023
f398761
1. Remove the registerRoutes test.
anton-vlasenko Oct 4, 2023
d85e545
Fix CS.
anton-vlasenko Oct 4, 2023
07d01ff
Fix CS.
anton-vlasenko Oct 4, 2023
ec52113
grouping font-families endpoints and add response schemas.
matiasbenedetto Oct 5, 2023
3967726
add default order for font families
matiasbenedetto Oct 5, 2023
a19ac36
add since 6.4 comment
matiasbenedetto Oct 5, 2023
05d3ff7
Remove extra new line
matiasbenedetto Oct 5, 2023
963d226
remove extra spaces
matiasbenedetto Oct 5, 2023
e28134f
add missing 'since 6.4' comment
matiasbenedetto Oct 5, 2023
b2a96fc
Get rid of WP_REST_Font_Library_Controller_UnitTestCase.
anton-vlasenko Oct 5, 2023
640159e
Fix parent class name.
anton-vlasenko Oct 5, 2023
d44da25
fix typo in comment
matiasbenedetto Oct 5, 2023
603ee9e
Rename controller methods.
anton-vlasenko Oct 5, 2023
7382406
Fix 404 errors.
anton-vlasenko Oct 5, 2023
d9ffea9
Move the tests to Tests_Fonts_WpRestFontCollectionsController.
anton-vlasenko Oct 5, 2023
9edfb39
Fix the tests.
anton-vlasenko Oct 5, 2023
c4de43f
Improve PHPDOC blocks.
anton-vlasenko Oct 5, 2023
9deeb4a
Fix @return type.
anton-vlasenko Oct 5, 2023
6c9e856
Implement the test for Tests_Fonts_WpRestFontCollectionsController::t…
anton-vlasenko Oct 9, 2023
89cd000
Fix the test.
anton-vlasenko Oct 9, 2023
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 PHP unit tests for font library
  • Loading branch information
matiasbenedetto committed Sep 22, 2023
commit 42eeb481fcd54ce3fd17f9294c19f971b413f40a
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php
/**
* Test WP_Font_Collection::__construct().
*
* @package WordPress
* @subpackage Font Library
*
* @group fonts
* @group font-library
*
* @covers WP_Font_Collection::__construct
*/
class Tests_Fonts_WpFontCollection_Construct extends WP_UnitTestCase {

public function test_should_initialize_data() {
$property = new ReflectionProperty( WP_Font_Collection::class, 'config' );
$property->setAccessible( true );

$config = array(
'id' => 'my-collection',
'name' => 'My Collection',
'description' => 'My collection description',
'src' => 'my-collection-data.json',
);
$font_collection = new WP_Font_Collection( $config );

$actual = $property->getValue( $font_collection );
$property->setAccessible( false );

$this->assertSame( $config, $actual );
}

/**
* @dataProvider data_should_throw_exception
*
* @param mixed $config Config of the font collection.
* @param string $expected_exception_message Expected exception message.
*/
public function test_should_throw_exception( $config, $expected_exception_message ) {
$this->expectException( 'Exception' );
$this->expectExceptionMessage( $expected_exception_message );
new WP_Font_Collection( $config );
}

/**
* Data provider.
*
* @return array
*/
public function data_should_throw_exception() {
return array(
'no id' => array(
array(
'name' => 'My Collection',
'description' => 'My collection description',
'src' => 'my-collection-data.json',
),
'Font Collection config ID is required as a non-empty string.',
),

'no config' => array(
'',
'Font Collection config options is required as a non-empty array.',
),

'empty array' => array(
array(),
'Font Collection config options is required as a non-empty array.',
),

'boolean instead of config array' => array(
false,
'Font Collection config options is required as a non-empty array.',
),

'null instead of config array' => array(
null,
'Font Collection config options is required as a non-empty array.',
),

'missing src' => array(
array(
'id' => 'my-collection',
'name' => 'My Collection',
'description' => 'My collection description',
),
'Font Collection config "src" option is required as a non-empty string.',
),

);
}
}
103 changes: 103 additions & 0 deletions tests/phpunit/tests/fonts/font-library/wpFontCollection/getData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php
/**
* Test WP_Font_Collection::get_data().
*
* @package WordPress
* @subpackage Font Library
*
* @group fonts
* @group font-library
*
* @covers WP_Font_Collection::get_data
*/
class Tests_Fonts_WpFontCollection_GetData extends WP_UnitTestCase {

public function set_up() {
parent::set_up();

// Mock the wp_remote_request() function.
add_filter( 'pre_http_request', array( $this, 'mock_request' ), 10, 3 );
}

public function tear_down() {
// Remove the mock to not affect other tests.
remove_filter( 'pre_http_request', array( $this, 'mock_request' ) );

parent::tear_down();
}

public function mock_request( $preempt, $args, $url ) {
// if the URL is not the URL you want to mock, return false.
if ( 'https://localhost/fonts/mock-font-collection.json' !== $url ) {
return false;
}

// Mock the response body.
$mock_collection_data = array(
'fontFamilies' => 'mock',
'categories' => 'mock',
);

return array(
'body' => json_encode( $mock_collection_data ),
'response' => array(
'code' => 200,
),
);
}

/**
* @dataProvider data_should_get_data
*
* @param array $config Font collection config options.
* @param array $expected_data Expected data.
*/
public function test_should_get_data( $config, $expected_data ) {
$collection = new WP_Font_Collection( $config );
$this->assertSame( $expected_data, $collection->get_data() );
}

/**
* Data provider.
*
* @return array[]
*/
public function data_should_get_data() {
$mock_file = wp_tempnam( 'my-collection-data-' );
file_put_contents( $mock_file, '{"this is mock data":true}' );

return array(
'with a file' => array(
'config' => array(
'id' => 'my-collection',
'name' => 'My Collection',
'description' => 'My collection description',
'src' => $mock_file,
),
'expected_data' => array(
'id' => 'my-collection',
'name' => 'My Collection',
'description' => 'My collection description',
'data' => array( 'this is mock data' => true ),
),
),
'with a url' => array(
'config' => array(
'id' => 'my-collection-with-url',
'name' => 'My Collection with URL',
'description' => 'My collection description',
'src' => 'https://localhost/fonts/mock-font-collection.json',
),
'expected_data' => array(
'id' => 'my-collection-with-url',
'name' => 'My Collection with URL',
'description' => 'My collection description',
'data' => array(
'fontFamilies' => 'mock',
'categories' => 'mock',
),
),
),
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
/**
* Test WP_Font_Family::__construct().
*
* @package WordPress
* @subpackage Font Library
*
* @group fonts
* @group font-library
*
* @covers WP_Font_Family::__construct
*/
class Tests_Fonts_WpFontFamily_Construct extends WP_UnitTestCase {

public function test_should_initialize_data() {
$property = new ReflectionProperty( WP_Font_Family::class, 'data' );
$property->setAccessible( true );

$font_data = array(
'fontFamily' => 'Piazzolla',
'name' => 'Piazzolla',
'slug' => 'piazzolla',
);
$font_family = new WP_Font_Family( $font_data );

$actual = $property->getValue( $font_family );
$property->setAccessible( false );

$this->assertSame( $font_data, $actual );
}

/**
* @dataProvider data_should_throw_exception
*
* @param mixed $font_data Data to test.
*/
public function test_should_throw_exception( $font_data ) {
$this->expectException( 'Exception' );
$this->expectExceptionMessage( 'Font family data is missing the slug.' );

new WP_Font_Family( $font_data );
}

/**
* Data provider.
*
* @return array
*/
public function data_should_throw_exception() {
return array(
'no slug' => array(
array(
'fontFamily' => 'Piazzolla',
'name' => 'Piazzolla',
),
),
'empty array' => array( array() ),
'boolean instead of array' => array( false ),
'null instead of array' => array( null ),
);
}
}
75 changes: 75 additions & 0 deletions tests/phpunit/tests/fonts/font-library/wpFontFamily/base.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
/**
* Test Case for WP_Font_Family tests.
*
* @package WordPress
* @subpackage Font Library
*/
abstract class WP_Font_Family_UnitTestCase extends WP_UnitTestCase {

/**
* Fonts directory (in uploads).
*
* @var string
*/
protected static $fonts_dir;

/**
* Merriweather test data shared by tests.
*
* @var array
*/
protected $merriweather = array(
'font_data' => array(),
'files_data' => array(),
'font_filename' => '',
);

public static function set_up_before_class() {
parent::set_up_before_class();

static::$fonts_dir = WP_Font_Library::get_fonts_dir();
wp_mkdir_p( static::$fonts_dir );
}

public function set_up() {
parent::set_up();

$merriweather_tmp_name = wp_tempnam( 'Merriweather-' );
copy( __DIR__ . '/../../../data/fonts/Merriweather.ttf', $merriweather_tmp_name );
$this->merriweather = array(
'font_data' => array(
'name' => 'Merriweather',
'slug' => 'merriweather',
'fontFamily' => 'Merriweather',
'fontFace' => array(
array(
'fontFamily' => 'Merriweather',
'fontStyle' => 'normal',
'fontWeight' => '400',
'uploadedFile' => 'files0',
),
),
),
'files_data' => array(
'files0' => array(
'name' => 'merriweather.ttf',
'type' => 'font/ttf',
'tmp_name' => $merriweather_tmp_name,
'error' => 0,
'size' => 123,
),
),
'font_filename' => path_join( static::$fonts_dir, 'merriweather_normal_400.ttf' ),
);
}

public function tear_down() {
// Clean up the /fonts directory.
foreach ( $this->files_in_dir( static::$fonts_dir ) as $file ) {
@unlink( $file );
}

parent::tear_down();
}
}
Loading