@@ -568,6 +568,35 @@ public function test_render_block_with_grid_layer_with_not_movable_block() {
568568 $ this ->assertEquals ( $ expected , $ filtered_block );
569569 }
570570
571+ /**
572+ * Test getting fonts.
573+ *
574+ * @covers AMP_Story_Post_Type::get_font
575+ * @covers AMP_Story_Post_Type::get_fonts
576+ */
577+ public function test_get_fonts () {
578+ $ fonts = AMP_Story_Post_Type::get_fonts ();
579+ $ this ->assertInternalType ( 'array ' , $ fonts );
580+
581+ $ arial_font = current (
582+ array_filter (
583+ $ fonts ,
584+ function ( $ font ) {
585+ return 'Arial ' === $ font ['name ' ];
586+ }
587+ )
588+ );
589+
590+ $ this ->assertEquals (
591+ [
592+ 'name ' => 'Arial ' ,
593+ 'fallbacks ' => [ 'Helvetica Neue ' , 'Helvetica ' , 'sans-serif ' ],
594+ 'slug ' => 'arial ' ,
595+ ],
596+ $ arial_font
597+ );
598+ }
599+
571600 /**
572601 * Test process google fonts.
573602 *
@@ -616,8 +645,8 @@ public function test_invalid_google_fonts_file() {
616645 * @covers AMP_Story_Post_Type::get_google_fonts
617646 * @dataProvider get_gfont_data
618647 *
619- * @param string $font Font name
620- * @param string $gfont gfont entry
648+ * @param string $font Font name.
649+ * @param string $gfont gfont entry.
621650 * @param string $fallbacks Font fallbacks.
622651 */
623652 public function test_google_fonts_entries ( $ font , $ gfont , $ fallbacks ) {
@@ -640,19 +669,19 @@ public function test_google_fonts_entries( $font, $gfont, $fallbacks ) {
640669 * @covers AMP_Story_Post_Type::get_font_fallback
641670 * @dataProvider get_font_fallback_data
642671 *
643- * @param string $expected
644- * @param string $category
672+ * @param string $expected Expected.
673+ * @param string $category Category.
645674 */
646- public function test_fallback_font ( $ expected , $ category ) {
675+ public function test_get_font_fallback ( $ expected , $ category ) {
647676 $ this ->assertEquals ( $ expected , AMP_Story_Post_Type::get_font_fallback ( $ category ) );
648677 }
649678
650679 /**
651680 * Helper to find key in array.
652681 *
653- * @param $data
654- * @param $key
655- * @param $value
682+ * @param array $data Data.
683+ * @param string $key Key.
684+ * @param mixed $value Value.
656685 *
657686 * @return false|int|string
658687 */
@@ -722,6 +751,64 @@ public function get_gfont_data() {
722751 ];
723752 }
724753
754+ /**
755+ * Get data for testing render_block_with_fonts.
756+ *
757+ * @return array Data.
758+ */
759+ public function get_render_block_with_fonts_test_data () {
760+ return [
761+ [
762+ 'Arial ' ,
763+ null ,
764+ ],
765+ [
766+ 'Aref Ruqaa ' ,
767+ 'aref-ruqaa-font ' ,
768+ ],
769+ ];
770+ }
771+
772+ /**
773+ * Test render_block_with_google_fonts.
774+ *
775+ * @param string $font_name Font Name.
776+ * @param string $enqueued_style Enqueued style.
777+ *
778+ * @dataProvider get_render_block_with_fonts_test_data
779+ * @covers AMP_Story_Post_Type::render_block_with_google_fonts
780+ */
781+ public function test_render_block_with_google_fonts ( $ font_name , $ enqueued_style ) {
782+ $ block_name = 'amp/amp-story-text ' ;
783+
784+ $ system_block_attrs = [ 'ampFontFamily ' => $ font_name ];
785+ $ system_text_block = sprintf (
786+ '<!-- wp:%1$s %2$s --><h1 data-font-family="%3$s">Text</h1><!-- /wp:%1$s --> ' ,
787+ $ block_name ,
788+ wp_json_encode ( $ system_block_attrs ),
789+ $ font_name
790+ );
791+ $ filtered_block = AMP_Story_Post_Type::render_block_with_google_fonts (
792+ $ system_text_block ,
793+ [
794+ 'name ' => $ block_name ,
795+ 'attrs ' => $ system_block_attrs ,
796+ ]
797+ );
798+ $ this ->assertStringStartsWith (
799+ sprintf ( '<style data-font-family="%1$s">[data-font-family="%1$s"] ' , $ font_name ),
800+ $ filtered_block
801+ );
802+ if ( $ enqueued_style ) {
803+ $ this ->assertTrue ( wp_style_is ( $ enqueued_style , 'enqueued ' ) );
804+ }
805+ }
806+
807+ /**
808+ * Get default settings definitions.
809+ *
810+ * @return array
811+ */
725812 public function get_default_settings_definitions () {
726813 return [
727814 [
0 commit comments