Commit b8010519 authored by Jakob Perry's avatar Jakob Perry
Browse files

Fix test deprecations

parent 7b79e106
......@@ -4,6 +4,7 @@ namespace Drupal\Tests\captcha\Functional;
use Drupal\captcha\Entity\CaptchaPoint;
use Drupal\Core\Url;
use Drupal\Core\StringTranslation\StringTranslationTrait;
/**
* Tests CAPTCHA admin settings.
......@@ -12,17 +13,19 @@ use Drupal\Core\Url;
*/
class CaptchaAdminTest extends CaptchaWebTestBase {
use StringTranslationTrait;
/**
* Test access to the admin pages.
*/
public function testAdminAccess() {
$this->drupalLogin($this->normalUser);
$this->drupalGet(self::CAPTCHA_ADMIN_PATH);
$this->assertText(t('Access denied'), 'Normal users should not be able to access the CAPTCHA admin pages', 'CAPTCHA');
$this->assertSession()->pageTextContains($this->t('Access denied'), 'Normal users should not be able to access the CAPTCHA admin pages', 'CAPTCHA');
$this->drupalLogin($this->adminUser);
$this->drupalGet(self::CAPTCHA_ADMIN_PATH);
$this->assertNoText(t('Access denied'), 'Admin users should be able to access the CAPTCHA admin pages', 'CAPTCHA');
$this->assertSession()->pageTextNotContains($this->t('Access denied'), 'Admin users should be able to access the CAPTCHA admin pages', 'CAPTCHA');
}
/**
......@@ -34,10 +37,10 @@ class CaptchaAdminTest extends CaptchaWebTestBase {
/* @var CaptchaPoint $result */
$result = captcha_get_form_id_setting($comment_form_id);
$this->assertNotNull($result, 'CAPTCHA exists', 'CAPTCHA');
$this->assertEqual($result->getCaptchaType(), 'test', 'CAPTCHA type: default', 'CAPTCHA');
$this->assertEquals($result->getCaptchaType(), 'test', 'CAPTCHA type: default');
$result = captcha_get_form_id_setting($comment_form_id, TRUE);
$this->assertNotNull($result, 'CAPTCHA exists', 'CAPTCHA');
$this->assertEqual($result, 'test', 'Setting and symbolic getting CAPTCHA point: "test"', 'CAPTCHA');
$this->assertEquals($result, 'test', 'Setting and symbolic getting CAPTCHA point: "test"');
// Set to 'default'.
captcha_set_form_id_setting($comment_form_id, 'default');
......@@ -46,24 +49,24 @@ class CaptchaAdminTest extends CaptchaWebTestBase {
->save();
$result = captcha_get_form_id_setting($comment_form_id);
$this->assertNotNull($result, 'CAPTCHA exists', 'CAPTCHA');
$this->assertEqual($result->getCaptchaType(), 'foo/bar', 'Setting and getting CAPTCHA point: default', 'CAPTCHA');
$this->assertEquals($result->getCaptchaType(), 'foo/bar', 'Setting and getting CAPTCHA point: default');
$result = captcha_get_form_id_setting($comment_form_id, TRUE);
$this->assertNotNull($result, 'Setting and symbolic getting CAPTCHA point: "default"', 'CAPTCHA');
$this->assertEqual($result, 'foo/bar', 'Setting and symbolic getting CAPTCHA point: default', 'CAPTCHA');
$this->assertNotNull($result, 'Setting and symbolic getting CAPTCHA point: "default"');
$this->assertEquals($result, 'foo/bar', 'Setting and symbolic getting CAPTCHA point: default');
// Set to 'baz/boo'.
captcha_set_form_id_setting($comment_form_id, 'baz/boo');
$result = captcha_get_form_id_setting($comment_form_id);
$this->assertNotNull($result, 'CAPTCHA exists', 'CAPTCHA');
$this->assertEqual($result->getCaptchaType(), 'baz/boo', 'Setting and getting CAPTCHA point: baz/boo', 'CAPTCHA');
$this->assertEquals($result->getCaptchaType(), 'baz/boo', 'Setting and getting CAPTCHA point: baz/boo');
$result = captcha_get_form_id_setting($comment_form_id, TRUE);
$this->assertEqual($result, 'baz/boo', 'Setting and symbolic getting CAPTCHA point: "baz/boo"', 'CAPTCHA');
$this->assertEquals($result, 'baz/boo', 'Setting and symbolic getting CAPTCHA point: "baz/boo"');
// Set to NULL (which should delete the CAPTCHA point setting entry).
captcha_set_form_id_setting($comment_form_id, NULL);
$result = captcha_get_form_id_setting($comment_form_id);
$this->assertNotNull($result, 'CAPTCHA exists', 'CAPTCHA');
$this->assertEqual($result->getCaptchaType(), 'foo/bar', 'Setting and getting CAPTCHA point: NULL', 'CAPTCHA');
$this->assertEquals($result->getCaptchaType(), 'foo/bar', 'Setting and getting CAPTCHA point: NULL');
$result = captcha_get_form_id_setting($comment_form_id, TRUE);
$this->assertNotNull($result, 'CAPTCHA exists', 'CAPTCHA');
......@@ -75,9 +78,9 @@ class CaptchaAdminTest extends CaptchaWebTestBase {
$this->assertNotNull($result, 'Setting and getting CAPTCHA point: baba/fofo', 'CAPTCHA');
// $this->assertEqual($result->module, 'baba', 'Setting and getting
// CAPTCHA point: baba/fofo', 'CAPTCHA');.
$this->assertEqual($result->getCaptchaType(), 'baba/fofo', 'Setting and getting CAPTCHA point: baba/fofo', 'CAPTCHA');
$this->assertEquals($result->getCaptchaType(), 'baba/fofo', 'Setting and getting CAPTCHA point: baba/fofo');
$result = captcha_get_form_id_setting($comment_form_id, TRUE);
$this->assertEqual($result, 'baba/fofo', 'Setting and symbolic getting CAPTCHA point: "baba/fofo"', 'CAPTCHA');
$this->assertEquals($result, 'baba/fofo', 'Setting and symbolic getting CAPTCHA point: "baba/fofo"');
}
/**
......@@ -91,13 +94,12 @@ class CaptchaAdminTest extends CaptchaWebTestBase {
*/
protected function assertCaptchaSetting($form_id, $challenge_type) {
$result = captcha_get_form_id_setting(self::COMMENT_FORM_ID, TRUE);
$this->assertEqual($result, $challenge_type,
t('Check CAPTCHA setting for form: expected: @expected, received: @received.',
$this->assertEquals($result, $challenge_type,
$this->t('Check CAPTCHA setting for form: expected: @expected, received: @received.',
[
'@expected' => var_export($challenge_type, TRUE),
'@received' => var_export($result, TRUE),
]),
'CAPTCHA');
]));
}
/**
......@@ -110,9 +112,9 @@ class CaptchaAdminTest extends CaptchaWebTestBase {
$edit = [
'administration_mode' => TRUE,
];
$this->drupalGet(self::CAPTCHA_ADMIN_PATH);
$this->submitForm($edit, 'Save configuration');
$this->submitForm($edit, $this->t('Save configuration'));
// Create a node with comments enabled.
$node = $this->drupalCreateNode();
......@@ -121,7 +123,7 @@ class CaptchaAdminTest extends CaptchaWebTestBase {
$this->drupalGet('node/' . $node->id());
// Click the add new comment link.
$this->clickLink(t('Add new comment'));
$this->clickLink($this->t('Add new comment'));
$add_comment_url = $this->getUrl();
// Remove fragment part from comment URL to avoid
......@@ -129,26 +131,27 @@ class CaptchaAdminTest extends CaptchaWebTestBase {
$add_comment_url = strtok($add_comment_url, "#");
// Click the CAPTCHA admin link to enable a challenge.
$this->clickLink(t('Place a CAPTCHA here for untrusted users.'));
$this->clickLink($this->t('Place a CAPTCHA here for untrusted users.'));
// Enable Math CAPTCHA.
$edit = ['captchaType' => 'captcha/Math'];
$this->drupalGet($this->getUrl());
$this->submitForm($edit, 'Save');
$this->submitForm($edit, $this->t('Save'));
// Check if returned to original comment form.
$this->assertUrl($add_comment_url, [],
$this->assertSession()->addressEquals($add_comment_url, [],
'After setting CAPTCHA with CAPTCHA admin links: should return to original form.', 'CAPTCHA');
// Check if CAPTCHA was successfully enabled
// (on CAPTCHA admin links fieldset).
$this->assertText(t('CAPTCHA: challenge "@type" enabled', ['@type' => $edit['captchaType']]),
$this->assertSession()->pageTextContains($this->t('CAPTCHA: challenge "@type" enabled', ['@type' => $edit['captchaType']]),
'Enable a challenge through the CAPTCHA admin links', 'CAPTCHA');
// Check if CAPTCHA was successfully enabled (through API).
$this->assertCaptchaSetting(self::COMMENT_FORM_ID, 'captcha/Math');
// Edit challenge type through CAPTCHA admin links.
$this->clickLink(t('change'));
$this->clickLink($this->t('change'));
// Enable Math CAPTCHA.
$edit = ['captchaType' => 'default'];
......@@ -156,31 +159,31 @@ class CaptchaAdminTest extends CaptchaWebTestBase {
$this->submitForm($edit, 'Save');
// Check if returned to original comment form.
$this->assertEqual($add_comment_url, $this->getUrl(),
'After editing challenge type CAPTCHA admin links: should return to original form.', 'CAPTCHA');
$this->assertEquals($add_comment_url, $this->getUrl(),
'After editing challenge type CAPTCHA admin links: should return to original form.');
// Check if CAPTCHA was successfully changed
// (on CAPTCHA admin links fieldset).
// This is actually the same as the previous setting because
// the captcha/Math is the default for the default challenge.
// TODO Make sure the edit is a real change.
$this->assertText(t('CAPTCHA: challenge "@type" enabled', ['@type' => $edit['captchaType']]),
$this->assertSession()->pageTextContains($this->t('CAPTCHA: challenge "@type" enabled', ['@type' => $edit['captchaType']]),
'Enable a challenge through the CAPTCHA admin links', 'CAPTCHA');
// Check if CAPTCHA was successfully edited (through API).
$this->assertCaptchaSetting(self::COMMENT_FORM_ID, 'default');
// Disable challenge through CAPTCHA admin links.
$this->drupalGet(Url::fromRoute('entity.captcha_point.disable', ['captcha_point' => self::COMMENT_FORM_ID]));
$this->submitForm([], 'Disable');
$this->submitForm([], $this->t('Disable'));
// Check if returned to captcha point list.
global $base_url;
$this->assertEqual($base_url . '/admin/config/people/captcha/captcha-points', $this->getUrl(),
'After disabling challenge in CAPTCHA admin: should return to captcha point list.', 'CAPTCHA');
$this->assertEquals($base_url . '/admin/config/people/captcha/captcha-points', $this->getUrl(),
'After disabling challenge in CAPTCHA admin: should return to captcha point list.');
// Check if CAPTCHA was successfully disabled
// (on CAPTCHA admin links fieldset).
$this->assertRaw(t('Captcha point %form_id has been disabled.', ['%form_id' => self::COMMENT_FORM_ID]),
$this->assertSession()->responseContains($this->t('Captcha point %form_id has been disabled.', ['%form_id' => self::COMMENT_FORM_ID]),
'Disable challenge through the CAPTCHA admin links', 'CAPTCHA');
}
......@@ -199,7 +202,7 @@ class CaptchaAdminTest extends CaptchaWebTestBase {
// Go to node page and click the "add comment" link.
$this->drupalGet('node/' . $node->id());
$this->clickLink(t('Add new comment'));
$this->clickLink($this->t('Add new comment'));
$add_comment_url = $this->getUrl();
// Check if CAPTCHA is visible on form.
......@@ -208,8 +211,8 @@ class CaptchaAdminTest extends CaptchaWebTestBase {
$edit = $this->getCommentFormValues();
$edit['captcha_response'] = 'xx';
$this->drupalGet($add_comment_url);
$this->submitForm($edit, 'Preview');
$this->assertText(self::CAPTCHA_WRONG_RESPONSE_ERROR_MESSAGE,
$this->submitForm($edit, $this->t('Preview'));
$this->assertSession()->pageTextContains(self::CAPTCHA_WRONG_RESPONSE_ERROR_MESSAGE,
'wrong CAPTCHA should block form submission.', 'CAPTCHA');
}
......@@ -225,12 +228,12 @@ class CaptchaAdminTest extends CaptchaWebTestBase {
$xss = '<script type="text/javascript">alert("xss")</script>';
$edit = ['description' => $xss];
$this->drupalGet(self::CAPTCHA_ADMIN_PATH);
$this->submitForm($edit, 'Save configuration');
$this->submitForm($edit, $this->t('Save configuration'));
// Visit user register form and check if JavaScript snippet is there.
$this->drupalLogout();
$this->drupalGet('user/register');
$this->assertNoRaw($xss, 'JavaScript should not be allowed in CAPTCHA description.', 'CAPTCHA');
$this->assertSession()->responseNotContains($xss, 'JavaScript should not be allowed in CAPTCHA description.', 'CAPTCHA');
}
/**
......@@ -248,7 +251,8 @@ class CaptchaAdminTest extends CaptchaWebTestBase {
// Clear the cache.
$this->drupalLogin($this->adminUser);
$this->drupalGet(self::CAPTCHA_ADMIN_PATH);
$this->submitForm([], 'Clear the CAPTCHA placement cache');
$this->submitForm([], $this->t('Clear the CAPTCHA placement cache'));
// Check that the placement cache is unset.
$placement_map = $this->container->get('cache.default')
->get('captcha_placement_map_cache');
......@@ -294,24 +298,24 @@ class CaptchaAdminTest extends CaptchaWebTestBase {
];
$this->drupalGet(self::CAPTCHA_ADMIN_PATH . '/captcha-points/add');
$this->submitForm($form_values, 'Save');
$this->assertText(t('Form ID field is required.'));
$this->assertSession()->pageTextContains($this->t('Form ID field is required.'));
// Set CAPTCHA point through admin/user/captcha/captcha/captcha_point.
$form_values['label'] = $label;
$this->drupalGet(self::CAPTCHA_ADMIN_PATH . '/captcha-points/add');
$this->submitForm($form_values, 'Save');
$this->assertRaw(t('Captcha Point for %label form was created.', ['%label' => $captcha_point_form_id]));
$this->submitForm($form_values, $this->t('Save'));
$this->assertSession()->responseContains($this->t('Captcha Point for %label form was created.', ['%label' => $captcha_point_form_id]));
// Check in database.
/* @var CaptchaPoint result */
$result = $this->getCaptchaPointSettingFromDatabase($captcha_point_form_id);
$this->assertEqual($result->captchaType, $captcha_point_module . '/' . $captcha_point_type,
$this->assertEquals($result->captchaType, $captcha_point_module . '/' . $captcha_point_type,
'Enabled CAPTCHA point should have module and type set');
// Disable CAPTCHA point again.
$this->drupalGet(self::CAPTCHA_ADMIN_PATH . '/captcha-points/' . $captcha_point_form_id . '/disable');
$this->submitForm([], 'Disable');
$this->assertRaw(t('Captcha point %label has been disabled.', ['%label' => $label]), 'Disabling of CAPTCHA point');
$this->submitForm([], $this->t('Disable'));
$this->assertSession()->responseContains($this->t('Captcha point %label has been disabled.', ['%label' => $label]), 'Disabling of CAPTCHA point');
// Check in database.
$result = $this->getCaptchaPointSettingFromDatabase($captcha_point_form_id);
......@@ -323,18 +327,18 @@ class CaptchaAdminTest extends CaptchaWebTestBase {
'captchaType' => $captcha_point_module . '/' . $captcha_point_type,
];
$this->drupalGet(self::CAPTCHA_ADMIN_PATH . '/captcha-points/' . $captcha_point_form_id);
$this->submitForm($form_values, 'Save');
$this->assertRaw(t('Captcha Point for %form_id form was updated.', ['%form_id' => $captcha_point_form_id]), 'Saving of CAPTCHA point settings');
$this->submitForm($form_values, $this->t('Save'));
$this->assertSession()->responseContains($this->t('Captcha Point for %form_id form was updated.', ['%form_id' => $captcha_point_form_id]), 'Saving of CAPTCHA point settings');
// Check in database.
$result = $this->getCaptchaPointSettingFromDatabase($captcha_point_form_id);
$this->assertEqual($result->captchaType, $captcha_point_module . '/' . $captcha_point_type,
$this->assertEquals($result->captchaType, $captcha_point_module . '/' . $captcha_point_type,
'Enabled CAPTCHA point should have module and type set');
// Delete CAPTCHA point.
$this->drupalGet(self::CAPTCHA_ADMIN_PATH . '/captcha-points/' . $captcha_point_form_id . '/delete');
$this->submitForm([], 'Delete');
$this->assertRaw(t('Captcha point %label has been deleted.', ['%label' => $label]),
$this->submitForm([], $this->t('Delete'));
$this->assertSession()->responseContains($this->t('Captcha point %label has been deleted.', ['%label' => $label]),
'Deleting of CAPTCHA point');
$result = $this->getCaptchaPointSettingFromDatabase($captcha_point_form_id);
......@@ -359,8 +363,8 @@ class CaptchaAdminTest extends CaptchaWebTestBase {
'captchaType' => $captcha_point_module . '/' . $captcha_point_type,
];
$this->drupalGet(self::CAPTCHA_ADMIN_PATH . '/captcha-points/add');
$this->submitForm($form_values, 'Save');
$this->assertRaw(t('Captcha Point for %form_id form was created.', ['%form_id' => $captcha_point_form_id]));
$this->submitForm($form_values, $this->t('Save'));
$this->assertSession()->responseContains($this->t('Captcha Point for %form_id form was created.', ['%form_id' => $captcha_point_form_id]));
// Switch from admin to non-admin.
$this->drupalLogin($this->normalUser);
......@@ -368,17 +372,17 @@ class CaptchaAdminTest extends CaptchaWebTestBase {
// Try to set CAPTCHA point
// through admin/user/captcha/captcha/captcha_point.
$this->drupalGet(self::CAPTCHA_ADMIN_PATH . '/captcha-points');
$this->assertText(t('You are not authorized to access this page.'),
$this->assertSession()->pageTextContains($this->t('You are not authorized to access this page.'),
'Non admin should not be able to set a CAPTCHA point');
// Try to disable the CAPTCHA point.
$this->drupalGet(self::CAPTCHA_ADMIN_PATH . '/captcha-points/' . $captcha_point_form_id . '/disable');
$this->assertText(t('You are not authorized to access this page.'),
$this->assertSession()->pageTextContains($this->t('You are not authorized to access this page.'),
'Non admin should not be able to disable a CAPTCHA point');
// Try to delete the CAPTCHA point.
$this->drupalGet(self::CAPTCHA_ADMIN_PATH . '/captcha-points/' . $captcha_point_form_id . '/delete');
$this->assertText(t('You are not authorized to access this page.'),
$this->assertSession()->pageTextContains($this->t('You are not authorized to access this page.'),
'Non admin should not be able to delete a CAPTCHA point');
// Switch from nonadmin to admin again.
......@@ -386,12 +390,12 @@ class CaptchaAdminTest extends CaptchaWebTestBase {
// Check if original CAPTCHA point still exists in database.
$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');
$this->assertEquals($result->captchaType, $captcha_point_module . '/' . $captcha_point_type, 'Enabled CAPTCHA point should have module and type set');
// Delete captcha point.
$this->drupalGet(self::CAPTCHA_ADMIN_PATH . '/captcha-points/' . $captcha_point_form_id . '/delete');
$this->submitForm([], 'Delete');
$this->assertRaw(t('Captcha point %label has been deleted.', ['%label' => $label]), 'Disabling of CAPTCHA point');
$this->assertSession()->responseContains($this->t('Captcha point %label has been deleted.', ['%label' => $label]), 'Disabling of CAPTCHA point');
}
}
......@@ -38,41 +38,41 @@ class CaptchaCacheTest extends CaptchaWebTestBase {
global $base_path;
// Check caching without captcha as anonymous user.
$this->drupalGet('');
$this->assertEqual($this->drupalGetHeader('x-drupal-cache'), 'MISS');
$this->assertEquals($this->getSession()->getResponseHeader('x-drupal-cache'), 'MISS');
$this->drupalGet('');
$this->assertEqual($this->drupalGetHeader('x-drupal-cache'), 'HIT');
$this->assertEquals($this->getSession()->getResponseHeader('x-drupal-cache'), 'HIT');
// Enable captcha on login block and test caching.
captcha_set_form_id_setting('user_login_form', 'captcha/Math');
$this->drupalGet('');
$sid = $this->getCaptchaSidFromForm();
$this->assertNull($this->drupalGetHeader('x-drupal-cache'), 'Cache is disabled');
$this->assertNull($this->getSession()->getResponseHeader('x-drupal-cache'), 'Cache is disabled');
$this->drupalGet('');
$this->assertNotEqual($sid, $this->getCaptchaSidFromForm());
$this->assertNotEquals($sid, $this->getCaptchaSidFromForm());
// Switch challenge to captcha/Test, check the captcha isn't cached.
captcha_set_form_id_setting('user_login_form', 'captcha/Test');
$this->drupalGet('');
$sid = $this->getCaptchaSidFromForm();
$this->assertNull($this->drupalGetHeader('x-drupal-cache'), 'Cache is disabled');
$this->assertNull($this->getSession()->getResponseHeader('x-drupal-cache'), 'Cache is disabled');
$this->drupalGet('');
$this->assertNotEqual($sid, $this->getCaptchaSidFromForm());
$this->assertNotEquals($sid, $this->getCaptchaSidFromForm());
// Switch challenge to image_captcha/Image, check the captcha isn't cached.
captcha_set_form_id_setting('user_login_form', 'image_captcha/Image');
$this->drupalGet('');
$image_path = $this->getSession()->getPage()->find('css', '.captcha img')->getAttribute('src');
$this->assertNull($this->drupalGetHeader('x-drupal-cache'), 'Cache disabled');
$this->assertNull($this->getSession()->getResponseHeader('x-drupal-cache'), 'Cache disabled');
// Check that we get a new image when vising the page again.
$this->drupalGet('');
$this->assertNotEqual($image_path, $this->getSession()->getPage()->find('css', '.captcha img')->getAttribute('src'));
$this->assertNotEquals($image_path, $this->getSession()->getPage()->find('css', '.captcha img')->getAttribute('src'));
// Check image caching, remove the base path since drupalGet() expects the
// internal path.
$this->drupalGet(substr($image_path, strlen($base_path)));
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
// Request image twice to make sure no errors happen (due to page caching).
$this->drupalGet(substr($image_path, strlen($base_path)));
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
}
/**
......
......@@ -49,7 +49,7 @@ class CaptchaPersistenceTest extends CaptchaWebTestBase {
*/
protected function assertPreservedCsid($captcha_sid_initial) {
$captcha_sid = $this->getCaptchaSidFromForm();
$this->assertEqual($captcha_sid_initial, $captcha_sid,
$this->assertEquals($captcha_sid_initial, $captcha_sid,
"CAPTCHA session ID should be preserved (expected: $captcha_sid_initial, found: $captcha_sid).");
}
......@@ -61,7 +61,7 @@ class CaptchaPersistenceTest extends CaptchaWebTestBase {
*/
protected function assertDifferentCsid($captcha_sid_initial) {
$captcha_sid = $this->getCaptchaSidFromForm();
$this->assertNotEqual($captcha_sid_initial, $captcha_sid, "CAPTCHA session ID should be different.");
$this->assertNotEquals($captcha_sid_initial, $captcha_sid, "CAPTCHA session ID should be different.");
}
/**
......@@ -83,7 +83,7 @@ class CaptchaPersistenceTest extends CaptchaWebTestBase {
'pass' => 'bazlaz',
'captcha_response' => 'Test 123',
];
$this->submitForm($edit, 'Log in', self::LOGIN_HTML_FORM_ID);
$this->submitForm($edit, $this->t('Log in'), self::LOGIN_HTML_FORM_ID);
// Check that there was no error message for the CAPTCHA.
$this->assertCaptchaResponseAccepted();
......@@ -93,7 +93,7 @@ class CaptchaPersistenceTest extends CaptchaWebTestBase {
$this->assertPreservedCsid($captcha_sid_initial);
// Post from again.
$this->submitForm($edit, 'Log in', self::LOGIN_HTML_FORM_ID);
$this->submitForm($edit, $this->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);
......@@ -117,7 +117,7 @@ class CaptchaPersistenceTest extends CaptchaWebTestBase {
'pass' => 'bazlaz',
'captcha_response' => 'Test 123',
];
$this->submitForm($edit, 'Log in', self::LOGIN_HTML_FORM_ID);
$this->submitForm($edit, $this->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.
......@@ -154,7 +154,7 @@ class CaptchaPersistenceTest extends CaptchaWebTestBase {
'pass' => 'bazlaz',
'captcha_response' => 'Test 123',
];
$this->submitForm($edit, 'Log in', self::LOGIN_HTML_FORM_ID);
$this->submitForm($edit, $this->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.
......@@ -196,7 +196,7 @@ class CaptchaPersistenceTest extends CaptchaWebTestBase {
'pass' => 'bazlaz',
'captcha_response' => 'Test 123',
];
$this->submitForm($edit, 'Log in', self::LOGIN_HTML_FORM_ID);
$this->submitForm($edit, $this->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.
......
......@@ -14,7 +14,7 @@ class CaptchaSessionReuseAttackTestCase extends CaptchaWebTestBase {
*/
protected function assertCaptchaSessionIdReuseAttackDetection() {
// There should be an error message about wrong response.
$this->assertText(self::CAPTCHA_WRONG_RESPONSE_ERROR_MESSAGE,
$this->assertSession()->pageTextContains(self::CAPTCHA_WRONG_RESPONSE_ERROR_MESSAGE,
'CAPTCHA response should flagged as wrong.',
'CAPTCHA'
);
......@@ -57,8 +57,8 @@ class CaptchaSessionReuseAttackTestCase extends CaptchaWebTestBase {
// Post a new comment, reusing the previous CAPTCHA session.
$edit = $this->getCommentFormValues();
$this->assertSession()->hiddenFieldExists("captcha_sid")->setValue((string) $captcha_sid);
$this->assertSession()->hiddenFieldExists("captcha_token")->setValue((string) $captcha_token);
$this->assertSession()->hiddenFieldExists("captcha_sid")->setValue((string)$captcha_sid);
$this->assertSession()->hiddenFieldExists("captcha_token")->setValue((string)$captcha_token);
$edit['captcha_response'] = $solution;
$this->submitForm($edit, 'Preview');
// CAPTCHA session reuse attack should be detected.
......@@ -105,8 +105,8 @@ class CaptchaSessionReuseAttackTestCase extends CaptchaWebTestBase {
// Post a new node, reusing the previous CAPTCHA session.
$edit = $this->getNodeFormValues();
$this->assertSession()->hiddenFieldExists("captcha_sid")->setValue((string) $captcha_sid);
$this->assertSession()->hiddenFieldExists("captcha_token")->setValue((string) $captcha_token);
$this->assertSession()->hiddenFieldExists("captcha_sid")->setValue((string)$captcha_sid);
$this->assertSession()->hiddenFieldExists("captcha_token")->setValue((string)$captcha_token);
$edit['captcha_response'] = $solution;
$this->submitForm($edit, 'Preview');
// CAPTCHA session reuse attack should be detected.
......@@ -145,7 +145,7 @@ class CaptchaSessionReuseAttackTestCase extends CaptchaWebTestBase {
$this->assertCaptchaPresence(FALSE);
// If a "log out" link appears on the page, it is almost certainly because
// the login was successful.
$this->assertText($this->normalUser->getDisplayName());
$this->assertSession()->pageTextContains($this->normalUser->getDisplayName());
// Log out again.
$this->drupalLogout();
......@@ -154,9 +154,9 @@ class CaptchaSessionReuseAttackTestCase extends CaptchaWebTestBase {
$this->drupalGet('<front>');
// Try to log in again, reusing the previous CAPTCHA session.
$this->assertSession()->hiddenFieldExists("captcha_sid")->setValue((string) $captcha_sid);
$this->assertSession()->hiddenFieldExists("captcha_token")->setValue((string) $captcha_token);
$this->assert('pass', json_encode($edit));
$this->assertSession()->hiddenFieldExists("captcha_sid")->setValue((string)$captcha_sid);
$this->assertSession()->hiddenFieldExists("captcha_token")->setValue((string)$captcha_token);
$this->assertNotEmpty(json_encode($edit));
$this->submitForm($edit, 'Log in');
// CAPTCHA session reuse attack should be detected.
$this->assertCaptchaSessionIdReuseAttackDetection();
......@@ -187,7 +187,7 @@ class CaptchaSessionReuseAttackTestCase extends CaptchaWebTestBase {
// Post should be accepted: no warnings,
// no CAPTCHA reuse detection (which could be used by user log in block).
$this->assertCaptchaResponseAccepted();
$this->assertText($comment_subject);
$this->assertSession()->pageTextContains($comment_subject);
}
}
......@@ -2,6 +2,8 @@
namespace Drupal\Tests\captcha\Functional;
use Drupal\Core\StringTranslation\StringTranslationTrait;
/**
* Tests CAPTCHA main test case sensitivity.
*
......@@ -9,6 +11,8 @@ namespace Drupal\Tests\captcha\Functional;
*/
class CaptchaTest extends CaptchaWebTestBase {
use StringTranslationTrait;
/**
* Modules to enable.
*
......@@ -44,15 +48,15 @@ class CaptchaTest extends CaptchaWebTestBase {
'pass' => $user->pass_raw,
'captcha_response' => '?',
];
$this->submitForm($edit, 'Log in', self::LOGIN_HTML_FORM_ID);
$this->submitForm($edit, $this->t('Log in'), self::LOGIN_HTML_FORM_ID);
// Check for error message.
$this->assertText(self::CAPTCHA_WRONG_RESPONSE_ERROR_MESSAGE, 'CAPTCHA should block user login form', 'CAPTCHA');
$this->assertSession()->pageTextContains(self::CAPTCHA_WRONG_RESPONSE_ERROR_MESSAGE, 'CAPTCHA should block user login form', 'CAPTCHA');
// And make sure that user is not logged in:
// check for name and password fields on ?q=user.
$this->drupalGet('user');
$this->assertField('name', t('Username field found.'), 'CAPTCHA');
$this->assertField('pass', t('Password field found.'), 'CAPTCHA');
$this->assertSession()->fieldExists('name');
$this->assertSession()->fieldExists('pass');
}
/**
......@@ -84,23 +88,23 @@ class CaptchaTest extends CaptchaWebTestBase {
$comment_body = $edit['comment_body[0][value]'];
$edit['captcha_response'] = $captcha_response;
$this->drupalGet('comment/reply/node/' . $node->id() . '/comment');
$this->submitForm($edit, 'Save', 'comment-form');
$this->submitForm($edit, $this->t('Save'), 'comment-form');
if ($should_pass) {
// There should be no error message.
$this->assertCaptchaResponseAccepted();
// Get node page and check that comment shows up.
$this->drupalGet('node/' . $node->id());
$this->assertText($comment_subject, $message . ' Comment should show up on node page.', 'CAPTCHA');
$this->assertText($comment_body, $message . ' Comment should show up on node page.', 'CAPTCHA');
$this->assertSession()->pageTextContains($comment_subject, $message . ' Comment should show up on node page.', 'CAPTCHA');
$this->assertSession()->pageTextContains($comment_body, $message . ' Comment should show up on node page.', 'CAPTCHA');
}
else {
// Check for error message.
$this->assertText(self::CAPTCHA_WRONG_RESPONSE_ERROR_MESSAGE, $message . ' Comment submission should be blocked.', 'CAPTCHA');
$this->assertSession()->pageTextContains(self::CAPTCHA_WRONG_RESPONSE_ERROR_MESSAGE, $message . ' Comment submission should be blocked.', 'CAPTCHA');
// Get node page and check that comment is not present.
$this->drupalGet('node/' . $node->id());
$this->assertNoText($comment_subject, $message . ' Comment should not show up on node page.', 'CAPTCHA');
$this->assertNoText($comment_body, $message . ' Comment should not show up on node page.', 'CAPTCHA');
$this->assertSession()->pageTextNotContains($comment_subject, $message . ' Comment should not show up on node page.', 'CAPTCHA');
$this->assertSession()->pageTextNotContains($comment_body, $message . ' Comment should not show up on node page.', 'CAPTCHA');
}
}
......@@ -155,7 +159,7 @@ class CaptchaTest extends CaptchaWebTestBase {
$edit = $this->getCommentFormValues();
$edit['captcha_response'] = 'Test 123';
$this->drupalGet('comment/reply/node/' . $node->id() . '/comment');
$this->submitForm($edit, 'Preview');
$this->submitForm($edit, $this->t('Preview'));
// Check that there is no CAPTCHA after preview.
$this->assertCaptchaPresence(FALSE);
......@@ -182,7 +186,7 @@ class CaptchaTest extends CaptchaWebTestBase {
$edit = $this->getNodeFormValues();
$edit['captcha_response'] = 'Test 123';
$this->drupalGet('node/add/page');
$this->submitForm($edit, 'Preview');
$this->submitForm($edit, $this->t('Preview'));
$this->assertCaptchaPresence(FALSE);