Commit e783438a authored by naveenvalecha's avatar naveenvalecha Committed by elachlan

Issue #2798991 by naveenvalecha: Fix coding standards & replace the deprecated methods

parent 524d26a3
......@@ -30,14 +30,16 @@ function _captcha_available_challenge_types($add_special_options = TRUE) {
$result = call_user_func_array($module . '_captcha', ['list']);
if (is_array($result)) {
foreach ($result as $type) {
$captcha_types["$module/$type"] = t('@type (from module @module)', ['@type' => $type, '@module' => $module]);
$captcha_types["$module/$type"] = t('@type (from module @module)', [
'@type' => $type,
'@module' => $module,
]);
}
}
}
return $captcha_types;
}
/**
* Helper function for generating an example challenge.
*/
......
......@@ -5,8 +5,8 @@
* General CAPTCHA functionality and helper functions.
*/
use Drupal\Component\Utility\Xss;
use Drupal\captcha\Entity\CaptchaPoint;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Render\Element;
/**
......@@ -30,7 +30,10 @@ function captcha_set_form_id_setting($form_id, $captcha_type) {
$captcha_point->setCaptchaType($captcha_type);
}
else {
$captcha_point = new CaptchaPoint(['formId' => $form_id, 'captchaType' => $captcha_type], 'captcha_point');
$captcha_point = new CaptchaPoint([
'formId' => $form_id,
'captchaType' => $captcha_type,
], 'captcha_point');
}
$captcha_point->enable();
......@@ -62,7 +65,6 @@ function captcha_get_form_id_setting($form_id, $symbolic = FALSE) {
return $captcha_point;
}
/**
* Helper function for generating a new CAPTCHA session.
*
......@@ -84,14 +86,14 @@ function _captcha_generate_captcha_session($form_id = NULL, $status = CAPTCHA_ST
// of the autoincrement field 'csid'.
$captcha_sid = db_insert('captcha_sessions')
->fields([
'uid' => $user->id(),
'sid' => session_id(),
'ip_address' => Drupal::request()->getClientIp(),
'timestamp' => REQUEST_TIME,
'form_id' => $form_id,
'solution' => $solution,
'status' => $status,
'attempts' => 0,
'uid' => $user->id(),
'sid' => session_id(),
'ip_address' => Drupal::request()->getClientIp(),
'timestamp' => REQUEST_TIME,
'form_id' => $form_id,
'solution' => $solution,
'status' => $status,
'attempts' => 0,
])
->execute();
return $captcha_sid;
......@@ -123,7 +125,8 @@ function _captcha_update_captcha_session($captcha_sid, $solution) {
*/
function _captcha_required_for_user($captcha_sid, $form_id) {
// Get the CAPTCHA persistence setting.
$captcha_persistence = \Drupal::config('captcha.settings')->get('persistence');
$captcha_persistence = \Drupal::config('captcha.settings')
->get('persistence');
// First check: should we always add a CAPTCHA?
if ($captcha_persistence == CAPTCHA_PERSISTENCE_SHOW_ALWAYS) {
......@@ -158,7 +161,6 @@ function _captcha_required_for_user($captcha_sid, $form_id) {
return TRUE;
}
/**
* Get the CAPTCHA description.
*
......@@ -182,7 +184,8 @@ function _captcha_get_description() {
*/
function _captcha_parse_captcha_type($captcha_type) {
if ($captcha_type == 'default') {
$captcha_type = \Drupal::config('captcha.settings')->get('default_challenge', 'captcha/Math');
$captcha_type = \Drupal::config('captcha.settings')
->get('default_challenge', 'captcha/Math');
}
return explode('/', $captcha_type);
}
......@@ -210,7 +213,8 @@ function _captcha_get_captcha_placement($form_id, $form) {
// By default however, probably all Drupal core forms
// are already correctly handled with the best effort guess
// based on the 'actions' element (see below).
$placement_map = \Drupal::moduleHandler()->invokeAll('captcha_placement_map');
$placement_map = \Drupal::moduleHandler()
->invokeAll('captcha_placement_map');
$write_cache = TRUE;
}
}
......@@ -322,7 +326,7 @@ function _captcha_insert_captcha_element(array &$form, array $placement, array $
$form_stepper = &$form;
foreach ($path as $step) {
if (isset($form_stepper[$step])) {
$form_stepper = & $form_stepper[$step];
$form_stepper = &$form_stepper[$step];
}
else {
// Given path is invalid: stop stepping and
......
......@@ -136,8 +136,14 @@ function captcha_install() {
}
// Explain to users that page caching may be disabled.
if ($config = \Drupal::config('system.performance')->get('cache.page.use_internal') != 0) {
drupal_set_message(\Drupal::translation()->translate('Note that the CAPTCHA module disables <a href="@performance_admin">page caching</a> of pages that include a CAPTCHA challenge.',
['@performance_admin' => Url::fromUri('internal:/admin/config/development/performance')->toString()]), 'warning');
if ($config = \Drupal::config('system.performance')
->get('cache.page.use_internal') != 0
) {
drupal_set_message(\Drupal::translation()
->translate('Note that the CAPTCHA module disables <a href="@performance_admin">page caching</a> of pages that include a CAPTCHA challenge.',
[
'@performance_admin' => Url::fromUri('internal:/admin/config/development/performance')
->toString(),
]), 'warning');
}
}
......@@ -11,11 +11,12 @@
use Drupal\captcha\Entity\CaptchaPoint;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\Core\Database\Database;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Link;
use \Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
/**
* Constants for CAPTCHA persistence.
*
......@@ -144,7 +145,9 @@ function captcha_form_alter(array &$form, FormStateInterface $form_state, $form_
if (!$account->hasPermission('skip CAPTCHA')) {
/* @var CaptchaPoint $captcha_point */
$captcha_point = \Drupal::entityTypeManager()->getStorage('captcha_point')->load($form_id);
$captcha_point = \Drupal::entityTypeManager()
->getStorage('captcha_point')
->load($form_id);
if ($captcha_point && $captcha_point->status()) {
// Build CAPTCHA form element.
......@@ -165,7 +168,9 @@ function captcha_form_alter(array &$form, FormStateInterface $form_state, $form_
}
}
elseif ($config->get('administration_mode') && $account->hasPermission('administer CAPTCHA settings')
&& (!\Drupal::service('router.admin_context')->isAdminRoute() || $config->get('allow_on_admin_pages'))) {
&& (!\Drupal::service('router.admin_context')
->isAdminRoute() || $config->get('allow_on_admin_pages'))
) {
// Add CAPTCHA administration tools.
/* @var \Drupal\captcha\Entity\CaptchaPoint $captcha_point */
$captcha_point = CaptchaPoint::load($form_id);
......@@ -184,17 +189,23 @@ function captcha_form_alter(array &$form, FormStateInterface $form_state, $form_
$markup = '<a href="@change">change</a>';
$captcha_element['#title'] = $captcha_point->status() ? t('CAPTCHA: challenge "@type" enabled', ['@type' => $captcha_point->getCaptchaType()]) : t('CAPTCHA: challenge "@type" disabled', ['@type' => $captcha_point->getCaptchaType()]);
$captcha_point->status() ? $captcha_element['#description'] = t('Untrusted users will see a CAPTCHA here (<a href="@settings">general CAPTCHA settings</a>).',
['@settings' => Url::fromRoute('captcha_settings')->toString()]) : $captcha_element['#description'] = t('CAPTCHA disabled, Untrusted users won\'t see the captcha (<a href="@settings">general CAPTCHA settings</a>).',
[
'@settings' => Url::fromRoute('captcha_settings')
->toString(),
]) : $captcha_element['#description'] = t('CAPTCHA disabled, Untrusted users won\'t see the captcha (<a href="@settings">general CAPTCHA settings</a>).',
['@settings' => Url::fromRoute('captcha_settings')->toString()]
);
);
$captcha_element['challenge'] = [
'#type' => 'item',
'#title' => t('Enabled challenge'),
'#markup' => t($markup, [
'%type' => $captcha_point->getCaptchaType(),
'@change' => $captcha_point->url('edit-form', ['query' => Drupal::destination()->getAsArray()]),
// '@disable' => $captcha_point->url('disable', ['query' => Drupal::destination()->getAsArray()]),
// '@enable' => $captcha_point->url('enable', ['query' => Drupal::destination()->getAsArray()]),
'@change' => $captcha_point->url('edit-form', [
'query' => Drupal::destination()
->getAsArray(),
]),
// '@disable' => $captcha_point->url('disable', ['query' => Drupal::destination()->getAsArray()]),
// '@enable' => $captcha_point->url('enable', ['query' => Drupal::destination()->getAsArray()]),
]),
];
// // Add an example challenge with solution.
......@@ -223,7 +234,8 @@ function captcha_form_alter(array &$form, FormStateInterface $form_state, $form_
'#markup' => Link::fromTextAndUrl(
t('Place a CAPTCHA here for untrusted users.'),
Url::fromRoute('captcha_point.add', [], [
'query' => Drupal::destination()->getAsArray() + ['form_id' => $form_id],
'query' => Drupal::destination()
->getAsArray() + ['form_id' => $form_id],
])
)->toString(),
];
......@@ -411,7 +423,7 @@ function captcha_validate($element, FormStateInterface &$form_state) {
$solution = db_query(
'SELECT solution FROM {captcha_sessions} WHERE csid = :csid',
[':csid' => $csid]
)
)
->fetchField();
// @todo: what is the result when there is no entry for
......@@ -455,10 +467,13 @@ function captcha_validate($element, FormStateInterface &$form_state) {
$form_state->setErrorByName('captcha_response', t('The answer you entered for the CAPTCHA was not correct.'));
// Update wrong response counter.
if (\Drupal::config('captcha.settings')->get('enable_stats', FALSE)) {
Drupal::state()->set('captcha.wrong_response_counter', Drupal::state()->get('captcha.wrong_response_counter', 0) + 1);
Drupal::state()->set('captcha.wrong_response_counter', Drupal::state()
->get('captcha.wrong_response_counter', 0) + 1);
}
if (\Drupal::config('captcha.settings')->get('log_wrong_responses', FALSE)) {
if (\Drupal::config('captcha.settings')
->get('log_wrong_responses', FALSE)
) {
\Drupal::logger('CAPTCHA')->notice(
'%form_id post blocked by CAPTCHA module: challenge %challenge (by module %module), user answered "@response", but the solution was "@solution".',
[
......
<?php
/**
* @file
* Contains functions used in the backend forms.
......
<?php
/**
* @file
* Contains CAPTCHA font previews controller class.
*/
namespace Drupal\image_captcha\Controller;
use Symfony\Component\HttpFoundation\Request;
......@@ -14,6 +9,7 @@ use Symfony\Component\HttpFoundation\StreamedResponse;
* A Controller to preview the captcha font on the settings page.
*/
class CaptchaFontPreview extends StreamedResponse {
/**
* {@inheritdoc}
*/
......
<?php
/**
* @file
* Contains CAPTCHA image response class.
*/
namespace Drupal\image_captcha\Controller;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
......
......@@ -320,7 +320,7 @@ class ImageCaptchaSettingsForm extends ConfigFormBase {
'#options' => $available_fonts,
'#attributes' => ['class' => ['image_captcha_admin_fonts_selection']],
'#process' => ['form_process_checkboxes'],
];
];
$form['image_captcha_font_size'] = [
'#type' => 'select',
......@@ -361,7 +361,7 @@ class ImageCaptchaSettingsForm extends ConfigFormBase {
/**
* Helper function to get fonts from the given directories.
*
* @param array|NULL $directories
* @param array|null $directories
* (Optional) an array of directories
* to recursively search through, if not given, the default
* directories will be used.
......
<?php
/**
* @file
* Contains CAPTCHA image response class.
*/
namespace Drupal\image_captcha\Response;
use Drupal\Core\Logger\LoggerChannelInterface;
......
......@@ -50,7 +50,7 @@ interface CaptchaPointInterface extends ConfigEntityInterface {
/**
* Setter for captcha type property.
*
* @param string|NULL $captcha_type
* @param string|null $captcha_type
* Captcha type.
*/
public function setCaptchaType($captcha_type);
......
......@@ -9,6 +9,7 @@ use Drupal\Core\Entity\EntityInterface;
* Builds the list of capture points for the captcha point form.
*/
class CaptchaPointListBuilder extends ConfigEntityListBuilder {
/**
* {@inheritdoc}
*/
......
......@@ -32,7 +32,9 @@ class Captcha extends FormElement {
// Override the default CAPTCHA validation function for case
// insensitive validation.
// TODO: shouldn't this be done somewhere else, e.g. in form_alter?
if (CAPTCHA_DEFAULT_VALIDATION_CASE_INSENSITIVE == \Drupal::config('captcha.settings')->get('default_validation')) {
if (CAPTCHA_DEFAULT_VALIDATION_CASE_INSENSITIVE == \Drupal::config('captcha.settings')
->get('default_validation')
) {
$captcha_element['#captcha_validate'] = 'captcha_validate_case_insensitive_equality';
}
return $captcha_element;
......@@ -42,7 +44,7 @@ class Captcha extends FormElement {
* Process callback for CAPTCHA form element.
*/
public static function processCaptchaElement(&$element, FormStateInterface $form_state, &$complete_form) {
// Add captcha.inc file
// Add captcha.inc file.
module_load_include('inc', 'captcha');
// Add Javascript for general CAPTCHA functionality.
......@@ -116,10 +118,15 @@ class Captcha extends FormElement {
if (_captcha_required_for_user($captcha_sid, $this_form_id) || $element['#captcha_admin_mode']) {
// Generate a CAPTCHA and its solution
// (note that the CAPTCHA session ID is given as third argument).
$captcha = \Drupal::moduleHandler()->invoke($captcha_type_module, 'captcha', ['generate', $captcha_type_challenge, $captcha_sid]);
$captcha = \Drupal::moduleHandler()
->invoke($captcha_type_module, 'captcha', [
'generate',
$captcha_type_challenge,
$captcha_sid,
]);
// @todo Isn't this moment a bit late to figure out that we don't need CAPTCHA?
if(!isset($captcha)) {
if (!isset($captcha)) {
return $element;
}
......@@ -127,7 +134,11 @@ class Captcha extends FormElement {
// The selected module did not return what we expected: log about it and quit.
\Drupal::logger('CAPTCHA')->error(
'CAPTCHA problem: unexpected result from hook_captcha() of module %module when trying to retrieve challenge type %type for form %form_id.',
['%type' => $captcha_type_challenge, '%module' => $captcha_type_module, '%form_id' => $this_form_id]
[
'%type' => $captcha_type_challenge,
'%module' => $captcha_type_module,
'%form_id' => $this_form_id,
]
);
return $element;
......
......@@ -2,9 +2,8 @@
namespace Drupal\captcha\Entity;
use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\Core\Cache\Cache;
use Drupal\captcha\CaptchaPointInterface;
use Drupal\Core\Config\Entity\ConfigEntityBase;
/**
* Defines the CaptchaPoint entity.
......
......@@ -2,10 +2,10 @@
namespace Drupal\captcha\Form;
use Drupal\Core\Url;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Link;
use Drupal\Core\Url;
/**
* Displays the captcha settings form.
......@@ -37,17 +37,24 @@ class CaptchaExamplesForm extends FormBase {
$form['info'] = [
'#markup' => t('This page gives an overview of all available challenge types, generated with their current settings.'),
];
foreach (\Drupal::moduleHandler()->getImplementations('captcha') as $mkey => $module) {
foreach (\Drupal::moduleHandler()
->getImplementations('captcha') as $mkey => $module) {
$challenges = call_user_func_array($module . '_captcha', ['list']);
if ($challenges) {
foreach ($challenges as $ckey => $challenge) {
$form["captcha_{$mkey}_{$ckey}"] = [
'#type' => 'details',
'#title' => t('Challenge %challenge by module %module', ['%challenge' => $challenge, '%module' => $module]),
'#title' => t('Challenge %challenge by module %module', [
'%challenge' => $challenge,
'%module' => $module,
]),
'challenge' => _captcha_generate_example_challenge($module, $challenge),
'more_examples' => [
'#markup' => Link::fromTextAndUrl(t('10 more examples of this challenge.'), Url::fromRoute('captcha_examples', array('module' => $module, 'challenge' => $challenge)))->toString(),
'#markup' => Link::fromTextAndUrl(t('10 more examples of this challenge.'), Url::fromRoute('captcha_examples', [
'module' => $module,
'challenge' => $challenge,
]))->toString(),
],
];
}
......
......@@ -45,7 +45,7 @@ class CaptchaPointDisableForm extends EntityConfirmFormBase {
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->entity->disable();
$this->entity->save();
drupal_set_message($this->t('Captcha point %label has been disabled.', array('%label' => $this->entity->label())));
drupal_set_message($this->t('Captcha point %label has been disabled.', ['%label' => $this->entity->label()]));
$form_state->setRedirect('captcha_point.list');
}
......
......@@ -24,6 +24,7 @@ class CaptchaPointEnableForm extends EntityConfirmFormBase {
public function getDescription() {
return $this->t('This will enable the captcha.');
}
/**
* {@inheritdoc}
*/
......@@ -44,7 +45,7 @@ class CaptchaPointEnableForm extends EntityConfirmFormBase {
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->entity->enable();
$this->entity->save();
drupal_set_message($this->t('Captcha point %label has been enabled.', array('%label' => $this->entity->label())));
drupal_set_message($this->t('Captcha point %label has been enabled.', ['%label' => $this->entity->label()]));
$form_state->setRedirect('captcha_point.list');
}
......
......@@ -2,9 +2,7 @@
namespace Drupal\captcha\Form;
use Drupal\captcha\Entity\CaptchaPoint;
use Drupal\Core\Entity\EntityForm;
use Drupal\captcha\CaptchaPointInterface;
use Drupal\Core\Form\FormStateInterface;
/**
......@@ -52,7 +50,8 @@ class CaptchaPointForm extends EntityForm {
'#type' => 'select',
'#title' => t('Challenge type'),
'#description' => t('The CAPTCHA type to use for this form.'),
'#default_value' => ($captcha_point->getCaptchaType() ?: $this->config('captcha.settings')->get('default_challenge')),
'#default_value' => ($captcha_point->getCaptchaType() ?: $this->config('captcha.settings')
->get('default_challenge')),
'#options' => _captcha_available_challenge_types(),
];
......
......@@ -158,7 +158,10 @@ class CaptchaSettingsForm extends ConfigFormBase {
$form['enable_stats'] = [
'#type' => 'checkbox',
'#title' => $this->t('Enable statistics'),
'#description' => $this->t('Keep CAPTCHA related counters in the <a href=":statusreport">status report</a>. Note that this comes with a performance penalty as updating the counters results in clearing the variable cache.', [':statusreport' => Url::fromRoute('system.status')->toString()]),
'#description' => $this->t('Keep CAPTCHA related counters in the <a href=":statusreport">status report</a>. Note that this comes with a performance penalty as updating the counters results in clearing the variable cache.', [
':statusreport' => Url::fromRoute('system.status')
->toString(),
]),
'#default_value' => $config->get('enable_stats'),
];
......@@ -172,7 +175,10 @@ class CaptchaSettingsForm extends ConfigFormBase {
// Replace the description with a link if dblog.module is enabled.
if (\Drupal::moduleHandler()->moduleExists('dblog')) {
$form['log_wrong_responses']['#description'] = $this->t('Report information about wrong responses to the <a href=":dblog">log</a>.', [':dblog' => Url::fromRoute('dblog.overview')->toString()]);
$form['log_wrong_responses']['#description'] = $this->t('Report information about wrong responses to the <a href=":dblog">log</a>.', [
':dblog' => Url::fromRoute('dblog.overview')
->toString(),
]);
}
// Submit button.
......
This diff is collapsed.
......@@ -31,7 +31,7 @@ abstract class CaptchaBaseWebTestCase extends WebTestBase {
const CAPTCHA_UNKNOWN_CSID_ERROR_MESSAGE = 'CAPTCHA validation error: unknown CAPTCHA session ID. Contact the site administrator if this problem persists.';
public static $modules = array('captcha', 'comment');
public static $modules = ['captcha', 'comment'];
/**
......@@ -44,7 +44,7 @@ abstract class CaptchaBaseWebTestCase extends WebTestBase {
/**
* Normal visitor with limited permissions.
*
* @var \Drupal\user\Entity\User $normalUser;
* @var \Drupal\user\Entity\User $normalUser ;
*/
protected $normalUser;
......@@ -69,13 +69,17 @@ abstract class CaptchaBaseWebTestCase extends WebTestBase {
parent::setUp();
module_load_include('inc', 'captcha');
$this->drupalCreateContentType(array('type' => 'page'));
$this->drupalCreateContentType(['type' => 'page']);
// Create a normal user.
$permissions = array(
'access comments', 'post comments', 'skip comment approval',
'access content', 'create page content', 'edit own page content',
);
$permissions = [
'access comments',
'post comments',
'skip comment approval',
'access content',
'create page content',
'edit own page content',
];
$this->normalUser = $this->drupalCreateUser($permissions);
// Create an admin user.
......@@ -94,9 +98,13 @@ abstract class CaptchaBaseWebTestCase extends WebTestBase {
$comment_field->save();
/* @var \Drupal\captcha\Entity\CaptchaPoint $captcha_point */
$captcha_point = \Drupal::entityTypeManager()->getStorage('captcha_point')->load('user_login_form');
$captcha_point = \Drupal::entityTypeManager()
->getStorage('captcha_point')
->load('user_login_form');
$captcha_point->enable()->save();
$this->config('captcha.settings')->set('default_challenge', 'captcha/test')->save();
$this->config('captcha.settings')
->set('default_challenge', 'captcha/test')
->save();
}
/**
......@@ -146,10 +154,10 @@ abstract class CaptchaBaseWebTestCase extends WebTestBase {
* Helper function to generate a form values array for comment forms.
*/
protected function getCommentFormValues() {
$edit = array(
$edit = [
'subject[0][value]' => 'comment_subject ' . $this->randomMachineName(32),
'comment_body[0][value]' => 'comment_body ' . $this->randomMachineName(256),
);
];
return $edit;
}
......@@ -158,10 +166,10 @@ abstract class CaptchaBaseWebTestCase extends WebTestBase {
* Helper function to generate a form values array for node forms.
*/
protected function getNodeFormValues() {
$edit = array(
$edit = [
'title[0][value]' => 'node_title ' . $this->randomMachineName(32),
'body[0][value]' => 'node_body ' . $this->randomMachineName(256),
);
];
return $edit;
}
......@@ -229,7 +237,7 @@ abstract class CaptchaBaseWebTestCase extends WebTestBase {
$challenge = (string) $elements[0];
$this->assert('pass', $challenge);
// Extract terms and operator from challenge.
$matches = array();
$matches = [];
preg_match('/\\s*(\\d+)\\s*(-|\\+)\\s*(\\d+)\\s*=\\s*/', $challenge, $matches);
// Solve the challenge.
$a = (int) $matches[1];
......@@ -244,11 +252,11 @@ abstract class CaptchaBaseWebTestCase extends WebTestBase {
*/
protected function allowCommentPostingForAnonymousVisitors() {
// Enable anonymous comments.
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array(
'access comments',
'post comments',
'skip comment approval',
));
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, [
'access comments',
'post comments',
'skip comment approval',
]);
}
}
......@@ -2,9 +2,6 @@
namespace Drupal\captcha\Tests;
use Drupal\captcha\Entity\CaptchaPoint;
use Drupal\Core\Url;
/**
* Tests CAPTCHA caching on various pages.
*
......@@ -23,7 +20,7 @@ class CaptchaCacheTestCase extends CaptchaBaseWebTestCase {
function setUp() {
parent::setUp();
$this->drupalPlaceBlock('user_login_block', array('id' => 'login'));
$this->drupalPlaceBlock('user_login_block', ['id' => 'login']);
}
/**
......
<?php
/**
* @file
* Contains Drupal\captcha\Tests\CaptchaCronTestCase.
*/
namespace Drupal\captcha\Tests;
......@@ -23,9 +19,9 @@ class CaptchaCronTestCase extends CaptchaBaseWebTestCase {
public function setUp() {
parent::setUp();
// add removed session.
// Add removed session.
$this->captcha_sessions['remove_sid'] = $this->addCaptchaSession(REQUEST_TIME - 1 - 60 * 60 * 24);
// add remain session.
// Add remain session.
$this->captcha_sessions['remain_sid'] = $this->addCaptchaSession(REQUEST_TIME);
}
......@@ -33,7 +29,7 @@ class CaptchaCronTestCase extends CaptchaBaseWebTestCase {
* Add test Captcha session data.
*/
public function addCaptchaSession($request_time) {
$admin_user = $this->drupalCreateUser(array('administer site configuration'));
$admin_user = $this->drupalCreateUser(['administer site configuration']);
$this->drupalLogin($admin_user);
// Initialize solution with random data.
......@@ -67,7 +63,7 @@ class CaptchaCronTestCase extends CaptchaBaseWebTestCase {
$connection = Database::getConnection();
$sids = $connection->select('captcha_sessions')
->fields('captcha_sessions', array('csid'))
->fields('captcha_sessions', ['csid'])
->condition('csid', array_values($this->captcha_sessions), 'IN')
->execute()
->fetchCol('csid');
......@@ -78,4 +74,5 @@ class CaptchaCronTestCase extends CaptchaBaseWebTestCase {
// Test if Captcha cron appropriately keeps sessions younger than a day.
$this->assertTrue(in_array($this->captcha_sessions['remain_sid'], $sids), 'Captcha cron does not remove captcha session data younger than 1 day.');
}
}
......@@ -18,7 +18,7 @@ class CaptchaPersistenceTestCase extends CaptchaBaseWebTestCase {
private function setUpPersistence($persistence) {
$this->drupalLogin($this->adminUser);
// Set persistence.
$edit = array('persistence' => $persistence);
$edit = ['persistence' => $persistence];
$this->drupalPostForm(self::CAPTCHA_ADMIN_PATH, $edit, 'Save configuration');
// Log admin out.
$this->drupalLogout();
......@@ -73,12 +73,12 @@ class CaptchaPersistenceTestCase extends CaptchaBaseWebTestCase {
$captcha_sid_initial = $this->getCaptchaSidFromForm();
// Try to with wrong user name and password, but correct CAPTCHA.
$edit = array(
$edit = [
'name' => 'foobar',
'pass' => 'bazlaz',
'captcha_response' => 'Test 123',
);
$this->drupalPostForm(NULL, $edit, t('Log in'), array(), array(), self::LOGIN_HTML_FORM_ID);
];
$this->drupalPostForm(NULL, $edit, t('Log in'), [], [], self::LOGIN_HTML_FORM_ID);
// Check that there was no error message for the CAPTCHA.
$this->assertCaptchaResponseAccepted();
......@@ -88,7 +88,7 @@ class CaptchaPersistenceTestCase extends CaptchaBaseWebTestCase {
$this->assertPreservedCsid($captcha_sid_initial);
// Post from again.
$this->drupalPostForm(NULL, $edit, t('Log in'), array(), array(), self::LOGIN_HTML_FORM_ID);
$this->drupalPostForm(NULL, $edit, t('Log in'), [], [], self::LOGIN_HTML_FORM_ID);
// Check that there was no error message for the CAPTCHA.
$this->assertCaptchaResponseAccepted();
$this->assertPreservedCsid($captcha_sid_initial);
......@@ -107,19 +107,19 @@ class CaptchaPersistenceTestCase extends CaptchaBaseWebTestCase {
$captcha_sid_initial = $this->getCaptchaSidFromForm();
// Try to with wrong user name and password, but correct CAPTCHA.
$edit = array(
$edit = [
'name' => 'foobar',
'pass' => 'bazlaz',
'captcha_response' => 'Test 123',
);
$this->drupalPostForm(NULL, $edit, t('Log in'), array(), array(), self::LOGIN_HTML_FORM_ID);
];
$this->drupalPostForm(NULL, $edit, t('Log in'), [], [], self::LOGIN_HTML_FORM_ID);
// Check that there was no error message for the CAPTCHA.
$this->assertCaptchaResponseAccepted();
// There shouldn't be a CAPTCHA on the new form.
$this->assertCaptchaPresence(FALSE);
$this->assertPreservedCsid($captcha_sid_initial);
// Start a new form instance/session
// Start a new form instance/session.
$this->drupalGet('node');
$this->drupalGet('user');