-
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.
Font Library: fix fonts not displaying correctly (#55393)
* Add kebab casing and font family wrapping in sanitization function. Remove commented code. * Simplify how kebab casing and quote wrapping is done. * Ensure incoming font is returned. * Add kebab casing to slug in form data. * Add tests for wpKebabCase * remove redundant test * test 2 different inputs on first wpKebabCase case * Move formatting functions to utils. * reduce the scope of the function * fix the live preview (without reloading the page) of the just installed fonts in the editor * format php * Add test for format_font_family. * Format php. * Add more test cases and format. * Remove accidental badKey. * Format. --------- Co-authored-by: Vicente Canales <[email protected]> Co-authored-by: Sarah Norris <[email protected]> Co-authored-by: Sarah Norris <[email protected]> Co-authored-by: Matias Benedetto <[email protected]>
- Loading branch information
1 parent
6f62e38
commit 500c9e4
Showing
7 changed files
with
191 additions
and
26 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
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
28 changes: 28 additions & 0 deletions
28
.../edit-site/src/components/global-styles/font-library-modal/utils/test/wpKebabCase.spec.js
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,28 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { wpKebabCase } from '../index'; | ||
|
||
describe( 'wpKebabCase', () => { | ||
it( 'should insert a dash between a letter and a digit', () => { | ||
const input = 'abc1def'; | ||
const expectedOutput = 'abc-1def'; | ||
expect( wpKebabCase( input ) ).toEqual( expectedOutput ); | ||
|
||
const input2 = 'abc1def2ghi'; | ||
const expectedOutput2 = 'abc-1def-2ghi'; | ||
expect( wpKebabCase( input2 ) ).toEqual( expectedOutput2 ); | ||
} ); | ||
|
||
it( 'should not insert a dash between two letters', () => { | ||
const input = 'abcdef'; | ||
const expectedOutput = 'abcdef'; | ||
expect( wpKebabCase( input ) ).toEqual( expectedOutput ); | ||
} ); | ||
|
||
it( 'should not insert a dash between a digit and a hyphen', () => { | ||
const input = 'abc1-def'; | ||
const expectedOutput = 'abc-1-def'; | ||
expect( wpKebabCase( input ) ).toEqual( expectedOutput ); | ||
} ); | ||
} ); |
59 changes: 59 additions & 0 deletions
59
phpunit/tests/fonts/font-library/wpFontFamilyUtils/formatFontFamily.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,59 @@ | ||
<?php | ||
/** | ||
* Test WP_Font_Family_Utils::format_font_family(). | ||
* | ||
* @package WordPress | ||
* @subpackage Font Library | ||
* | ||
* @group fonts | ||
* @group font-library | ||
* | ||
* @covers WP_Font_Family_Utils::format_font_family | ||
*/ | ||
class Tests_Fonts_WpFontsFamilyUtils_FormatFontFamily extends WP_UnitTestCase { | ||
|
||
/** | ||
* @dataProvider data_should_format_font_family | ||
* | ||
* @param string $font_family Font family. | ||
* @param string $expected Expected family. | ||
*/ | ||
public function test_should_format_font_family( $font_family, $expected ) { | ||
$this->assertSame( | ||
$expected, | ||
WP_Font_Family_Utils::format_font_family( | ||
$font_family | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* Data provider. | ||
* | ||
* @return array[] | ||
*/ | ||
public function data_should_format_font_family() { | ||
return array( | ||
'data_families_with_spaces_and_numbers' => array( | ||
'font_family' => 'Rock 3D , Open Sans,serif', | ||
'expected' => "'Rock 3D', 'Open Sans', serif", | ||
), | ||
'data_single_font_family' => array( | ||
'font_family' => 'Rock 3D', | ||
'expected' => "'Rock 3D'", | ||
), | ||
'data_no_spaces' => array( | ||
'font_family' => 'Rock3D', | ||
'expected' => 'Rock3D', | ||
), | ||
'data_many_spaces_and_existing_quotes' => array( | ||
'font_family' => 'Rock 3D serif, serif,sans-serif, "Open Sans"', | ||
'expected' => "'Rock 3D serif', serif, sans-serif, \"Open Sans\"", | ||
), | ||
'data_empty_family' => array( | ||
'font_family' => ' ', | ||
'expected' => '', | ||
), | ||
); | ||
} | ||
} |