Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
7aeb2fcf
Commit
7aeb2fcf
authored
Aug 09, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed test breaks.
parent
20727c8c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
18 deletions
+46
-18
HtmlBase.php
framework/yii/helpers/HtmlBase.php
+8
-6
HtmlTest.php
tests/unit/framework/helpers/HtmlTest.php
+38
-12
No files found.
framework/yii/helpers/HtmlBase.php
View file @
7aeb2fcf
...
...
@@ -761,9 +761,10 @@ class HtmlBase
if
(
$formatter
!==
null
)
{
$lines
[]
=
call_user_func
(
$formatter
,
$index
,
$label
,
$name
,
$checked
,
$value
);
}
else
{
$checkbox
=
static
::
checkbox
(
$name
,
$checked
,
array
(
'value'
=>
$value
));
$content
=
static
::
label
(
$checkbox
.
' '
.
(
$encode
?
static
::
encode
(
$label
)
:
$label
));
$lines
[]
=
static
::
tag
(
'div'
,
$content
,
array
(
'class'
=>
'checkbox'
));
$lines
[]
=
static
::
checkbox
(
$name
,
$checked
,
array
(
'value'
=>
$value
,
'label'
=>
$encode
?
static
::
encode
(
$label
)
:
$label
,
));
}
$index
++
;
}
...
...
@@ -819,9 +820,10 @@ class HtmlBase
if
(
$formatter
!==
null
)
{
$lines
[]
=
call_user_func
(
$formatter
,
$index
,
$label
,
$name
,
$checked
,
$value
);
}
else
{
$radio
=
static
::
radio
(
$name
,
$checked
,
array
(
'value'
=>
$value
));
$content
=
static
::
label
(
$radio
.
' '
.
(
$encode
?
static
::
encode
(
$label
)
:
$label
));
$lines
[]
=
static
::
tag
(
'div'
,
$content
,
array
(
'class'
=>
'radio'
));
$lines
[]
=
static
::
radio
(
$name
,
$checked
,
array
(
'value'
=>
$value
,
'label'
=>
$encode
?
static
::
encode
(
$label
)
:
$label
,
));
}
$index
++
;
}
...
...
tests/unit/framework/helpers/HtmlTest.php
View file @
7aeb2fcf
...
...
@@ -210,6 +210,19 @@ class HtmlTest extends TestCase
$this
->
assertEquals
(
'<input type="radio" name="test" value="1">'
,
Html
::
radio
(
'test'
));
$this
->
assertEquals
(
'<input type="radio" class="a" name="test" checked>'
,
Html
::
radio
(
'test'
,
true
,
array
(
'class'
=>
'a'
,
'value'
=>
null
)));
$this
->
assertEquals
(
'<input type="hidden" name="test" value="0"><input type="radio" class="a" name="test" value="2" checked>'
,
Html
::
radio
(
'test'
,
true
,
array
(
'class'
=>
'a'
,
'uncheck'
=>
'0'
,
'value'
=>
2
)));
$this
->
assertEquals
(
'<div class="radio"><label class="bbb"><input type="checkbox" class="a" name="test" checked> ccc</label></div>'
,
Html
::
radio
(
'test'
,
true
,
array
(
'class'
=>
'a'
,
'value'
=>
null
,
'label'
=>
'ccc'
,
'labelOptions'
=>
array
(
'class'
=>
'bbb'
),
)));
$this
->
assertEquals
(
'<input type="hidden" name="test" value="0"><div class="radio"><label><input type="checkbox" class="a" name="test" value="2" checked></label></div>'
,
Html
::
radio
(
'test'
,
true
,
array
(
'class'
=>
'a'
,
'uncheck'
=>
'0'
,
'label'
=>
'ccc'
,
'value'
=>
2
,
)));
}
public
function
testCheckbox
()
...
...
@@ -217,6 +230,19 @@ class HtmlTest extends TestCase
$this
->
assertEquals
(
'<input type="checkbox" name="test" value="1">'
,
Html
::
checkbox
(
'test'
));
$this
->
assertEquals
(
'<input type="checkbox" class="a" name="test" checked>'
,
Html
::
checkbox
(
'test'
,
true
,
array
(
'class'
=>
'a'
,
'value'
=>
null
)));
$this
->
assertEquals
(
'<input type="hidden" name="test" value="0"><input type="checkbox" class="a" name="test" value="2" checked>'
,
Html
::
checkbox
(
'test'
,
true
,
array
(
'class'
=>
'a'
,
'uncheck'
=>
'0'
,
'value'
=>
2
)));
$this
->
assertEquals
(
'<div class="checkbox"><label class="bbb"><input type="checkbox" class="a" name="test" checked> ccc</label></div>'
,
Html
::
checkbox
(
'test'
,
true
,
array
(
'class'
=>
'a'
,
'value'
=>
null
,
'label'
=>
'ccc'
,
'labelOptions'
=>
array
(
'class'
=>
'bbb'
),
)));
$this
->
assertEquals
(
'<input type="hidden" name="test" value="0"><div class="checkbox"><label><input type="checkbox" class="a" name="test" value="2" checked></label></div>'
,
Html
::
checkbox
(
'test'
,
true
,
array
(
'class'
=>
'a'
,
'uncheck'
=>
'0'
,
'label'
=>
'ccc'
,
'value'
=>
2
,
)));
}
public
function
testDropDownList
()
...
...
@@ -299,20 +325,20 @@ EOD;
$this
->
assertEquals
(
''
,
Html
::
checkboxList
(
'test'
));
$expected
=
<<<EOD
<
label><input type="checkbox" name="test[]" value="value1"> text1</label
>
<
label><input type="checkbox" name="test[]" value="value2" checked> text2</label
>
<
div class="checkbox"><label><input type="checkbox" name="test[]" value="value1"> text1</label></div
>
<
div class="checkbox"><label><input type="checkbox" name="test[]" value="value2" checked> text2</label></div
>
EOD;
$this
->
assertEqualsWithoutLE
(
$expected
,
Html
::
checkboxList
(
'test'
,
array
(
'value2'
),
$this
->
getDataItems
()));
$expected
=
<<<EOD
<
label><input type="checkbox" name="test[]" value="value1<>"> text1<></label
>
<
label><input type="checkbox" name="test[]" value="value 2"> text 2</label
>
<
div class="checkbox"><label><input type="checkbox" name="test[]" value="value1<>"> text1<></label></div
>
<
div class="checkbox"><label><input type="checkbox" name="test[]" value="value 2"> text 2</label></div
>
EOD;
$this
->
assertEqualsWithoutLE
(
$expected
,
Html
::
checkboxList
(
'test'
,
array
(
'value2'
),
$this
->
getDataItems2
()));
$expected
=
<<<EOD
<
input type="hidden" name="test" value="0"><label><input type="checkbox" name="test[]" value="value1"> text1</label
><br>
<
label><input type="checkbox" name="test[]" value="value2" checked> text2</label
>
<
div class="checkbox"><input type="hidden" name="test" value="0"><label><input type="checkbox" name="test[]" value="value1"> text1</label></div
><br>
<
div class="checkbox"><label><input type="checkbox" name="test[]" value="value2" checked> text2</label></div
>
EOD;
$this
->
assertEqualsWithoutLE
(
$expected
,
Html
::
checkboxList
(
'test'
,
array
(
'value2'
),
$this
->
getDataItems
(),
array
(
'separator'
=>
"<br>
\n
"
,
...
...
@@ -335,20 +361,20 @@ EOD;
$this
->
assertEquals
(
''
,
Html
::
radioList
(
'test'
));
$expected
=
<<<EOD
<
label><input type="radio" name="test" value="value1"> text1</label
>
<
label><input type="radio" name="test" value="value2" checked> text2</label
>
<
div class="radio"><label><input type="radio" name="test" value="value1"> text1</label></div
>
<
div class="radio"><label><input type="radio" name="test" value="value2" checked> text2</label></div
>
EOD;
$this
->
assertEqualsWithoutLE
(
$expected
,
Html
::
radioList
(
'test'
,
array
(
'value2'
),
$this
->
getDataItems
()));
$expected
=
<<<EOD
<
label><input type="radio" name="test" value="value1<>"> text1<></label
>
<
label><input type="radio" name="test" value="value 2"> text 2</label
>
<
div class="radio"><label><input type="radio" name="test" value="value1<>"> text1<></label></div
>
<
div class="radio"><label><input type="radio" name="test" value="value 2"> text 2</label></div
>
EOD;
$this
->
assertEqualsWithoutLE
(
$expected
,
Html
::
radioList
(
'test'
,
array
(
'value2'
),
$this
->
getDataItems2
()));
$expected
=
<<<EOD
<
input type="hidden" name="test" value="0"><label><input type="radio" name="test" value="value1"> text1</label
><br>
<
label><input type="radio" name="test" value="value2" checked> text2</label
>
<
div class="radio"><input type="hidden" name="test" value="0"><label><input type="radio" name="test" value="value1"> text1</label></div
><br>
<
div class="radio"><label><input type="radio" name="test" value="value2" checked> text2</label></div
>
EOD;
$this
->
assertEqualsWithoutLE
(
$expected
,
Html
::
radioList
(
'test'
,
array
(
'value2'
),
$this
->
getDataItems
(),
array
(
'separator'
=>
"<br>
\n
"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment