Skip to content
Permalink
Browse files

Standardize on `-` separated lowercase IDs

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 f14aa83da0e94853114562411ecc7ca51d6d8897
Showing with 35 additions and 35 deletions.
  1. +1 −1 src/View/Input/Radio.php
  2. +34 −34 tests/TestCase/View/Input/RadioTest.php
@@ -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'])) {
@@ -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',
];
@@ -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',
];
@@ -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',
];
@@ -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',
@@ -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',
];
@@ -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',
];
@@ -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',
];
@@ -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',
@@ -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',
];

0 comments on commit f14aa83

Please sign in to comment.
You can’t perform that action at this time.