Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
captcha_pack
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
captcha_pack
Commits
6a4881f2
Commit
6a4881f2
authored
5 months ago
by
Viktor Holovachek
Browse files
Options
Downloads
Patches
Plain Diff
Resolve
#3474842
"Cover the module"
parent
68916514
No related branches found
No related tags found
1 merge request
!18
Resolve #3474842 "Cover the module"
Pipeline
#286289
passed with warnings
5 months ago
Stage: build
Stage: validate
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/src/Functional/CaptchaPackTests.php
+92
-0
92 additions, 0 deletions
tests/src/Functional/CaptchaPackTests.php
with
92 additions
and
0 deletions
tests/src/Functional/CaptchaPackTests.php
0 → 100644
+
92
−
0
View file @
6a4881f2
<?php
namespace
Drupal\Tests\captcha_pack\Functional
;
use
Drupal\captcha\Entity\CaptchaPoint
;
use
Drupal\Tests\BrowserTestBase
;
/**
* Tests different captcha types.
*/
class
CaptchaPackTests
extends
BrowserTestBase
{
/**
* {@inheritdoc}
*/
protected
static
$modules
=
[
'captcha'
,
'captcha_pack'
,
'foo_captcha'
];
/**
* {@inheritdoc}
*/
protected
$defaultTheme
=
'stark'
;
/**
* Testing the protection of the user log in form.
*/
public
function
testCaptchaOnLoginForm
()
{
// Create user and test log in without CAPTCHA.
$user
=
$this
->
drupalCreateUser
();
$this
->
drupalLogin
(
$user
);
// Log out again.
$this
->
drupalLogout
();
// Set a CAPTCHA on login form.
$this
->
setCaptcha
(
'user_login_form'
,
'foo_captcha/Foo CAPTCHA'
);
// Go to the login page and check the page response.
$this
->
drupalGet
(
'user/login'
);
$this
->
assertSession
()
->
statusCodeEquals
(
200
);
// Check if the page contains the description.
$description
=
\Drupal
::
config
(
'captcha.settings'
)
->
get
(
'description'
);
$this
->
assertSession
()
->
pageTextContains
(
$description
);
// Try to log in, which should fail.
$edit
=
[
'name'
=>
$user
->
getUsername
(),
'pass'
=>
$user
->
pass_raw
,
'captcha_response'
=>
'?'
,
];
$this
->
submitForm
(
$edit
,
'Log in'
,
'user-login-form'
);
// Check for error message.
$this
->
assertSession
()
->
pageTextContains
(
'The answer you entered for the CAPTCHA was not correct.'
);
// Go to the login page and check the page response.
$this
->
drupalGet
(
'user/login'
);
$this
->
assertSession
()
->
statusCodeEquals
(
200
);
// Try to log in, which should work.
$edit
=
[
'name'
=>
$user
->
getUsername
(),
'pass'
=>
$user
->
pass_raw
,
'captcha_response'
=>
'foo'
,
];
$this
->
submitForm
(
$edit
,
'Log in'
,
'user-login-form'
);
$this
->
assertSession
()
->
pageTextContains
(
$user
->
getUsername
());
}
/**
* Helper function to set the captcha type.
*/
public
function
setCaptcha
(
$form_id
,
$captcha_type
)
{
/** @var \Drupal\captcha\CaptchaPointInterface $captcha_point */
$captcha_point
=
CaptchaPoint
::
load
(
$form_id
);
if
(
$captcha_point
)
{
$captcha_point
->
setCaptchaType
(
$captcha_type
);
}
else
{
$captcha_point
=
new
CaptchaPoint
([
'formId'
=>
$form_id
,
'captchaType'
=>
$captcha_type
,
],
'captcha_point'
);
}
$captcha_point
->
enable
();
$captcha_point
->
save
();
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment