-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wp_get_webfont_providers() plus tests
- Loading branch information
1 parent
0740239
commit 549908c
Showing
5 changed files
with
188 additions
and
12 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
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,72 @@ | ||
<?php | ||
/** | ||
* Unit and integration tests for wp_get_webfont_providers(). | ||
* | ||
* @package WordPress | ||
* @subpackage Webfonts | ||
*/ | ||
|
||
require_once __DIR__ . '/wp-webfonts-testcase.php'; | ||
require_once __DIR__ . '/../fixtures/mock-provider.php'; | ||
|
||
/** | ||
* @group webfonts | ||
* @covers ::wp_get_webfont_providers | ||
*/ | ||
class Tests_Webfonts_WpGetWebfontProviders extends WP_Webfonts_TestCase { | ||
private $providers_property; | ||
|
||
public function set_up() { | ||
parent::set_up(); | ||
$this->providers_property = new ReflectionProperty( WP_Webfonts::class, 'providers' ); | ||
$this->providers_property->setAccessible( true ); | ||
} | ||
|
||
/** | ||
* Unit test. | ||
* | ||
* @dataProvider data_get_providers | ||
* | ||
* @param array $providers Not used. | ||
* @param array $expected Expected results. | ||
*/ | ||
public function test_should_return_mocked_providers( array $providers, array $expected ) { | ||
$mock = $this->set_up_mock( 'get_providers' ); | ||
$mock->expects( $this->once() ) | ||
->method( 'get_providers' ) | ||
->will( $this->returnValue( $expected ) ); | ||
|
||
$this->assertSame( $expected, wp_get_webfont_providers() ); | ||
} | ||
|
||
/** | ||
* Integration test that sets the `WP_Webfonts::providers` property. | ||
* | ||
* @dataProvider data_get_providers | ||
* | ||
* @param array $providers Array of providers to test. | ||
* @param array $expected Expected results. | ||
*/ | ||
public function test_should_return_providers( array $providers, array $expected ) { | ||
$this->setup_providers( $providers ); | ||
$this->assertSame( $expected, wp_get_webfont_providers() ); | ||
} | ||
|
||
/** | ||
* Sets up the given providers and stores them in the `WP_Webfonts::providers` property. | ||
* | ||
* @param array $providers Array of providers to set up. | ||
*/ | ||
private function setup_providers( array $providers ) { | ||
$data = array(); | ||
|
||
foreach ( $providers as $provider_id => $class ) { | ||
$data[ $provider_id ] = array( | ||
'class' => $class, | ||
'fonts' => array(), | ||
); | ||
} | ||
|
||
$this->providers_property->setValue( wp_webfonts(), $data ); | ||
} | ||
} |
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,62 @@ | ||
<?php | ||
/** | ||
* WP_Webfonts::get_providers() tests. | ||
* | ||
* @package WordPress | ||
* @subpackage Webfonts | ||
*/ | ||
|
||
require_once __DIR__ . '/../wp-webfonts-testcase.php'; | ||
require_once __DIR__ . '/../../fixtures/mock-provider.php'; | ||
|
||
/** | ||
* @group webfonts | ||
* @covers WP_Webfonts::get_providers | ||
*/ | ||
class Tests_Webfonts_WpWebfonts_GetProviders extends WP_Webfonts_TestCase { | ||
private $wp_webfonts; | ||
private $providers_property; | ||
|
||
public function set_up() { | ||
parent::set_up(); | ||
$this->wp_webfonts = new WP_Webfonts(); | ||
|
||
$this->providers_property = new ReflectionProperty( WP_Webfonts::class, 'providers' ); | ||
$this->providers_property->setAccessible( true ); | ||
} | ||
|
||
public function test_should_be_empty() { | ||
$actual = $this->wp_webfonts->get_providers(); | ||
$this->assertIsArray( $actual, 'Should return an empty array' ); | ||
$this->assertEmpty( $actual, 'Should return an empty array when no providers are registered' ); | ||
} | ||
|
||
/** | ||
* @dataProvider data_get_providers | ||
* | ||
* @param array $providers Array of providers to test. | ||
* @param array $expected Expected results. | ||
*/ | ||
public function test_get_providers( array $providers, array $expected ) { | ||
$this->setup_providers( $providers ); | ||
$this->assertSame( $expected, $this->wp_webfonts->get_providers() ); | ||
} | ||
|
||
/** | ||
* Sets up the given providers and stores them in the `WP_Webfonts::providers` property. | ||
* | ||
* @param array $providers Array of providers to set up. | ||
*/ | ||
private function setup_providers( array $providers ) { | ||
$data = array(); | ||
|
||
foreach ( $providers as $provider_id => $class ) { | ||
$data[ $provider_id ] = array( | ||
'class' => $class, | ||
'fonts' => array(), | ||
); | ||
} | ||
|
||
$this->providers_property->setValue( $this->wp_webfonts, $data ); | ||
} | ||
} |