Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
fb475a2
remove font collection
matiasbenedetto Sep 21, 2023
a50a2de
add wp_unregister_font_collection function
matiasbenedetto Sep 21, 2023
8b90373
format php
matiasbenedetto Sep 21, 2023
2968267
fix function comment
matiasbenedetto Sep 21, 2023
42a61c5
add tests for unregister_font_collection
matiasbenedetto Sep 21, 2023
27102fa
removig unused variable
matiasbenedetto Sep 21, 2023
da35119
Merge branch 'trunk' into try/unregister-font-collection
matiasbenedetto Oct 10, 2023
7830ff7
update wording on comments
matiasbenedetto Oct 10, 2023
2d6dcd2
Merge branch 'try/unregister-font-collection' of github.com:WordPress…
matiasbenedetto Oct 10, 2023
b7c9113
keep track of unregistered font collection ids in an array
matiasbenedetto Oct 11, 2023
cb28b82
add tests to assure that get_font_collections returns an empty array …
matiasbenedetto Oct 11, 2023
eee0a8d
fix tests
matiasbenedetto Oct 11, 2023
e489991
test the initial empty value of the font library collections
matiasbenedetto Oct 11, 2023
177aa58
format
matiasbenedetto Oct 11, 2023
06a10ea
simplify unregistering of font collections and add _doing_it_wrong call
matiasbenedetto Oct 11, 2023
4d16323
add translation domain
matiasbenedetto Oct 11, 2023
6f2ba86
adding _doing_it_wrong if you are registering collections with the sa…
matiasbenedetto Oct 12, 2023
d9ee03a
updating tests
matiasbenedetto Oct 12, 2023
a07e9fb
replace 6.4.0 by 6.5.0 in comments
matiasbenedetto Oct 12, 2023
e9f7b44
update version
matiasbenedetto Nov 14, 2023
e864318
Merge branch 'trunk' into try/unregister-font-collection
matiasbenedetto Dec 21, 2023
6ca8662
consolidate code as only one function to avoid code repetition
matiasbenedetto Dec 21, 2023
5a2c1ff
create base test case
matiasbenedetto Dec 21, 2023
83525bf
format php
matiasbenedetto Dec 21, 2023
a42fa3f
assertWPError
matiasbenedetto Dec 21, 2023
771e760
check that collection was not unregistered by mistake
matiasbenedetto Dec 21, 2023
5d38c57
calling parent test class mehtods
matiasbenedetto Dec 21, 2023
dcd9770
format php
matiasbenedetto Dec 21, 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
create base test case
  • Loading branch information
matiasbenedetto committed Dec 21, 2023
commit 5a2c1ffeff71d783a7ecc3e9b035f35a4a37e21f
24 changes: 24 additions & 0 deletions phpunit/tests/fonts/font-library/wpFontLibrary/base.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* Test Case for WP_Font_Library tests.
*
* @package WordPress
* @subpackage Font Library
*/
abstract class WP_Font_Library_UnitTestCase extends WP_UnitTestCase {
public function reset_font_collections() {
// Resets the private static property WP_Font_Library::$collections to empty array.
$reflection = new ReflectionClass( 'WP_Font_Library' );
$property = $reflection->getProperty( 'collections' );
$property->setAccessible( true );
$property->setValue( array() );
}

public function set_up() {
$this->reset_font_collections();
}

public function tear_down() {
$this->reset_font_collections();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,16 @@
*
* @covers WP_Font_Library::get_font_collection
*/
class Tests_Fonts_WpFontLibrary_GetFontCollection extends WP_UnitTestCase {
class Tests_Fonts_WpFontLibrary_GetFontCollection extends WP_Font_Library_UnitTestCase {

public static function set_up_before_class() {
public function test_should_get_font_collection() {
$my_font_collection_config = array(
'id' => 'my-font-collection',
'name' => 'My Font Collection',
'description' => 'Demo about how to a font collection to your WordPress Font Library.',
'src' => path_join( __DIR__, 'my-font-collection-data.json' ),
);

wp_register_font_collection( $my_font_collection_config );
}

public function test_should_get_font_collection() {
$font_collection = WP_Font_Library::get_font_collection( 'my-font-collection' );
$this->assertInstanceOf( 'WP_Font_Collection', $font_collection );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,7 @@
*
* @covers WP_Font_Library::get_font_collections
*/
class Tests_Fonts_WpFontLibrary_GetFontCollections extends WP_UnitTestCase {

public function reset_collections() {
// Resets the private static property WP_Font_Library::$collections to empty array.
$reflection = new ReflectionClass( 'WP_Font_Library' );
$property = $reflection->getProperty( 'collections' );
$property->setAccessible( true );
$property->setValue( array() );
}

public function set_up() {
$this->reset_collections();
}

public function tear_down() {
$this->reset_collections();
}

class Tests_Fonts_WpFontLibrary_GetFontCollections extends WP_Font_Library_UnitTestCase {
public function test_should_get_an_empty_list() {
$font_collections = WP_Font_Library::get_font_collections();
$this->assertEmpty( $font_collections, 'Should return an empty array.' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
* @covers WP_Font_Library::get_fonts_dir
*/
class Tests_Fonts_WpFontLibrary_GetFontsDir extends WP_UnitTestCase {
class Tests_Fonts_WpFontLibrary_GetFontsDir extends WP_Font_Library_UnitTestCase {

public function test_get_fonts_dir() {
$this->assertStringEndsWith( '/wp-content/fonts', WP_Font_Library::get_fonts_dir() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
* @covers WP_Font_Family_Utils::get_expected_font_mime_types_per_php_version
*/
class Tests_Fonts_WpFontsFamilyUtils_GetMimeTypes extends WP_UnitTestCase {
class Tests_Fonts_WpFontsFamilyUtils_GetMimeTypes extends WP_Font_Library_UnitTestCase {

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
* @covers WP_Font_Library::register_font_collection
*/
class Tests_Fonts_WpFontLibrary_RegisterFontCollection extends WP_UnitTestCase {
class Tests_Fonts_WpFontLibrary_RegisterFontCollection extends WP_Font_Library_UnitTestCase {

public function test_should_register_font_collection() {
$config = array(
Expand Down Expand Up @@ -69,11 +69,11 @@ public function test_should_return_error_if_id_is_repeated() {
// Register first collection.
$collection1 = WP_Font_Library::register_font_collection( $config1 );
$this->assertInstanceOf( 'WP_Font_Collection', $collection1, 'A collection should be registered.' );

// Expects a _doing_it_wrong notice.
$this->setExpectedIncorrectUsage( 'WP_Font_Library::register_font_collection' );
// Try to register a second collection with same id.
$collection2 = WP_Font_Library::register_font_collection( $config2 );
$this->assertWPError( $collection2, 'Second collection with the same id should fail.' );
$this->assertInstanceOf( 'WP_Error', $collection2, 'Should return an instance of WP_Error.' );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
* @covers WP_Font_Library::set_upload_dir
*/
class Tests_Fonts_WpFontLibrary_SetUploadDir extends WP_UnitTestCase {
class Tests_Fonts_WpFontLibrary_SetUploadDir extends WP_Font_Library_UnitTestCase {

public function test_should_set_fonts_upload_dir() {
$defaults = array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,9 @@
*
* @covers WP_Font_Library::unregister_font_collection
*/
class Tests_Fonts_WpFontLibrary_UnregisterFontCollection extends WP_UnitTestCase {

public function set_up() {
// Resets the private static property WP_Font_Library::$collections to empty array.
$reflection = new ReflectionClass( 'WP_Font_Library' );
$property = $reflection->getProperty( 'collections' );
$property->setAccessible( true );
$property->setValue( array() );
class Tests_Fonts_WpFontLibrary_UnregisterFontCollection extends WP_Font_Library_UnitTestCase {

public function test_should_unregister_font_collection() {
// Registers two mock font collections.
$config = array(
'id' => 'mock-font-collection-1',
Expand All @@ -35,9 +29,7 @@ public function set_up() {
'src' => 'my-mock-data.json',
);
WP_Font_Library::register_font_collection( $config );
}

public function test_should_unregister_font_collection() {
// Unregister mock font collection.
WP_Font_Library::unregister_font_collection( 'mock-font-collection-1' );
$collections = WP_Font_Library::get_font_collections();
Expand Down