Problem/Motivation

Email address is validated in SubscriberFormBase which is unnecessary because it's validated anyway since it's an email field. (It is HTML5 type="email", and even without HTML5 support it is validated.) Besides I think we don't test subscription with an invalid email address.

Proposed resolution

Remove custom validation, and add testing.

Remaining tasks

User interface changes

User will see the usual Drupal Core error message when entering invalid address, not the custom Simplenews one.

API changes

Comments

MarinkoIg’s picture

Assigned: Unassigned » MarinkoIg

Assigned to me.

MarinkoIg’s picture

Status: Active » Needs review
StatusFileSize
new2.96 KB

I tried something but is not correct...

Status: Needs review » Needs work
thenchev’s picture

+    if (!$validation) {
+      $this->setErrorByName('mail[0][value]', t('The e-mail address you supplied is not valid.'));
+    }

First, you should start with this line. The reason you have an error is $this->setErrorByName does not exist

MarinkoIg’s picture

StatusFileSize
new2.69 KB
new1.02 KB

I changed..

MarinkoIg’s picture

Status: Needs work » Needs review
StatusFileSize
new2.69 KB
new1.02 KB

I forgot 'Needs review'

Status: Needs review » Needs work

The last submitted patch, 6: 2421337-6.patch, failed testing.

The last submitted patch, 6: 2421337-6.patch, failed testing.

thenchev’s picture

+++ b/src/Tests/SimplenewsSubscribeTest.php
@@ -863,4 +863,57 @@ class SimplenewsSubscribeTest extends SimplenewsTestBase {
 
+  function testSubscribeAnonymousWithInvalidEmail() {
+    // 0. Preparation

You should add a dock block here to explain what your method is doing.

Also add visibility before function, "public" should be ok.

+++ b/src/Tests/SimplenewsSubscribeTest.php
@@ -863,4 +863,57 @@ class SimplenewsSubscribeTest extends SimplenewsTestBase {
+      'administer newsletters',
+      'administer permissions')
+    );

Parenthesis should be on a new line here. Should look like this:
'administer newsletters',
'administer permissions',
)

+++ b/src/Tests/SimplenewsSubscribeTest.php
@@ -863,4 +863,57 @@ class SimplenewsSubscribeTest extends SimplenewsTestBase {
+    );
+    $single_block = $this->setupSubscriptionBlock($block_settings);
+

$single_block is not used anywhere after this code. You can remove it.

+++ b/src/Tests/SimplenewsSubscribeTest.php
@@ -863,4 +863,57 @@ class SimplenewsSubscribeTest extends SimplenewsTestBase {
+
+    // Testing invalid email
+    // Testing invalid email

Remove one of these.

+++ b/src/Tests/SimplenewsSubscribeTest.php
@@ -863,4 +863,57 @@ class SimplenewsSubscribeTest extends SimplenewsTestBase {
+    $this->assertText(t("The email address $mail is not valid"), t("Correct"));

This line could be more descriptive. Instead of "Correct" you can say "Invalid email shows error"

MarinkoIg’s picture

Status: Needs work » Needs review
StatusFileSize
new2.68 KB
new1.58 KB

With changes..

Status: Needs review » Needs work

The last submitted patch, 10: 2421337-10.patch, failed testing.

MarinkoIg’s picture

Status: Needs work » Needs review
StatusFileSize
new2.74 KB
new861 bytes

Status: Needs review » Needs work

The last submitted patch, 12: 2421337-12.patch, failed testing.

The last submitted patch, 10: 2421337-10.patch, failed testing.

The last submitted patch, 12: 2421337-12.patch, failed testing.

miro_dietiker’s picture

A separate test just to test invalid mail addresses seems a bit much overhead to me.
I would prefer to extend one of the existing subscription tests with an invalid address and check the message. 2..5 extra lines, not more.

MarinkoIg’s picture

Status: Needs work » Needs review
StatusFileSize
new1.5 KB
new2.56 KB

Miro, I took your advice and made changes.

miro_dietiker’s picture

Status: Needs review » Reviewed & tested by the community

Looks fine now!

berdir’s picture

Status: Reviewed & tested by the community » Fixed

Yes, looks good.

  • Berdir committed 4f34a6d on 8.x-1.x authored by MarinkoIg
    Issue #2421337 by MarinkoIg: Drop SubscriberFormBase email validation,...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.