From 8a91dd8b6b56f2088e693529e30e0cd0053ed3aa Mon Sep 17 00:00:00 2001 From: mik-laj Date: Tue, 26 Jul 2016 18:11:09 +0200 Subject: [PATCH 1/2] Accessibility icons --- src/View/Helper/BootstrapHtmlHelper.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/View/Helper/BootstrapHtmlHelper.php b/src/View/Helper/BootstrapHtmlHelper.php index 5d29241..8662894 100644 --- a/src/View/Helper/BootstrapHtmlHelper.php +++ b/src/View/Helper/BootstrapHtmlHelper.php @@ -86,6 +86,7 @@ public function icon ($icon, $options = []) { public function faIcon ($icon, $options = []) { $options = $this->addClass($options, 'fa'); $options = $this->addClass($options, 'fa-'.$icon); + $options['aria-hidden'] = 'true'; return $this->tag('i', '', $options); } @@ -98,6 +99,7 @@ public function faIcon ($icon, $options = []) { public function glIcon ($icon, $options = []) { $options = $this->addClass($options, 'glyphicon'); $options = $this->addClass($options, 'glyphicon-'.$icon); + $options['aria-hidden'] = 'true'; return $this->tag('i', '', $options); } From 2d8ad33a60442386c339c1a520feaa5a8b49d9f2 Mon Sep 17 00:00:00 2001 From: mik-laj Date: Thu, 28 Jul 2016 12:33:43 +0200 Subject: [PATCH 2/2] Fix test for aria-hidden in icon --- src/View/Helper/BootstrapHtmlHelper.php | 8 +++++-- .../View/Helper/BootstrapHtmlHelperTest.php | 14 +++++++----- .../Helper/BootstrapPaginatorHelperTest.php | 6 +++-- .../View/Helper/BootstrapPanelHelperTest.php | 6 +++-- .../View/Helper/BootstrapTraitTest.php | 22 ++++++++++++++----- 5 files changed, 39 insertions(+), 17 deletions(-) diff --git a/src/View/Helper/BootstrapHtmlHelper.php b/src/View/Helper/BootstrapHtmlHelper.php index 8662894..8c542a9 100644 --- a/src/View/Helper/BootstrapHtmlHelper.php +++ b/src/View/Helper/BootstrapHtmlHelper.php @@ -86,7 +86,9 @@ public function icon ($icon, $options = []) { public function faIcon ($icon, $options = []) { $options = $this->addClass($options, 'fa'); $options = $this->addClass($options, 'fa-'.$icon); - $options['aria-hidden'] = 'true'; + $options += [ + 'aria-hidden' => 'true' + ]; return $this->tag('i', '', $options); } @@ -99,7 +101,9 @@ public function faIcon ($icon, $options = []) { public function glIcon ($icon, $options = []) { $options = $this->addClass($options, 'glyphicon'); $options = $this->addClass($options, 'glyphicon-'.$icon); - $options['aria-hidden'] = 'true'; + $options += [ + 'aria-hidden' => 'true' + ]; return $this->tag('i', '', $options); } diff --git a/tests/TestCase/View/Helper/BootstrapHtmlHelperTest.php b/tests/TestCase/View/Helper/BootstrapHtmlHelperTest.php index 1cad192..6618827 100644 --- a/tests/TestCase/View/Helper/BootstrapHtmlHelperTest.php +++ b/tests/TestCase/View/Helper/BootstrapHtmlHelperTest.php @@ -55,31 +55,35 @@ public function testIcon () { // Default icon (Glyphicon) $this->assertHtml ([ ['i' => [ - 'class' => 'glyphicon glyphicon-'.$type + 'class' => 'glyphicon glyphicon-'.$type, + 'aria-hidden' => 'true' ]], '/i' ], $this->Html->icon($type)); $this->assertHtml ([ ['i' => [ 'class' => $options['class'].' glyphicon glyphicon-'.$type, - 'id' => $options['id'] + 'id' => $options['id'], + 'aria-hidden' => 'true' ]], '/i' ], $this->Html->icon($type, $options)); // FontAwesome icon $this->assertHtml ([ ['i' => [ - 'class' => 'fa fa-'.$type + 'class' => 'fa fa-'.$type, + 'aria-hidden' => 'true' ]], '/i' ], $this->Html->faIcon($type)); $this->assertHtml ([ ['i' => [ 'class' => $options['class'].' fa fa-'.$type, - 'id' => $options['id'] + 'id' => $options['id'], + 'aria-hidden' => 'true' ]], '/i' - ], $this->Html->faIcon($type, $options)); + ], $this->Html->faIcon($type, $options)); } public function testLabel () { diff --git a/tests/TestCase/View/Helper/BootstrapPaginatorHelperTest.php b/tests/TestCase/View/Helper/BootstrapPaginatorHelperTest.php index caf507e..8c925b5 100644 --- a/tests/TestCase/View/Helper/BootstrapPaginatorHelperTest.php +++ b/tests/TestCase/View/Helper/BootstrapPaginatorHelperTest.php @@ -59,7 +59,8 @@ public function testPrev () { ]], ['a' => true], ['i' => [ - 'class' => 'glyphicon glyphicon-chevron-left' + 'class' => 'glyphicon glyphicon-chevron-left', + 'aria-hidden' => 'true' ]], '/i', '/a', '/li' ], $this->Paginator->prev('i:chevron-left')); @@ -79,7 +80,8 @@ public function testNext () { 'href' => '/index?page=2' ]], ['i' => [ - 'class' => 'glyphicon glyphicon-chevron-right' + 'class' => 'glyphicon glyphicon-chevron-right', + 'aria-hidden' => 'true' ]], '/i', '/a', '/li' ], $this->Paginator->next('i:chevron-right')); diff --git a/tests/TestCase/View/Helper/BootstrapPanelHelperTest.php b/tests/TestCase/View/Helper/BootstrapPanelHelperTest.php index f04ec6b..b1b98b1 100644 --- a/tests/TestCase/View/Helper/BootstrapPanelHelperTest.php +++ b/tests/TestCase/View/Helper/BootstrapPanelHelperTest.php @@ -136,7 +136,8 @@ public function testHeader () { 'class' => 'panel-title' ]], ['i' => [ - 'class' => 'glyphicon glyphicon-home' + 'class' => 'glyphicon glyphicon-home', + 'aria-hidden' => 'true' ]], '/i', ' Home', '/h4', '/div' @@ -215,7 +216,8 @@ public function testHeader () { 'aria-controls' => '#collapse-2' ]], ['i' => [ - 'class' => 'glyphicon glyphicon-home' + 'class' => 'glyphicon glyphicon-home', + 'aria-hidden' => 'true' ]], '/i', ' Home', '/a', '/h4', diff --git a/tests/TestCase/View/Helper/BootstrapTraitTest.php b/tests/TestCase/View/Helper/BootstrapTraitTest.php index 8c29980..56896d3 100644 --- a/tests/TestCase/View/Helper/BootstrapTraitTest.php +++ b/tests/TestCase/View/Helper/BootstrapTraitTest.php @@ -82,7 +82,8 @@ public function testEasyIcon() { 'expected' => [ 'escape' => false, 'result' => [['i' => [ - 'class' => 'glyphicon glyphicon-plus' + 'class' => 'glyphicon glyphicon-plus', + 'aria-hidden' => 'true' ]], '/i'] ] ]); @@ -98,7 +99,8 @@ public function testEasyIcon() { 'expected' => [ 'escape' => false, 'result' => [['i' => [ - 'class' => 'glyphicon glyphicon-plus' + 'class' => 'glyphicon glyphicon-plus', + 'aria-hidden' => 'true' ]], '/i', ' Add'] ] ]); @@ -107,7 +109,8 @@ public function testEasyIcon() { 'expected' => [ 'escape' => false, 'result' => ['Add ', ['i' => [ - 'class' => 'glyphicon glyphicon-plus' + 'class' => 'glyphicon glyphicon-plus', + 'aria-hidden' => 'true' ]], '/i'] ] ]); @@ -136,7 +139,8 @@ public function testHelperMethods() { 'class' => 'btn btn-default', 'type' => 'submit' ]], ['i' => [ - 'class' => 'glyphicon glyphicon-plus' + 'class' => 'glyphicon glyphicon-plus', + 'aria-hidden' => 'true' ]], '/i', '/button' ], $result) ; $result = $this->Form->input ('fieldname', [ @@ -154,7 +158,10 @@ public function testHelperMethods() { ['span' => [ 'class' => 'input-group-addon' ]], - ['i' => ['class' => 'glyphicon glyphicon-home']], '/i', + ['i' => [ + 'class' => 'glyphicon glyphicon-home', + 'aria-hidden' => 'true' + ]], '/i', '/span', ['input' => [ 'type' => 'text', @@ -165,7 +172,10 @@ public function testHelperMethods() { ['span' => [ 'class' => 'input-group-addon' ]], - ['i' => ['class' => 'glyphicon glyphicon-plus']], '/i', + ['i' => [ + 'class' => 'glyphicon glyphicon-plus', + 'aria-hidden' => 'true' + ]], '/i', '/span', '/div', '/div'