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
a5ababe4
Commit
a5ababe4
authored
Mar 11, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finished HtmlTest.
parent
03e212bc
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
218 additions
and
22 deletions
+218
-22
ArrayHelper.php
framework/util/ArrayHelper.php
+2
-2
Html.php
framework/util/Html.php
+8
-7
Controller.php
framework/web/Controller.php
+0
-5
Pagination.php
framework/web/Pagination.php
+2
-2
ActiveForm.php
framework/widgets/ActiveForm.php
+6
-0
HtmlTest.php
tests/unit/framework/util/HtmlTest.php
+200
-1
todo.md
todo.md
+0
-5
No files found.
framework/util/ArrayHelper.php
View file @
a5ababe4
...
...
@@ -293,7 +293,7 @@ class ArrayHelper
* @return array the encoded data
* @see http://www.php.net/manual/en/function.htmlspecialchars.php
*/
public
static
function
htmlEncode
(
$data
,
$valuesOnly
=
fals
e
,
$charset
=
null
)
public
static
function
htmlEncode
(
$data
,
$valuesOnly
=
tru
e
,
$charset
=
null
)
{
if
(
$charset
===
null
)
{
$charset
=
Yii
::
$app
->
charset
;
...
...
@@ -322,7 +322,7 @@ class ArrayHelper
* @return array the decoded data
* @see http://www.php.net/manual/en/function.htmlspecialchars-decode.php
*/
public
static
function
htmlDecode
(
$data
,
$valuesOnly
=
fals
e
)
public
static
function
htmlDecode
(
$data
,
$valuesOnly
=
tru
e
)
{
$d
=
array
();
foreach
(
$data
as
$key
=>
$value
)
{
...
...
framework/util/Html.php
View file @
a5ababe4
...
...
@@ -106,6 +106,7 @@ class Html
'checked'
,
'readonly'
,
'disabled'
,
'multiple'
,
'size'
,
'maxlength'
,
...
...
@@ -652,7 +653,7 @@ class Html
* except that the array keys represent the optgroup labels specified in $items.
* @return string the generated drop-down list tag
*/
public
static
function
dropDownList
(
$name
,
$items
,
$selection
=
null
,
$attributes
=
array
())
public
static
function
dropDownList
(
$name
,
$items
=
array
()
,
$selection
=
null
,
$attributes
=
array
())
{
$attributes
[
'name'
]
=
$name
;
$options
=
static
::
renderOptions
(
$items
,
$selection
,
$attributes
);
...
...
@@ -693,7 +694,7 @@ class Html
* mode, we can still obtain the posted unselect value.
* @return string the generated list box tag
*/
public
static
function
listBox
(
$name
,
$items
,
$selection
=
null
,
$attributes
=
array
())
public
static
function
listBox
(
$name
,
$items
=
array
()
,
$selection
=
null
,
$attributes
=
array
())
{
if
(
!
isset
(
$attributes
[
'size'
]))
{
$attributes
[
'size'
]
=
4
;
...
...
@@ -742,7 +743,7 @@ class Html
* value and the checked status of the checkbox input.
* @return string the generated checkbox list
*/
public
static
function
checkboxList
(
$name
,
$items
,
$selection
=
null
,
$options
=
array
())
public
static
function
checkboxList
(
$name
,
$items
=
array
()
,
$selection
=
null
,
$options
=
array
())
{
if
(
substr
(
$name
,
-
2
)
!==
'[]'
)
{
$name
.=
'[]'
;
...
...
@@ -800,7 +801,7 @@ class Html
* value and the checked status of the radio button input.
* @return string the generated radio button list
*/
public
static
function
radioList
(
$name
,
$items
,
$selection
=
null
,
$options
=
array
())
public
static
function
radioList
(
$name
,
$items
=
array
()
,
$selection
=
null
,
$options
=
array
())
{
$formatter
=
isset
(
$options
[
'item'
])
?
$options
[
'item'
]
:
null
;
$lines
=
array
();
...
...
@@ -850,7 +851,7 @@ class Html
{
$lines
=
array
();
if
(
isset
(
$attributes
[
'prompt'
]))
{
$prompt
=
str
tr
(
static
::
encode
(
$attributes
[
'prompt'
]),
' '
,
' '
);
$prompt
=
str
_replace
(
' '
,
' '
,
static
::
encode
(
$attributes
[
'prompt'
])
);
$lines
[]
=
static
::
tag
(
'option'
,
$prompt
,
array
(
'value'
=>
''
));
}
...
...
@@ -863,7 +864,7 @@ class Html
$groupAttrs
=
isset
(
$groups
[
$key
])
?
$groups
[
$key
]
:
array
();
$groupAttrs
[
'label'
]
=
$key
;
$attrs
=
array
(
'options'
=>
$options
,
'groups'
=>
$groups
);
$content
=
static
::
renderOptions
(
$
selection
,
$value
,
$attrs
);
$content
=
static
::
renderOptions
(
$
value
,
$selection
,
$attrs
);
$lines
[]
=
static
::
tag
(
'optgroup'
,
"
\n
"
.
$content
.
"
\n
"
,
$groupAttrs
);
}
else
{
$attrs
=
isset
(
$options
[
$key
])
?
$options
[
$key
]
:
array
();
...
...
@@ -871,7 +872,7 @@ class Html
$attrs
[
'selected'
]
=
$selection
!==
null
&&
(
!
is_array
(
$selection
)
&&
!
strcmp
(
$key
,
$selection
)
||
is_array
(
$selection
)
&&
in_array
(
$key
,
$selection
));
$lines
[]
=
static
::
tag
(
'option'
,
str
tr
(
static
::
encode
(
$value
),
' '
,
' '
),
$attrs
);
$lines
[]
=
static
::
tag
(
'option'
,
str
_replace
(
' '
,
' '
,
static
::
encode
(
$value
)
),
$attrs
);
}
}
...
...
framework/web/Controller.php
View file @
a5ababe4
...
...
@@ -16,8 +16,4 @@ namespace yii\web;
*/
class
Controller
extends
\yii\base\Controller
{
public
function
createUrl
(
$route
,
$params
=
array
())
{
}
}
\ No newline at end of file
framework/web/Pagination.php
View file @
a5ababe4
...
...
@@ -14,7 +14,7 @@ use Yii;
*
* When data needs to be rendered in multiple pages, Pagination can be used to
* represent information such as [[itemCount|total item count]], [[pageSize|page size]],
* [[page|current page]], etc. These information can be passed to [[yii\w
eb\w
idgets\Pager|pagers]]
* [[page|current page]], etc. These information can be passed to [[yii\widgets\Pager|pagers]]
* to render pagination buttons or links.
*
* The following example shows how to create a pagination object and feed it
...
...
@@ -47,7 +47,7 @@ use Yii;
* }
*
* // display pagination
* $this->widget('yii\w
eb\w
idgets\LinkPager', array(
* $this->widget('yii\widgets\LinkPager', array(
* 'pages' => $pages,
* ));
* ~~~
...
...
framework/widgets/ActiveForm.php
0 → 100644
View file @
a5ababe4
<?php
class
ActiveForm
{
}
tests/unit/framework/util/HtmlTest.php
View file @
a5ababe4
...
...
@@ -50,6 +50,11 @@ class HtmlTest extends \yii\test\TestCase
$this
->
assertEquals
(
'<input type="text" name="test" value="<>">'
,
Html
::
tag
(
'input'
,
''
,
array
(
'type'
=>
'text'
,
'name'
=>
'test'
,
'value'
=>
'<>'
)));
Html
::
$closeVoidElements
=
true
;
$this
->
assertEquals
(
'<span disabled="disabled"></span>'
,
Html
::
tag
(
'span'
,
''
,
array
(
'disabled'
=>
true
)));
Html
::
$showBooleanAttributeValues
=
false
;
$this
->
assertEquals
(
'<span disabled></span>'
,
Html
::
tag
(
'span'
,
''
,
array
(
'disabled'
=>
true
)));
Html
::
$showBooleanAttributeValues
=
true
;
}
public
function
testBeginTag
()
...
...
@@ -166,69 +171,263 @@ class HtmlTest extends \yii\test\TestCase
public
function
testButtonInput
()
{
$this
->
assertEquals
(
'<input type="button" name="test" value="Button" />'
,
Html
::
buttonInput
(
'test'
));
$this
->
assertEquals
(
'<input type="button" class="a" name="test" value="text" />'
,
Html
::
buttonInput
(
'test'
,
'text'
,
array
(
'class'
=>
'a'
)));
}
public
function
testSubmitInput
()
{
$this
->
assertEquals
(
'<input type="submit" value="Submit" />'
,
Html
::
submitInput
());
$this
->
assertEquals
(
'<input type="submit" class="a" name="test" value="text" />'
,
Html
::
submitInput
(
'test'
,
'text'
,
array
(
'class'
=>
'a'
)));
}
public
function
testResetInput
()
{
$this
->
assertEquals
(
'<input type="reset" value="Reset" />'
,
Html
::
resetInput
());
$this
->
assertEquals
(
'<input type="reset" class="a" name="test" value="text" />'
,
Html
::
resetInput
(
'test'
,
'text'
,
array
(
'class'
=>
'a'
)));
}
public
function
testTextInput
()
{
$this
->
assertEquals
(
'<input type="text" name="test" />'
,
Html
::
textInput
(
'test'
));
$this
->
assertEquals
(
'<input type="text" class="t" name="test" value="value" />'
,
Html
::
textInput
(
'test'
,
'value'
,
array
(
'class'
=>
't'
)));
}
public
function
testHiddenInput
()
{
$this
->
assertEquals
(
'<input type="hidden" name="test" />'
,
Html
::
hiddenInput
(
'test'
));
$this
->
assertEquals
(
'<input type="hidden" class="t" name="test" value="value" />'
,
Html
::
hiddenInput
(
'test'
,
'value'
,
array
(
'class'
=>
't'
)));
}
public
function
testPasswordInput
()
{
$this
->
assertEquals
(
'<input type="password" name="test" />'
,
Html
::
passwordInput
(
'test'
));
$this
->
assertEquals
(
'<input type="password" class="t" name="test" value="value" />'
,
Html
::
passwordInput
(
'test'
,
'value'
,
array
(
'class'
=>
't'
)));
}
public
function
testFileInput
()
{
$this
->
assertEquals
(
'<input type="file" name="test" />'
,
Html
::
fileInput
(
'test'
));
$this
->
assertEquals
(
'<input type="file" class="t" name="test" value="value" />'
,
Html
::
fileInput
(
'test'
,
'value'
,
array
(
'class'
=>
't'
)));
}
public
function
testTextarea
()
{
$this
->
assertEquals
(
'<textarea name="test"></textarea>'
,
Html
::
textarea
(
'test'
));
$this
->
assertEquals
(
'<textarea class="t" name="test">value<></textarea>'
,
Html
::
textarea
(
'test'
,
'value<>'
,
array
(
'class'
=>
't'
)));
}
public
function
testRadio
()
{
$this
->
assertEquals
(
'<input type="radio" name="test" value="1" />'
,
Html
::
radio
(
'test'
));
$this
->
assertEquals
(
'<input type="radio" class="a" name="test" checked="checked" />'
,
Html
::
radio
(
'test'
,
null
,
true
,
array
(
'class'
=>
'a'
)));
$this
->
assertEquals
(
'<input type="hidden" name="test" value="0" /><input type="radio" class="a" name="test" checked="checked" />'
,
Html
::
radio
(
'test'
,
null
,
true
,
array
(
'class'
=>
'a'
,
'uncheck'
=>
'0'
)));
}
public
function
testCheckbox
()
{
$this
->
assertEquals
(
'<input type="checkbox" name="test" value="1" />'
,
Html
::
checkbox
(
'test'
));
$this
->
assertEquals
(
'<input type="checkbox" class="a" name="test" checked="checked" />'
,
Html
::
checkbox
(
'test'
,
null
,
true
,
array
(
'class'
=>
'a'
)));
$this
->
assertEquals
(
'<input type="hidden" name="test" value="0" /><input type="checkbox" class="a" name="test" checked="checked" />'
,
Html
::
checkbox
(
'test'
,
null
,
true
,
array
(
'class'
=>
'a'
,
'uncheck'
=>
'0'
)));
}
public
function
testDropDownList
()
{
$this
->
assertEquals
(
"<select name=
\"
test
\"
>
\n\n
</select>"
,
Html
::
dropDownList
(
'test'
));
$this
->
assertEquals
(
"<select name=
\"
test
\"
>
\n
<option value=
\"
value1
\"
>text1</option>
\n
<option value=
\"
value2
\"
>text2</option>
\n
</select>"
,
Html
::
dropDownList
(
'test'
,
$this
->
getDataItems
()));
$this
->
assertEquals
(
"<select name=
\"
test
\"
>
\n
<option value=
\"
value1
\"
>text1</option>
\n
<option value=
\"
value2
\"
selected=
\"
selected
\"
>text2</option>
\n
</select>"
,
Html
::
dropDownList
(
'test'
,
$this
->
getDataItems
(),
'value2'
));
}
public
function
testListBox
()
{
$expected
=
<<<EOD
<select name="test" size="4">
</select>
EOD;
$this
->
assertEquals
(
$expected
,
Html
::
listBox
(
'test'
));
$expected
=
<<<EOD
<select name="test" size="5">
<option value="value1">text1</option>
<option value="value2">text2</option>
</select>
EOD;
$this
->
assertEquals
(
$expected
,
Html
::
listBox
(
'test'
,
$this
->
getDataItems
(),
null
,
array
(
'size'
=>
5
)));
$expected
=
<<<EOD
<select name="test" size="4">
<option value="value1<>">text1<></option>
<option value="value 2">text 2</option>
</select>
EOD;
$this
->
assertEquals
(
$expected
,
Html
::
listBox
(
'test'
,
$this
->
getDataItems2
(),
null
));
$expected
=
<<<EOD
<select name="test" size="4">
<option value="value1">text1</option>
<option value="value2" selected="selected">text2</option>
</select>
EOD;
$this
->
assertEquals
(
$expected
,
Html
::
listBox
(
'test'
,
$this
->
getDataItems
(),
'value2'
));
$expected
=
<<<EOD
<select name="test" size="4">
<option value="value1" selected="selected">text1</option>
<option value="value2" selected="selected">text2</option>
</select>
EOD;
$this
->
assertEquals
(
$expected
,
Html
::
listBox
(
'test'
,
$this
->
getDataItems
(),
array
(
'value1'
,
'value2'
)));
$expected
=
<<<EOD
<select name="test[]" multiple="multiple" size="4">
</select>
EOD;
$this
->
assertEquals
(
$expected
,
Html
::
listBox
(
'test'
,
array
(),
null
,
array
(
'multiple'
=>
true
)));
$expected
=
<<<EOD
<input type="hidden" name="test" value="0" /><select name="test" size="4">
</select>
EOD;
$this
->
assertEquals
(
$expected
,
Html
::
listBox
(
'test'
,
array
(),
''
,
array
(
'unselect'
=>
'0'
)));
}
public
function
testCheckboxList
()
{
$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="checked" /> text2</label>
EOD;
$this
->
assertEquals
(
$expected
,
Html
::
checkboxList
(
'test'
,
$this
->
getDataItems
(),
array
(
'value2'
)));
$expected
=
<<<EOD
<label><input type="checkbox" name="test[]" value="value1<>" /> text1<></label>
<label><input type="checkbox" name="test[]" value="value 2" /> text 2</label>
EOD;
$this
->
assertEquals
(
$expected
,
Html
::
checkboxList
(
'test'
,
$this
->
getDataItems2
(),
array
(
'value2'
)));
$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="checked" /> text2</label>
EOD;
$this
->
assertEquals
(
$expected
,
Html
::
checkboxList
(
'test'
,
$this
->
getDataItems
(),
array
(
'value2'
),
array
(
'separator'
=>
"<br />
\n
"
,
'unselect'
=>
'0'
,
)));
$expected
=
<<<EOD
<label>text1 <input type="checkbox" name="test[]" value="value1" /></label>
<label>text2 <input type="checkbox" name="test[]" value="value2" checked="checked" /></label>
EOD;
$this
->
assertEquals
(
$expected
,
Html
::
checkboxList
(
'test'
,
$this
->
getDataItems
(),
array
(
'value2'
),
array
(
'item'
=>
function
(
$index
,
$label
,
$name
,
$value
,
$checked
)
{
return
Html
::
label
(
$label
.
' '
.
Html
::
checkbox
(
$name
,
$value
,
$checked
));
}
)));
}
public
function
testRadioList
()
{
$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="checked" /> text2</label>
EOD;
$this
->
assertEquals
(
$expected
,
Html
::
radioList
(
'test'
,
$this
->
getDataItems
(),
array
(
'value2'
)));
$expected
=
<<<EOD
<label><input type="radio" name="test" value="value1<>" /> text1<></label>
<label><input type="radio" name="test" value="value 2" /> text 2</label>
EOD;
$this
->
assertEquals
(
$expected
,
Html
::
radioList
(
'test'
,
$this
->
getDataItems2
(),
array
(
'value2'
)));
$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="checked" /> text2</label>
EOD;
$this
->
assertEquals
(
$expected
,
Html
::
radioList
(
'test'
,
$this
->
getDataItems
(),
array
(
'value2'
),
array
(
'separator'
=>
"<br />
\n
"
,
'unselect'
=>
'0'
,
)));
$expected
=
<<<EOD
<label>text1 <input type="radio" name="test" value="value1" /></label>
<label>text2 <input type="radio" name="test" value="value2" checked="checked" /></label>
EOD;
$this
->
assertEquals
(
$expected
,
Html
::
radioList
(
'test'
,
$this
->
getDataItems
(),
array
(
'value2'
),
array
(
'item'
=>
function
(
$index
,
$label
,
$name
,
$value
,
$checked
)
{
return
Html
::
label
(
$label
.
' '
.
Html
::
radio
(
$name
,
$value
,
$checked
));
}
)));
}
public
function
testRenderOptions
()
{
$this
->
assertEquals
(
''
,
Html
::
renderOptions
(
array
()));
$data
=
array
(
'value1'
=>
'label1'
,
'group1'
=>
array
(
'value11'
=>
'label11'
,
'group11'
=>
array
(
'value111'
=>
'label111'
,
),
'group12'
=>
array
(),
),
'value2'
=>
'label2'
,
'group2'
=>
array
(),
);
$expected
=
<<<EOD
<option value="">please select<></option>
<option value="value1" selected="selected">label1</option>
<optgroup label="group1">
<option value="value11">label11</option>
<optgroup label="group11">
<option class="option" value="value111" selected="selected">label111</option>
</optgroup>
<optgroup class="group" label="group12">
</optgroup>
</optgroup>
<option value="value2">label2</option>
<optgroup label="group2">
</optgroup>
EOD;
$attributes
=
array
(
'prompt'
=>
'please select<>'
,
'options'
=>
array
(
'value111'
=>
array
(
'class'
=>
'option'
),
),
'groups'
=>
array
(
'group12'
=>
array
(
'class'
=>
'group'
),
),
);
$this
->
assertEquals
(
$expected
,
Html
::
renderOptions
(
$data
,
array
(
'value111'
,
'value1'
),
$attributes
));
}
public
function
testRenderAttributes
()
{
$this
->
assertEquals
(
''
,
Html
::
renderAttributes
(
array
()));
$this
->
assertEquals
(
' name="test" value="1<>"'
,
Html
::
renderAttributes
(
array
(
'name'
=>
'test'
,
'empty'
=>
null
,
'value'
=>
'1<>'
)));
Html
::
$showBooleanAttributeValues
=
false
;
$this
->
assertEquals
(
' checked disabled'
,
Html
::
renderAttributes
(
array
(
'checked'
=>
'checked'
,
'disabled'
=>
true
,
'hidden'
=>
false
)));
Html
::
$showBooleanAttributeValues
=
true
;
}
p
ublic
function
testUrl
()
p
rotected
function
getDataItems
()
{
return
array
(
'value1'
=>
'text1'
,
'value2'
=>
'text2'
,
);
}
protected
function
getDataItems2
()
{
return
array
(
'value1<>'
=>
'text1<>'
,
'value 2'
=>
'text 2'
,
);
}
}
todo.md
View file @
a5ababe4
...
...
@@ -32,8 +32,6 @@ memo
*
module
-
Module should be able to define its own configuration including routes. Application should be able to overwrite it.
*
application
*
security
-
backport 1.1 changes
-
built-in console commands
+
api doc builder
*
support for markdown syntax
...
...
@@ -46,7 +44,6 @@ memo
*
parsing??
*
make dates/date patterns uniform application-wide including JUI, formats etc.
-
helpers
*
array
*
image
*
string
*
file
...
...
@@ -59,8 +56,6 @@ memo
*
move generation API out of gii, provide yiic commands to use it. Use same templates for gii/yiic.
*
i18n variant of templates
*
allow to generate module-specific CRUD
-
markup and HTML helpers
*
use HTML5 instead of XHTML
-
assets
*
ability to manage scripts order (store these in a vector?)
*
http://ryanbigg.com/guides/asset_pipeline.html, http://guides.rubyonrails.org/asset_pipeline.html, use content hash instead of mtime + directory hash.
...
...
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