-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Font Library: unregister font collection (#54701)
* remove font collection * add wp_unregister_font_collection function * format php * fix function comment * add tests for unregister_font_collection * removig unused variable * update wording on comments Co-authored-by: Colin Stewart <79332690+costdev@users.noreply.github.com> * keep track of unregistered font collection ids in an array * add tests to assure that get_font_collections returns an empty array if all the font collections were unregistered * fix tests * test the initial empty value of the font library collections * format * simplify unregistering of font collections and add _doing_it_wrong call * add translation domain * adding _doing_it_wrong if you are registering collections with the same id or unregistering a non existing collection id * updating tests * replace 6.4.0 by 6.5.0 in comments Co-authored-by: Vicente Canales <1157901+vcanales@users.noreply.github.com> * update version Co-authored-by: Grant Kinney <creativecoder@users.noreply.github.com> * consolidate code as only one function to avoid code repetition * create base test case * format php * assertWPError * check that collection was not unregistered by mistake * calling parent test class mehtods * format php --------- Co-authored-by: Colin Stewart <79332690+costdev@users.noreply.github.com> Co-authored-by: Vicente Canales <1157901+vcanales@users.noreply.github.com> Co-authored-by: Grant Kinney <creativecoder@users.noreply.github.com>
- Loading branch information
1 parent
80f8d9e
commit 302c148
Showing
10 changed files
with
156 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?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() { | ||
parent::set_up(); | ||
$this->reset_font_collections(); | ||
} | ||
|
||
public function tear_down() { | ||
parent::tear_down(); | ||
$this->reset_font_collections(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
phpunit/tests/fonts/font-library/wpFontLibrary/unregisterFontCollection.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
/** | ||
* Test WP_Font_Library::unregister_font_collection(). | ||
* | ||
* @package WordPress | ||
* @subpackage Font Library | ||
* | ||
* @group fonts | ||
* @group font-library | ||
* | ||
* @covers WP_Font_Library::unregister_font_collection | ||
*/ | ||
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', | ||
'name' => 'Mock Collection to be unregistered', | ||
'description' => 'A mock font collection to be unregistered.', | ||
'src' => 'my-collection-data.json', | ||
); | ||
WP_Font_Library::register_font_collection( $config ); | ||
|
||
$config = array( | ||
'id' => 'mock-font-collection-2', | ||
'name' => 'Mock Collection', | ||
'description' => 'A mock font collection.', | ||
'src' => 'my-mock-data.json', | ||
); | ||
WP_Font_Library::register_font_collection( $config ); | ||
|
||
// Unregister mock font collection. | ||
WP_Font_Library::unregister_font_collection( 'mock-font-collection-1' ); | ||
$collections = WP_Font_Library::get_font_collections(); | ||
$this->assertArrayNotHasKey( 'mock-font-collection-1', $collections, 'Font collection was not unregistered.' ); | ||
$this->assertArrayHasKey( 'mock-font-collection-2', $collections, 'Font collection was unregistered by mistake.' ); | ||
|
||
// Unregisters remaining mock font collection. | ||
WP_Font_Library::unregister_font_collection( 'mock-font-collection-2' ); | ||
$collections = WP_Font_Library::get_font_collections(); | ||
$this->assertArrayNotHasKey( 'mock-font-collection-2', $collections, 'Mock font collection was not unregistered.' ); | ||
|
||
// Checks that all font collections were unregistered. | ||
$this->assertEmpty( $collections, 'Font collections were not unregistered.' ); | ||
} | ||
|
||
public function unregister_non_existing_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.' ); | ||
} | ||
} |