Commit 552fa23a authored by LKS90's avatar LKS90

Tests fully fixed, unneccessary changes reverted, corrected all code sniffer warnings

parent 144e25b5
......@@ -92,7 +92,7 @@ function _captcha_generate_captcha_session($form_id = NULL, $status = CAPTCHA_ST
'solution' => $solution,
'status' => $status,
'attempts' => 0,
])
])
->execute();
return $captcha_sid;
}
......
......@@ -311,19 +311,17 @@ function captcha_form_alter(array &$form, FormStateInterface $form_state, $form_
if ($config->get('add_captcha_description')) {
$captcha_element['#description'] = _captcha_get_description();
}
if ($captcha_point->status()) {
// Get placement in form and insert in form.
$captcha_placement = _captcha_get_captcha_placement($form_id, $form);
_captcha_insert_captcha_element($form, $captcha_placement, $captcha_element);
}
// Get placement in form and insert in form.
$captcha_placement = _captcha_get_captcha_placement($form_id, $form);
_captcha_insert_captcha_element($form, $captcha_placement, $captcha_element);
}
}
elseif ($config->get('administration_mode') && $account->hasPermission('administer CAPTCHA settings')
&& (!\Drupal::service('router.admin_context')->isAdminRoute() || $config->get('allow_on_admin_pages'))) {
// Add CAPTCHA administration tools.
/* @var CaptchaPoint $captcha_point */
$captcha_point = \Drupal::entityManager()->getStorage('captcha_point')->load($form_id);
$captcha_point = CaptchaPoint::load($form_id);
// For administrators: show CAPTCHA info and offer link to configure it.
$captcha_element = [
......
services:
captcha.subscriber:
captcha.config_subscriber:
class: Drupal\captcha\EventSubscriber\CaptchaCachedSettingsSubscriber
tags:
- { name: event_subscriber }
......@@ -327,7 +327,7 @@ class ImageCaptchaSettingsForm extends ConfigFormBase {
'#process' => ['form_process_checkboxes'],
];
$form['image_captcha_font_size'] = [
$form['image_captcha_font_size'] = [
'#type' => 'select',
'#title' => t('Font size'),
'#options' => [
......@@ -342,7 +342,7 @@ class ImageCaptchaSettingsForm extends ConfigFormBase {
],
'#default_value' => (int) $config->get('image_captcha_font_size'),
'#description' => t('The font size influences the size of the image. Note that larger values make the image generation more CPU intensive.'),
];
];
}
// Character spacing (available for both the TrueType
......
......@@ -60,9 +60,4 @@ interface CaptchaPointInterface extends ConfigEntityInterface {
*/
public function setCaptchaType($captcha_type);
/**
* {@inheritdoc}
*/
public function disable();
}
......@@ -29,6 +29,9 @@ use Drupal\captcha\CaptchaPointInterface;
* },
* config_prefix = "captcha_point",
* admin_permission = "administer CAPTCHA settings",
* list_cache_tags = {
* "rendered"
* },
* entity_keys = {
* "id" = "formId",
* "label" = "label",
......@@ -96,14 +99,6 @@ class CaptchaPoint extends ConfigEntityBase implements CaptchaPointInterface {
}
}
/**
* {@inheritdoc}
*/
public function disable() {
Cache::invalidateTags($this->getCacheTags());
return $this->setStatus(FALSE);
}
/**
* {@inheritdoc}
*/
......
......@@ -19,7 +19,7 @@ class CaptchaPointDeleteForm extends EntityConfirmFormBase {
* {@inheritdoc}
*/
public function getQuestion() {
return $this->t('Are you sure you want to delete %name?', array('%name' => $this->entity->getOriginalId()));
return $this->t('Are you sure you want to delete %name?', array('%name' => $this->entity->label()));
}
/**
......@@ -41,7 +41,7 @@ class CaptchaPointDeleteForm extends EntityConfirmFormBase {
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->entity->delete();
drupal_set_message($this->t('Captcha point %label has been deleted.', array('%label' => $this->entity->getOriginalId())));
drupal_set_message($this->t('Captcha point %label has been deleted.', array('%label' => $this->entity->label())));
$form_state->setRedirectUrl($this->getCancelUrl());
}
......
......@@ -49,7 +49,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->getOriginalId())));
drupal_set_message($this->t('Captcha point %label has been disabled.', array('%label' => $this->entity->label())));
}
}
......@@ -41,6 +41,7 @@ class CaptchaPointForm extends EntityForm {
'#type' => 'textfield',
'#title' => $this->t('Form ID'),
'#default_value' => $captcha_point->label(),
'#required' => TRUE,
);
$form['formId'] = array(
......@@ -50,6 +51,7 @@ class CaptchaPointForm extends EntityForm {
'exists' => 'captcha_point_load',
),
'#disable' => !$captcha_point->isNew(),
'#required' => TRUE,
);
// Select widget for CAPTCHA type.
......@@ -73,13 +75,13 @@ class CaptchaPointForm extends EntityForm {
$status = $captcha_point->save();
if ($status == SAVED_NEW) {
drupal_set_message($this->t('Captcha Point for %label form was created.', array(
'%label' => $captcha_point->getFormId(),
drupal_set_message($this->t('Captcha Point for %form_id form was created.', array(
'%form_id' => $captcha_point->getFormId(),
)));
}
else {
drupal_set_message($this->t('Captcha Point for %label form was updated.', array(
'%label' => $captcha_point->getFormId(),
drupal_set_message($this->t('Captcha Point for %form_id form was updated.', array(
'%form_id' => $captcha_point->getFormId(),
)));
}
$form_state->setRedirect('captcha_point.list');
......
......@@ -283,9 +283,10 @@ class CaptchaAdminTestCase extends CaptchaBaseWebTestCase {
// Log in as admin.
$this->drupalLogin($this->adminUser);
$label = 'TEST';
// Set CAPTCHA point through admin/user/captcha/captcha/captcha_point.
$form_values = array(
'label' => $label,
'formId' => $captcha_point_form_id,
'captchaType' => $captcha_point_module . '/' . $captcha_point_type,
);
......@@ -300,7 +301,7 @@ class CaptchaAdminTestCase extends CaptchaBaseWebTestCase {
// Disable CAPTCHA point again.
$this->drupalPostForm(self::CAPTCHA_ADMIN_PATH . '/captcha-points/' . $captcha_point_form_id . '/disable', array(), t('Disable'));
$this->assertRaw(t('Captcha point %label has been disabled.', array('%label' => $captcha_point_form_id)), 'Disabling of CAPTCHA point');
$this->assertRaw(t('Captcha point %label has been disabled.', array('%label' => $label)), 'Disabling of CAPTCHA point');
// Check in database.
$result = $this->getCaptchaPointSettingFromDatabase($captcha_point_form_id);
......@@ -310,7 +311,7 @@ class CaptchaAdminTestCase extends CaptchaBaseWebTestCase {
'captchaType' => $captcha_point_module . '/' . $captcha_point_type,
);
$this->drupalPostForm(self::CAPTCHA_ADMIN_PATH . '/captcha-points/' . $captcha_point_form_id, $form_values, t('Save'));
$this->assertRaw(t('Captcha Point for %label form was updated.', array('%label' => $captcha_point_form_id)), 'Disabling of CAPTCHA point');
$this->assertRaw(t('Captcha Point for %form_id form was updated.', array('%form_id' => $captcha_point_form_id)), 'Saving of CAPTCHA point settings');
// Check in database.
$result = $this->getCaptchaPointSettingFromDatabase($captcha_point_form_id);
......@@ -319,7 +320,8 @@ class CaptchaAdminTestCase extends CaptchaBaseWebTestCase {
// Delete CAPTCHA point.
$this->drupalPostForm(self::CAPTCHA_ADMIN_PATH . '/captcha-points/' . $captcha_point_form_id . '/delete', array(), t('Delete'));
$this->assertRaw(t('Captcha point %label has been deleted.', array('%label' => $captcha_point_form_id)), 'Disabling of CAPTCHA point');
$this->assertRaw(t('Captcha point %label has been deleted.', array('%label' => $label)),
'Deleting of CAPTCHA point');
$result = $this->getCaptchaPointSettingFromDatabase($captcha_point_form_id);
$this->assertFalse($result, 'Deleted CAPTCHA point should be in database');
......@@ -333,15 +335,17 @@ class CaptchaAdminTestCase extends CaptchaBaseWebTestCase {
$captcha_point_form_id = 'form_' . strtolower($this->randomMachineName(32));
$captcha_point_module = 'captcha';
$captcha_point_type = 'Math';
$label = 'TEST_2';
$this->drupalLogin($this->adminUser);
$form_values = array(
'label' => $label,
'formId' => $captcha_point_form_id,
'captchaType' => $captcha_point_module . '/' . $captcha_point_type,
);
$this->drupalPostForm(self::CAPTCHA_ADMIN_PATH . '/captcha-points/add', $form_values, 'Save');
$this->assertRaw(t('Captcha Point for %label form was created.', array('%label' => $captcha_point_form_id)));
$this->assertRaw(t('Captcha Point for %form_id form was created.', array('%form_id' => $captcha_point_form_id)));
// Switch from admin to non-admin.
$this->drupalLogin($this->normalUser);
......@@ -369,9 +373,9 @@ class CaptchaAdminTestCase extends CaptchaBaseWebTestCase {
$result = $this->getCaptchaPointSettingFromDatabase($captcha_point_form_id);
$this->assertEqual($result->captchaType, $captcha_point_module . '/' . $captcha_point_type, 'Enabled CAPTCHA point should have module and type set');
// Delete CAPTCHA point.
// Delete captcha point.
$this->drupalPostForm(self::CAPTCHA_ADMIN_PATH . '/captcha-points/' . $captcha_point_form_id . '/delete', array(), 'Delete');
$this->assertRaw(t('Captcha point %label has been deleted.', array('%label' => $captcha_point_form_id)), 'Disabling of CAPTCHA point');
$this->assertRaw(t('Captcha point %label has been deleted.', array('%label' => $label)), 'Disabling of CAPTCHA point');
}
}
......@@ -39,7 +39,7 @@ class CaptchaPersistenceTestCase extends CaptchaBaseWebTestCase {
// (because posting the CAPTCHA admin form would set the CAPTCHA to 'none').
captcha_set_form_id_setting('user_login_form', 'captcha/Test');
$this->drupalGet('user');
$this->assertCaptchaPresence(FALSE);
$this->assertCaptchaPresence(TRUE);
captcha_set_form_id_setting('user_register_form', 'captcha/Test');
$this->drupalGet('user/register');
$this->assertCaptchaPresence(TRUE);
......@@ -203,7 +203,6 @@ class CaptchaPersistenceTestCase extends CaptchaBaseWebTestCase {
$this->assertPreservedCsid($captcha_sid_initial);
// Start a new form instance/session
$this->drupalGet('node');
$this->drupalGet('user');
$this->assertCaptchaPresence(FALSE);
$this->assertDifferentCsid($captcha_sid_initial);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment