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
Fix #11132 - trim warning in Cake\View\Helper::addClass #11133
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having a test case for this case is needed. If you need help with that let me know and I can add a test.
src/View/Helper.php
Outdated
@@ -197,7 +197,9 @@ protected function _confirm($message, $okCode, $cancelCode = '', $options = []) | |||
*/ | |||
public function addClass(array $options = [], $class = null, $key = 'class') | |||
{ | |||
if (isset($options[$key]) && trim($options[$key])) { | |||
if (is_array($options[$key])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need an isset() here as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it was a quick patch - I'll have a look at writing a test.
Thank you for offering help - if I get stuck, I'll ask! :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
This looks like sth that might need a test case to prevent regressions in the future. |
src/View/Helper.php
Outdated
if (isset($options[$key]) && trim($options[$key])) { | ||
if (is_array($options[$key])) { | ||
$options[$key][] = $class; | ||
} else if (isset($options[$key]) && trim($options[$key])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
elseif
Fix coding style
Codecov Report
@@ Coverage Diff @@
## master #11133 +/- ##
============================================
+ Coverage 94.88% 94.9% +0.01%
- Complexity 12850 12854 +4
============================================
Files 437 437
Lines 32767 32771 +4
============================================
+ Hits 31092 31101 +9
+ Misses 1675 1670 -5
Continue to review full report at Codecov.
|
tests/TestCase/View/HelperTest.php
Outdated
public function testAddClassArray() | ||
{ | ||
$Helper = new TestHelper($this->View); | ||
$input = array('class' => [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use short array syntax everywhere please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed - thanks
Refs cakephp#11133
Refs cakephp#11133
Fixes #11132 .
Adds support for the
class
element of an$options
array to also be an array.