Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

アイコンのアクセシビリティ対応 #1059

Merged
merged 13 commits into from
Feb 28, 2024
25 changes: 25 additions & 0 deletions inc/icon-accessibility/class-icon-accessibility.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

class VEU_Icon_Accessibility {
/**
* Font Awesome アイコンに aria-hidden="true" を付与する
*
* @param string $content 変換前のコンテンツ文字列
* @return string 変換後のコンテンツ文字列
*/
public static function add_aria_hidden_to_fontawesome($content) {
$pattern = '/<i ([^>]*class=["\'][^"\']*fa[^"\']*["\'][^>]*)>/i';

$content = preg_replace_callback($pattern, function($matches) {
$tag_content = $matches[1];

if (strpos($tag_content, 'aria-hidden') !== false) {
return '<i ' . $tag_content . '>';
} else {
return '<i ' . $tag_content . ' aria-hidden="true">';
}
}, $content);

return $content;
}
}
6 changes: 6 additions & 0 deletions inc/icon-accessibility/icon-accessibility.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

require_once 'class-icon-accessibility.php';

add_filter('the_content', array( 'VEU_Icon_Accessibility', 'add_aria_hidden_to_fontawesome' ));
add_filter('render_block', array( 'VEU_Icon_Accessibility', 'add_aria_hidden_to_fontawesome' ), 10, 2);
3 changes: 2 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ e.g.

== Changelog ==

[ Other ][ PostTypeManager ] Add Rewrite option of Post Type / Taxonomy.
[ Add function ][ Icon Accessability ] Font Awesome Icon A11y Hide.
[ Other ][ PostType Manager ] Add Rewrite option of Post Type / Taxonomy.
[ Bug Fix ][ Page content to widget ] Fixed an issue where a warning occurs when the target page is deleted.

= 9.94.2 =
Expand Down
16 changes: 11 additions & 5 deletions tests/test-get-common-options-default.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function test_veu_get_common_options_default() {
array(
'is_block_theme' => true,
'correct' => array(

'active_fontawesome' => false,
'active_wpTitle' => true,
'active_addReusableBlockMenu' => true,
Expand Down Expand Up @@ -61,6 +62,7 @@ function test_veu_get_common_options_default() {
'active_Contactform7AssetOptimize' => false,
'active_article_structure_data' => true,
'active_website_structure_data' => true,
'active_icon_accessibility' => true,
'active_page_exclude_from_list_pages' => true,
'post_metabox_individual' => false,
'delete_options_at_deactivate' => false,
Expand Down Expand Up @@ -107,12 +109,15 @@ function test_veu_get_common_options_default() {
'active_Contactform7AssetOptimize' => false,
'active_article_structure_data' => true,
'active_website_structure_data' => true,
'active_icon_accessibility' => true,
'active_page_exclude_from_list_pages' => true,
'post_metabox_individual' => false,
'delete_options_at_deactivate' => false,
'content_filter_state' => 'content',
),
),

),

),
);

Expand All @@ -121,14 +126,15 @@ function test_veu_get_common_options_default() {
$return = veu_get_common_options_default( $test_value['is_block_theme'] );
$correct = $test_value['correct'];

// 取得できたHTMLが、意図したHTMLと等しいかテスト
$this->assertEquals( $correct, $return );

print PHP_EOL;
print 'correct :' . PHP_EOL;
var_dump( $correct );
print 'return :' . PHP_EOL;
var_dump( $return );
var_dump( $return );

// 取得できたHTMLが、意図したHTMLと等しいかテスト
$this->assertEquals( $correct, $return );

}
}
}
72 changes: 72 additions & 0 deletions tests/test-icon-accessibility.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
/**
* SnsBtnsStyle
*
* @package Vk_All_In_One_Expansion_Unit
*/

require_once VEU_DIRECTORY_PATH . '/inc/icon-accessibility/icon-accessibility.php';

/**
* Share button test
*/
class IconAccessibilityTest extends WP_UnitTestCase {

public function set_up() {
parent::set_up();
}

/**
* シェアボタンの色
*
* @return void
*/
public function test_add_aria_hidden_to_fontawesome() {


print PHP_EOL;
print '------------------------------------' . PHP_EOL;
print 'test_add_aria_hidden_to_fontawesome' . PHP_EOL;
print '------------------------------------' . PHP_EOL;

$test_cases = array(
array(
'content' => '<div><i class="fa fa-home"></i></div>',
'correct' => '<div><i class="fa fa-home" aria-hidden="true"></i></div>'
),
array(
'content' => '<p>Text <i class="fa fa-envelope"></i> more text.</p>',
'correct' => '<p>Text <i class="fa fa-envelope" aria-hidden="true"></i> more text.</p>'
),
array(
'content' => '<div><i class="fa fa-car" aria-hidden="true"></i></div>',
'correct' => '<div><i class="fa fa-car" aria-hidden="true"></i></div>'
),
array(
'content' => '<ul><li><i class="fa fa-check"></i> Item 1</li><li><i class="fa fa-check"></i> Item 2</li></ul>',
'correct' => '<ul><li><i class="fa fa-check" aria-hidden="true"></i> Item 1</li><li><i class="fa fa-check" aria-hidden="true"></i> Item 2</li></ul>'
),
array(
'content' => '<footer><i class="fa fa-twitter"></i> Follow us!</footer>',
'correct' => '<footer><i class="fa fa-twitter" aria-hidden="true"></i> Follow us!</footer>'
),
array(
'content' => '<footer><i aria-hidden="false" class="fa fa-twitter"></i> Follow us!</footer>',
'correct' => '<footer><i aria-hidden="false" class="fa fa-twitter"></i> Follow us!</footer>'
),
);

foreach ( $test_cases as $key => $test_value ) {

$return = VEU_Icon_Accessibility::add_aria_hidden_to_fontawesome( $test_value['content'] );

$this->assertEquals( $test_value['correct'], $return );

print PHP_EOL;
print 'correct :' . $test_value['correct'] . PHP_EOL;
print 'return :' . $return . PHP_EOL;
}
}


}
13 changes: 13 additions & 0 deletions tests/test-promotion-alert.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
*/
class PromotionAlertTest extends WP_UnitTestCase {

public function set_up() {
parent::set_up();

// アイコンアクセサビリティのテストが影響するのでフィルターを外す
remove_filter('the_content', array( 'VEU_Icon_Accessibility', 'add_aria_hidden_to_fontawesome' ));
remove_filter('render_block', array( 'VEU_Icon_Accessibility', 'add_aria_hidden_to_fontawesome' ), 10);
}

/**
* テストデータ作成
*/
Expand Down Expand Up @@ -366,6 +374,8 @@ public function test_get_display_condition() {

public function test_get_alert_content() {



$data = self::setup_data();

$test_array = array(
Expand Down Expand Up @@ -464,6 +474,9 @@ public function test_get_alert_content() {

$this->go_to( get_permalink( $data['post_id_01'] ) );

$options = get_option( 'vkExUnit_common_options' );
var_dump($options['active_icon_accessibility']);

$return = VEU_Promotion_Alert::get_alert_content();
$correct = $test_value['correct'];

Expand Down
11 changes: 11 additions & 0 deletions veu-packages.php
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,17 @@ function veu_get_packages( $is_block_theme = null ) {
'include' => 'disable-emojis.php',
);

/*
icon_accessibility
/*-------------------------------------------*/
$required_packages[] = array(
'name' => 'icon_accessibility',
'title' => __( 'Font Awesome Icon A11y Hide', 'vk-all-in-one-expansion-unit' ),
'description' => __( 'Add aria-hidden="true" to Font Awesome icons to hide them from screen readers, improving accessibility', 'vk-all-in-one-expansion-unit' ),
'default' => true,
'include' => 'icon-accessibility/icon-accessibility.php',
);

$required_packages[] = array(
'name' => 'admin_bar',
'title' => __( 'Admin bar manu', 'vk-all-in-one-expansion-unit' ),
Expand Down
Loading