Skip to content

Commit

Permalink
Standardize on - separated lowercase IDs
Browse files Browse the repository at this point in the history
All of the generated classnames and IDs should be consistent. This is
not compatible with previous versions of CakePHP, but has the benefit of
allowing a single convention to be remembered. This convention is also
shared by most CSS frameworks as well.

At some point in the future generating IDs might be pulled out into
a separate method that can be overridden.
  • Loading branch information
markstory committed Jan 15, 2014
1 parent 500562d commit f14aa83
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/View/Input/Radio.php
Expand Up @@ -134,7 +134,7 @@ protected function _renderInput($val, $text, $data) {
$radio['name'] = $data['name'];

if (empty($radio['id'])) {
$radio['id'] = Inflector::slug($radio['name'] . '_' . $radio['value']);
$radio['id'] = mb_strtolower(Inflector::slug($radio['name'] . '_' . $radio['value'], '-'));
}

if (isset($data['val']) && strval($data['val']) === strval($radio['value'])) {
Expand Down
68 changes: 34 additions & 34 deletions tests/TestCase/View/Input/RadioTest.php
Expand Up @@ -52,18 +52,18 @@ public function testRenderSimple() {
'type' => 'radio',
'name' => 'Crayons[color]',
'value' => 'r',
'id' => 'Crayons_color_r'
'id' => 'crayons-color-r'
]],
['label' => ['for' => 'Crayons_color_r']],
['label' => ['for' => 'crayons-color-r']],
'Red',
'/label',
['input' => [
'type' => 'radio',
'name' => 'Crayons[color]',
'value' => 'b',
'id' => 'Crayons_color_b'
'id' => 'crayons-color-b'
]],
['label' => ['for' => 'Crayons_color_b']],
['label' => ['for' => 'crayons-color-b']],
'Black',
'/label',
];
Expand Down Expand Up @@ -134,18 +134,18 @@ public function testRenderEmptyOption() {
'type' => 'radio',
'name' => 'Crayons[color]',
'value' => '',
'id' => 'Crayons_color'
'id' => 'crayons-color'
]],
['label' => ['for' => 'Crayons_color']],
['label' => ['for' => 'crayons-color']],
'empty',
'/label',
['input' => [
'type' => 'radio',
'name' => 'Crayons[color]',
'value' => 'r',
'id' => 'Crayons_color_r'
'id' => 'crayons-color-r'
]],
['label' => ['for' => 'Crayons_color_r']],
['label' => ['for' => 'crayons-color-r']],
'Red',
'/label',
];
Expand All @@ -158,18 +158,18 @@ public function testRenderEmptyOption() {
'type' => 'radio',
'name' => 'Crayons[color]',
'value' => '',
'id' => 'Crayons_color'
'id' => 'crayons-color'
]],
['label' => ['for' => 'Crayons_color']],
['label' => ['for' => 'crayons-color']],
'Choose one',
'/label',
['input' => [
'type' => 'radio',
'name' => 'Crayons[color]',
'value' => 'r',
'id' => 'Crayons_color_r'
'id' => 'crayons-color-r'
]],
['label' => ['for' => 'Crayons_color_r']],
['label' => ['for' => 'crayons-color-r']],
'Red',
'/label',
];
Expand All @@ -193,12 +193,12 @@ public function testRenderInputInsideLabel() {
];
$result = $radio->render($data);
$expected = [
['label' => ['for' => 'Crayons_color_r']],
['label' => ['for' => 'crayons-color-r']],
['input' => [
'type' => 'radio',
'name' => 'Crayons[color]',
'value' => 'r',
'id' => 'Crayons_color_r'
'id' => 'crayons-color-r'
]],
'Red',
'/label',
Expand All @@ -225,31 +225,31 @@ public function testRenderSelected() {
$result = $radio->render($data);
$expected = [
['input' => [
'id' => 'Versions_ver_1',
'id' => 'versions-ver-1',
'name' => 'Versions[ver]',
'type' => 'radio',
'value' => '1',
'checked' => 'checked'
]],
['label' => ['for' => 'Versions_ver_1']],
['label' => ['for' => 'versions-ver-1']],
'one',
'/label',
['input' => [
'id' => 'Versions_ver_1x',
'id' => 'versions-ver-1x',
'name' => 'Versions[ver]',
'type' => 'radio',
'value' => '1x'
]],
['label' => ['for' => 'Versions_ver_1x']],
['label' => ['for' => 'versions-ver-1x']],
'one x',
'/label',
['input' => [
'id' => 'Versions_ver_2',
'id' => 'versions-ver-2',
'name' => 'Versions[ver]',
'type' => 'radio',
'value' => '2'
]],
['label' => ['for' => 'Versions_ver_2']],
['label' => ['for' => 'versions-ver-2']],
'two',
'/label',
];
Expand All @@ -275,23 +275,23 @@ public function testRenderDisabled() {
$result = $radio->render($data);
$expected = [
['input' => [
'id' => 'Versions_ver_1',
'id' => 'versions-ver-1',
'name' => 'Versions[ver]',
'type' => 'radio',
'value' => '1',
'disabled' => 'disabled'
]],
['label' => ['for' => 'Versions_ver_1']],
['label' => ['for' => 'versions-ver-1']],
'one',
'/label',
['input' => [
'id' => 'Versions_ver_1x',
'id' => 'versions-ver-1x',
'name' => 'Versions[ver]',
'type' => 'radio',
'value' => '1x',
'disabled' => 'disabled'
]],
['label' => ['for' => 'Versions_ver_1x']],
['label' => ['for' => 'versions-ver-1x']],
'one x',
'/label',
];
Expand All @@ -301,22 +301,22 @@ public function testRenderDisabled() {
$result = $radio->render($data);
$expected = [
['input' => [
'id' => 'Versions_ver_1',
'id' => 'versions-ver-1',
'name' => 'Versions[ver]',
'type' => 'radio',
'value' => '1',
'disabled' => 'disabled'
]],
['label' => ['for' => 'Versions_ver_1']],
['label' => ['for' => 'versions-ver-1']],
'one',
'/label',
['input' => [
'id' => 'Versions_ver_1x',
'id' => 'versions-ver-1x',
'name' => 'Versions[ver]',
'type' => 'radio',
'value' => '1x',
]],
['label' => ['for' => 'Versions_ver_1x']],
['label' => ['for' => 'versions-ver-1x']],
'one x',
'/label',
];
Expand All @@ -342,13 +342,13 @@ public function testRenderLabelOptions() {
$result = $radio->render($data);
$expected = [
['input' => [
'id' => 'Versions_ver_1',
'id' => 'versions-ver-1',
'name' => 'Versions[ver]',
'type' => 'radio',
'value' => '1',
]],
['input' => [
'id' => 'Versions_ver_1x',
'id' => 'versions-ver-1x',
'name' => 'Versions[ver]',
'type' => 'radio',
'value' => '1x',
Expand All @@ -370,21 +370,21 @@ public function testRenderLabelOptions() {
$result = $radio->render($data);
$expected = [
['input' => [
'id' => 'Versions_ver_1',
'id' => 'versions-ver-1',
'name' => 'Versions[ver]',
'type' => 'radio',
'value' => '1',
]],
['label' => ['class' => 'my-class', 'for' => 'Versions_ver_1']],
['label' => ['class' => 'my-class', 'for' => 'versions-ver-1']],
'one',
'/label',
['input' => [
'id' => 'Versions_ver_1x',
'id' => 'versions-ver-1x',
'name' => 'Versions[ver]',
'type' => 'radio',
'value' => '1x',
]],
['label' => ['class' => 'my-class', 'for' => 'Versions_ver_1x']],
['label' => ['class' => 'my-class', 'for' => 'versions-ver-1x']],
'one x',
'/label',
];
Expand Down

0 comments on commit f14aa83

Please sign in to comment.