Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Q
question2answer
Overview
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
outils
question2answer
Commits
5f1c179d
Commit
5f1c179d
authored
Oct 28, 2014
by
Scott
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #65 from pupi1985/patch-27
Added support for boolean values to the qa_js function
parents
6c5d47da
ed7e88f5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
2 deletions
+25
-2
qa-base.php
qa-include/qa-base.php
+6
-2
UtilStringTest.php
qa-tests/UtilStringTest.php
+19
-0
No files found.
qa-include/qa-base.php
View file @
5f1c179d
...
...
@@ -864,10 +864,14 @@
function
qa_js
(
$value
,
$forcequotes
=
false
)
/*
Return JavaScript representation of $value, putting in quotes if non-numeric or if $forcequotes is true
Return JavaScript representation of $value, putting in quotes if non-numeric or if $forcequotes is true. In the
case of boolean values they are returned as the appropriate true or false string
*/
{
if
(
is_numeric
(
$value
)
&&
!
$forcequotes
)
$boolean
=
is_bool
(
$value
);
if
(
$boolean
)
$value
=
$value
?
'true'
:
'false'
;
if
((
is_numeric
(
$value
)
||
$boolean
)
&&
!
$forcequotes
)
return
$value
;
else
return
"'"
.
strtr
(
$value
,
array
(
...
...
qa-tests/UtilStringTest.php
View file @
5f1c179d
...
...
@@ -155,4 +155,23 @@ class UtilStringTest extends PHPUnit_Framework_TestCase
$this
->
assertFalse
(
qa_string_matches_one
(
$this
->
strBasic
,
$nonMatches
)
);
}
function
test__qa_js
()
{
$test
=
qa_js
(
'test'
);
$this
->
assertEquals
(
$test
,
"'test'"
);
$test
=
qa_js
(
'test'
,
true
);
$this
->
assertEquals
(
$test
,
"'test'"
);
$test
=
qa_js
(
123
);
$this
->
assertEquals
(
$test
,
123
);
$test
=
qa_js
(
123
,
true
);
$this
->
assertEquals
(
$test
,
"'123'"
);
$test
=
qa_js
(
true
);
$this
->
assertEquals
(
$test
,
'true'
);
$test
=
qa_js
(
true
,
true
);
$this
->
assertEquals
(
$test
,
"'true'"
);
}
}
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