Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
no-captcha
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
CENTER-TBI
no-captcha
Commits
c7fc3b45
Unverified
Commit
c7fc3b45
authored
Dec 04, 2018
by
Nguyen Van Anh
Committed by
GitHub
Dec 04, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #125 from marivaldojr/master
displaySubmit with custom data-callback
parents
a5aefd96
159f260e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
14 deletions
+28
-14
src/NoCaptcha.php
src/NoCaptcha.php
+11
-7
tests/NoCaptchaTest.php
tests/NoCaptchaTest.php
+17
-7
No files found.
src/NoCaptcha.php
View file @
c7fc3b45
...
...
@@ -82,16 +82,20 @@ class NoCaptcha
*/
public
function
displaySubmit
(
$formIdentifier
,
$text
=
'submit'
,
$attributes
=
[])
{
$javascript
=
''
;
if
(
!
isset
(
$attributes
[
'data-callback'
]))
{
$functionName
=
'onSubmit'
.
str_replace
([
'-'
,
'='
,
'\''
,
'"'
,
'<'
,
'>'
,
'`'
],
''
,
$formIdentifier
);
$attributes
[
'data-callback'
]
=
$functionName
;
$attributes
=
$this
->
prepareAttributes
(
$attributes
);
$button
=
sprintf
(
'<button%s><span>%s</span></button>'
,
$this
->
buildAttributes
(
$attributes
),
$text
);
$javascript
=
sprintf
(
'<script>function %s(){document.getElementById("%s").submit();}</script>'
,
$functionName
,
$formIdentifier
);
}
$attributes
=
$this
->
prepareAttributes
(
$attributes
);
$button
=
sprintf
(
'<button%s><span>%s</span></button>'
,
$this
->
buildAttributes
(
$attributes
),
$text
);
return
$button
.
$javascript
;
}
...
...
tests/NoCaptchaTest.php
View file @
c7fc3b45
...
...
@@ -23,9 +23,9 @@ class NoCaptchaTest extends PHPUnit_Framework_TestCase
$withLang
=
'<script src="https://www.google.com/recaptcha/api.js?hl=vi" async defer></script>'
.
"
\n
"
;
$withCallback
=
'<script src="https://www.google.com/recaptcha/api.js?render=explicit&onload=myOnloadCallback" async defer></script>'
.
"
\n
"
;
$this
->
assertEquals
(
$
this
->
captcha
->
renderJs
(),
$simple
);
$this
->
assertEquals
(
$
this
->
captcha
->
renderJs
(
'vi'
),
$withLang
);
$this
->
assertEquals
(
$
this
->
captcha
->
renderJs
(
null
,
true
,
'myOnloadCallback'
),
$withCallback
);
$this
->
assertEquals
(
$
simple
,
$this
->
captcha
->
renderJs
()
);
$this
->
assertEquals
(
$
withLang
,
$this
->
captcha
->
renderJs
(
'vi'
)
);
$this
->
assertEquals
(
$
withCallback
,
$this
->
captcha
->
renderJs
(
null
,
true
,
'myOnloadCallback'
)
);
}
public
function
testDisplay
()
...
...
@@ -35,8 +35,8 @@ class NoCaptchaTest extends PHPUnit_Framework_TestCase
$simple
=
'<div data-sitekey="{site-key}" class="g-recaptcha"></div>'
;
$withAttrs
=
'<div data-theme="light" data-sitekey="{site-key}" class="g-recaptcha"></div>'
;
$this
->
assertEquals
(
$
this
->
captcha
->
display
(),
$simple
);
$this
->
assertEquals
(
$
this
->
captcha
->
display
([
'data-theme'
=>
'light'
]),
$withAttrs
);
$this
->
assertEquals
(
$
simple
,
$this
->
captcha
->
display
()
);
$this
->
assertEquals
(
$
withAttrs
,
$this
->
captcha
->
display
([
'data-theme'
=>
'light'
])
);
}
public
function
testdisplaySubmit
()
...
...
@@ -47,8 +47,18 @@ class NoCaptchaTest extends PHPUnit_Framework_TestCase
$simple
=
'<button data-callback="onSubmittest" data-sitekey="{site-key}" class="g-recaptcha"><span>submit</span></button>'
;
$withAttrs
=
'<button data-theme="light" class="g-recaptcha 123" data-callback="onSubmittest" data-sitekey="{site-key}"><span>submit123</span></button>'
;
$this
->
assertEquals
(
$
this
->
captcha
->
displaySubmit
(
'test'
),
$simple
.
$javascript
);
$this
->
assertEquals
(
$
simple
.
$javascript
,
$this
->
captcha
->
displaySubmit
(
'test'
)
);
$withAttrsResult
=
$this
->
captcha
->
displaySubmit
(
'test'
,
'submit123'
,[
'data-theme'
=>
'light'
,
'class'
=>
'123'
]);
$this
->
assertEquals
(
$withAttrsResult
,
$withAttrs
.
$javascript
);
$this
->
assertEquals
(
$withAttrs
.
$javascript
,
$withAttrsResult
);
}
public
function
testdisplaySubmitWithCustomCallback
()
{
$this
->
assertTrue
(
$this
->
captcha
instanceof
NoCaptcha
);
$withAttrs
=
'<button data-theme="light" class="g-recaptcha 123" data-callback="onSubmitCustomCallback" data-sitekey="{site-key}"><span>submit123</span></button>'
;
$withAttrsResult
=
$this
->
captcha
->
displaySubmit
(
'test-custom'
,
'submit123'
,[
'data-theme'
=>
'light'
,
'class'
=>
'123'
,
'data-callback'
=>
'onSubmitCustomCallback'
]);
$this
->
assertEquals
(
$withAttrs
,
$withAttrsResult
);
}
}
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